Using large pages - periodic reboot?

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

chrisw
Posts: 4746
Joined: Tue Apr 03, 2012 4:28 pm
Location: Midi-Pyrénées
Full name: Christopher Whittington

Re: Using large pages - periodic reboot?

Post by chrisw »

RubiChess wrote: Wed Nov 30, 2022 1:39 pm
chrisw wrote: Tue Nov 29, 2022 6:14 pm How much do large pages help chess engines?
Running depth 26 bench in my engine on a Windows machine with permission to use large pages enabled and using 1024MB hash tables.
1. Usage of large pages disabled by UCI option:

Code: Select all

RubiChess-20221102_x86-64-avx2.exe -option "Allow Large Pages" false -option Hash 1024 bench -depth 26
Time  : 57754
Nodes : 122640389
NPS   : 2123478
2. Usage of large pages enabled:

Code: Select all

RubiChess-20221102_x86-64-avx2.exe -option Hash 1024 bench -depth 26
Time  : 49201
Nodes : 122640389
NPS   : 2492605
So we have 17% more speed under these conditions.
With 256MB hash and a depth 24 bench I measured only 5% more speed with large pages enabled compared to disabled, so the advantage depends on the conditions.
Thanks! Needless to say, I rushed off to see how to get this done (POV Windows 10 system). First sight, it seems fairly tortuous to persuade Windows. Spun through the Microsoft script linked to on SF pages, but ran into problem of “who” to enable, the script seemed to be for an SQL server. It also recommended using RamMap, but that just hung. It’s not that I’m not sure what I’m doing wrong, more a case of not knowing what I’m doing, as ever.

For Windows, it doesn’t seem like the engine code needs anything done at all, so I wondered how you disabled it with UCI. Checked quickly the Rubichess code on GitHub but couldn’t see the UCI option. So, confused ….
syzygy
Posts: 5807
Joined: Tue Feb 28, 2012 11:56 pm

Re: Using large pages - periodic reboot?

Post by syzygy »

gordonr wrote: Tue Nov 29, 2022 5:56 pm
Modern Times wrote: Tue Nov 29, 2022 12:09 am I may be wrong, but I think once they are allocated you don't lose them. There is some ambiguity in that wording. Maybe someone else knows for sure.
Thanks

I think the setting remains but for how long "large pages" can be efficiently used without reboots, I'm not sure. I've since found the following link:

https://mahdytech.com/large-pages-how-when/#the-whynot

It's not chess specific but it does highlight a potential issue. I'm going to monitor performance in combination with doing some reboots periodically.
If the engine remains running, you will not lose the large pages.

If you stop the engine and restart it almost immediately, it should normally find back the large pages that were just deallocated.

If you have been running all kinds of applications on your computer since you last rebooted, memory might have become too fragmented for Windows to find enough large pages when you start the chess engine. Ideally the chess engine will report whether allocating large pages succeded. More ideally, you run Linux which will transparenty shuffle things around to give you the large pages you want.

It is possible that Windows 11 has improved on this point (but I have no information about this).
User avatar
RubiChess
Posts: 650
Joined: Fri Mar 30, 2018 7:20 am
Full name: Andreas Matthies

Re: Using large pages - periodic reboot?

Post by RubiChess »

chrisw wrote: Wed Nov 30, 2022 6:18 pm Thanks! Needless to say, I rushed off to see how to get this done (POV Windows 10 system). First sight, it seems fairly tortuous to persuade Windows. Spun through the Microsoft script linked to on SF pages, but ran into problem of “who” to enable, the script seemed to be for an SQL server. It also recommended using RamMap, but that just hung. It’s not that I’m not sure what I’m doing wrong, more a case of not knowing what I’m doing, as ever.
I wrote a "HowTo enable large pages right" in this forum. forum3/viewtopic.php?f=2&t=76086&p=8767 ... ge#p876714
The link to the UserRights module doesn't work anymore but I googled and found this https://www.powershellgallery.com/packa ... Right.psm1
chrisw wrote: Wed Nov 30, 2022 6:18 pm For Windows, it doesn’t seem like the engine code needs anything done at all, so I wondered how you disabled it with UCI. Checked quickly the Rubichess code on GitHub but couldn’t see the UCI option. So, confused ….
The Windows code that allocs large memory and, depending on en.allowlargepages, uses a "large pages alloc" is here: https://github.com/Matthies/RubiChess/b ... s.cpp#L656
The UCI option is registered and linked to en.allowlargepages here: https://github.com/Matthies/RubiChess/b ... e.cpp#L197
The "event handler" for this UCI option is here: https://github.com/Matthies/RubiChess/b ... ne.cpp#L38

The only reason for this UCI option (besides that I could use it for this thread) is to avoid that in RubiX-RubiY tests with quite large Hash settings, one engine gets the large pages and the other fails to alloc with large pages. That would destroy the test and so I always set "Allow Large Pages" to false when running tests on my Windows machine.

Regards, Andreas
chrisw
Posts: 4746
Joined: Tue Apr 03, 2012 4:28 pm
Location: Midi-Pyrénées
Full name: Christopher Whittington

Re: Using large pages - periodic reboot?

Post by chrisw »

RubiChess wrote: Wed Nov 30, 2022 10:27 pm
chrisw wrote: Wed Nov 30, 2022 6:18 pm Thanks! Needless to say, I rushed off to see how to get this done (POV Windows 10 system). First sight, it seems fairly tortuous to persuade Windows. Spun through the Microsoft script linked to on SF pages, but ran into problem of “who” to enable, the script seemed to be for an SQL server. It also recommended using RamMap, but that just hung. It’s not that I’m not sure what I’m doing wrong, more a case of not knowing what I’m doing, as ever.

Cut this one out and frame it. Thanks Andreas.


I wrote a "HowTo enable large pages right" in this forum. forum3/viewtopic.php?f=2&t=76086&p=8767 ... ge#p876714
The link to the UserRights module doesn't work anymore but I googled and found this https://www.powershellgallery.com/packa ... Right.psm1
chrisw wrote: Wed Nov 30, 2022 6:18 pm For Windows, it doesn’t seem like the engine code needs anything done at all, so I wondered how you disabled it with UCI. Checked quickly the Rubichess code on GitHub but couldn’t see the UCI option. So, confused ….
The Windows code that allocs large memory and, depending on en.allowlargepages, uses a "large pages alloc" is here: https://github.com/Matthies/RubiChess/b ... s.cpp#L656
The UCI option is registered and linked to en.allowlargepages here: https://github.com/Matthies/RubiChess/b ... e.cpp#L197
The "event handler" for this UCI option is here: https://github.com/Matthies/RubiChess/b ... ne.cpp#L38

The only reason for this UCI option (besides that I could use it for this thread) is to avoid that in RubiX-RubiY tests with quite large Hash settings, one engine gets the large pages and the other fails to alloc with large pages. That would destroy the test and so I always set "Allow Large Pages" to false when running tests on my Windows machine.

Regards, Andreas
User avatar
MikeB
Posts: 4889
Joined: Thu Mar 09, 2006 6:34 am
Location: Pen Argyl, Pennsylvania

Re: Using large pages - periodic reboot?

Post by MikeB »

chrisw wrote: Tue Nov 29, 2022 6:14 pm How much do large pages help chess engines?
Why?
How?
About 10%. The system performance increase stems from the reduction of translation lookaside buffer (TLB) misses due to the ability of the TLB to map to a larger virtual memory range. It also speeds up memory prefetching by eliminating the need to restart prefetch operations on 4 KB boundaries.
Speed increases are more noticeable when using 2048 GB hash sizes or larger.
Image