Skip to content

zend alloc large page support for win(64) proposal. #8405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

devnexen
Copy link
Member

some archs may have more than large page size supported but the minimum aligns with ZEND_MM_CHUNK_SIZE.

@devnexen
Copy link
Member Author

cc @cmb69

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

void *ptr;
#ifdef _WIN64
// For now enabling only for 64 bits, seems more costly than benefitial otherwise
// ZEND_MM_CHUNK_SIZE being the minimum large page size too.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure about this? Don't we need to check GetLargePageMinimum()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did in a small app, x86 64 supports 2MB and 1GB and GetLargePageMinimum returns the former.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but doesn't this depend on the processor? What if a processor doesn't support large pages at all, or requires a larger size than 2MiB (ZEND_MM_CHUNK_SIZE)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point I ll add a check.

@cmb69
Copy link
Member

cmb69 commented Apr 20, 2022

Generally, it would be good to do some performance testing for this with some real-world apps.

@@ -454,9 +454,13 @@ static void *zend_mm_mmap(size_t size)
#ifdef _WIN32
void *ptr;
#ifdef _WIN64
static zend_long minlgsz = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A static variable won't play nicely with thread-safe builds. I think we need to initialize the variable in start_memory_manager(), so it won't be modified after startup.

@devnexen devnexen force-pushed the php_zend_win32_largepages branch 2 times, most recently from b265427 to 01ea398 Compare April 20, 2022 12:08
@devnexen devnexen force-pushed the php_zend_win32_largepages branch from 01ea398 to ce3ae9c Compare April 20, 2022 17:56
@cmb69
Copy link
Member

cmb69 commented Apr 21, 2022

I just checked this, and noticed that the large page allocation fails with code 1314 ("A required privilege is not held by the client.") According to the docs, we first need to

Obtain the SeLockMemoryPrivilege privilege by calling the AdjustTokenPrivileges function. For more information, see Assigning Privileges to an Account and Changing Privileges in a Token.

Apparently, it's starting to get "funny".

@devnexen
Copy link
Member Author

ah good to know thanks, I may revisit it a bit later to see if this is worth pursuing, albeit I understand the reasoning behind this.

@ramsey
Copy link
Member

ramsey commented May 22, 2022

I may revisit it a bit later to see if this is worth pursuing

@devnexen How is this looking?

@devnexen
Copy link
Member Author

been sidetracked a bit but will be back to it soonish.

devnexen added 2 commits May 28, 2022 05:58
some archs may have more than large page size supported but the minimum aligns with ZEND_MM_CHUNK_SIZE.
@devnexen devnexen force-pushed the php_zend_win32_largepages branch 2 times, most recently from 4237581 to fd263ab Compare May 28, 2022 05:52
@devnexen devnexen force-pushed the php_zend_win32_largepages branch from fd263ab to 460edaa Compare May 28, 2022 06:25
@devnexen
Copy link
Member Author

@cmb69 no rush but when you have a moment, still not sure about this.

@Girgias Girgias requested a review from cmb69 June 20, 2022 12:08
@devnexen
Copy link
Member Author

devnexen commented Jul 2, 2022

ping :)

@github-actions
Copy link

github-actions bot commented Sep 1, 2022

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

@dstogov
Copy link
Member

dstogov commented Oct 9, 2023

We don't use huge pages for memory manager by default (zend_mm_use_huge_pages = false by default).
On Linux PHP might crash on fork() because of insufficient free huge pages (to clone RW heap pages).
I'm not sure about possible Windows related problems, but I wouldn't add this feature without benchmarks.

Adjusting process privileges from itself looks suspicious :)

@devnexen
Copy link
Member Author

devnexen commented Oct 9, 2023

Looking at it now, I would need a real windows expert to double check anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants