Large/huge pages support on windows

Post all other topics which do not belong to any other category.
Post Reply
Hardcode
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun May 21, 2023 5:50 pm
Contact:

Large/huge pages support on windows

Post by Hardcode »

I saw a some threads about using huge pages on linux for some UPS gain and I did similar thing for windows.

Patch with instructions: https://github.com/Hardcode84/factorio-large-pages
Need patched TBB library: https://github.com/Hardcode84/oneTBB/tr ... -pages-win

Large pages support is quite finicky on Windows, you need to enable them first via group policy editor. Also, you cannot reserve them like on linux, and they are very susceptible to physical mem fragmentation and after some uptime you can find you cannot allocate any large pages even if you have enough free ram.

You can check how much large pages memory was allocated using rammap: https://learn.microsoft.com/en-us/sysin ... ads/rammap
This patch should work with steam 1.1.80 and 1.1.81

Some perf measurements (saves from dosh's patreon):

Code: Select all

sushi:

before

  Performed 1000 updates in 14299.998 ms
  avg: 14.300 ms, min: 12.791 ms, max: 18.595 ms
  checksum: 3950118544
  19.540 Goodbye
  
tbbmalloc

  Performed 1000 updates in 13469.460 ms
  avg: 13.469 ms, min: 12.417 ms, max: 17.850 ms
  checksum: 3950118544
  17.993 Goodbye
  
tbbmalloc + huge pages

  Performed 1000 updates in 12207.342 ms
  avg: 12.207 ms, min: 11.126 ms, max: 15.822 ms
  checksum: 3950118544
  16.411 Goodbye
  
  
SE:

before:

  Performed 1000 updates in 11056.954 ms
  avg: 11.057 ms, min: 9.795 ms, max: 27.241 ms
  checksum: 2406519625
  61.348 Goodbye

tbbmalloc:
  
  Performed 1000 updates in 10744.327 ms
  avg: 10.744 ms, min: 9.502 ms, max: 24.667 ms
  checksum: 2406519625
  53.865 Goodbye

tbbmalloc + huge pages:

  Performed 1000 updates in 9319.778 ms
  avg: 9.320 ms, min: 8.200 ms, max: 22.630 ms
  checksum: 2406519625
  49.449 Goodbye
  
logibrain:

before:

  Performed 1000 updates in 8771.204 ms
  avg: 8.771 ms, min: 5.529 ms, max: 26.442 ms
  checksum: 3349378544
  15.131 Goodbye
  
tbbmalloc:
  
  Performed 1000 updates in 7702.753 ms
  avg: 7.703 ms, min: 5.010 ms, max: 19.551 ms
  checksum: 3349378544
  13.075 Goodbye
  
tbbmalloc + huge pages:
  
  Performed 1000 updates in 7246.894 ms
  avg: 7.247 ms, min: 4.841 ms, max: 18.670 ms
  checksum: 3349378544
  12.203 Goodbye
In general, I've got 10-15% UPS improvement on my machine.
Also, I've some marginal UPS improvements even without large pages, just from replacing allocator with TBB one, but some other people who tested it reported no improvement.

FunMaker
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Wed Jun 08, 2016 8:43 pm
Contact:

Re: Large/huge pages support on windows

Post by FunMaker »

I like your efford to increase performance. The performance gain looks huge - noticing there were no changes to factorio itself. Imho the development on the os side lost the focus on performance. To me it is in fact a long known rumour that memory managment on windows is garbage.

blahfasel2000
Inserter
Inserter
Posts: 49
Joined: Sat Mar 28, 2020 2:10 pm
Contact:

Re: Large/huge pages support on windows

Post by blahfasel2000 »

Large pages are a very specific optimization that only few applications benefit from. For most general desktop apps they would actually be detrimental. Plus they provide the most benefit if only a single application on the system uses them (the CPU has separate TLB caches for large and normal pages; with only a single app using large pages competition for the limited number of TLB cache entries is reduced). There is a reason why neither Windows nor Linux enables them by default unless the application specifically requests them.

AaronVB
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Sep 13, 2023 9:16 pm
Contact:

Re: Large/huge pages support on windows

Post by AaronVB »

I'm curious if this could work with a dedicated server on linux. Previously, libhugetlbfs could be used, but that project does not work anymore since a dependency (glibc in this case) removed some hooks.

Hardcode
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun May 21, 2023 5:50 pm
Contact:

Re: Large/huge pages support on windows

Post by Hardcode »

AaronVB wrote:
Thu Sep 14, 2023 11:18 am
I'm curious if this could work with a dedicated server on linux. Previously, libhugetlbfs could be used, but that project does not work anymore since a dependency (glibc in this case) removed some hooks.
Didn't checked forum for some time, sorry

This patch is Windows specific, you don't need it on linux.

Transparent huge pages should work out of the box for factorio on linux. If THP doesn't work for you, you can try to replace default allocator. Linux version of tbbmalloc already supports huge pages and it would be something like

Code: Select all

TBB_MALLOC_USE_HUGE_PAGES=1 LD_PRELOAD=libtbbmalloc_proxy.so ./factorio
. You can find similar guides for mimalloc and, probably, other allocators over the internet.

AaronVB
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Sep 13, 2023 9:16 pm
Contact:

Re: Large/huge pages support on windows

Post by AaronVB »

I did a small test on my i9 Arch Linux Box. Here are my results: https://files.catbox.moe/f5py0e.txt
I gave the CPU some time to cool down between runs. Large Pages = 2MiB, not 1GiB
Image

NineNine
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Mon Oct 24, 2022 11:20 pm
Contact:

Re: Large/huge pages support on windows

Post by NineNine »

A someone who is in the process of trying to teach myself C, this is a super cool project (I learned about malloc just last night, in fact).

Practically, I wish a 12% performance boost would help. But, considering that most people with UPS problems are growing approaching exponentially, 12% won't help for very long. :(

Factorio really needs to be played on quantum supercomputers.

AaronVB
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Sep 13, 2023 9:16 pm
Contact:

Re: Large/huge pages support on windows

Post by AaronVB »

NineNine wrote:
Mon Jan 29, 2024 3:30 pm
Practically, I wish a 12% performance boost would help. But, considering that most people with UPS problems are growing approaching exponentially, 12% won't help for very long. :(
I imagine, with 1GiB pages, one could get a little more performance. I just don't know how to set them up... that's a project for the weekend.

EDIT: I gained ~2.8% more with 1GiB Pages over 2MiB Pages.
Image

Post Reply

Return to “General discussion”