Skip to content

Conversation

devnexen
Copy link
Member

Using the kernel global vm_page_size set by the dynamic linker before the process starts.

Using the kernel global vm_page_size set by the dynamic linker
before the process starts.
@devnexen devnexen requested a review from dstogov as a code owner August 15, 2025 21:21
@devnexen devnexen requested a review from iluuu1994 August 15, 2025 21:46
@TimWolla TimWolla requested a review from a team August 15, 2025 21:47
Copy link
Member

@DanielEScherzer DanielEScherzer left a comment

Choose a reason for hiding this comment

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

No RM objections, technical review not performed

Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

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

From what I see here, this seems to be accurate: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/arm/vm_param.h#L85


@devnexen Is there some public documentation rather than just code that this works?

@TimWolla
Copy link
Member

And does this result in a measurable improvement?

@devnexen
Copy link
Member Author

devnexen commented Aug 16, 2025

From what I see here, this seems to be accurate: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/arm/vm_param.h#L85

@devnexen Is there some public documentation rather than just code that this works?

That is the issue in general with macos, however in this case here sysconf to give you an idea then here getpagesize. So we save the whole syscall at first access basically. Normally, you would at least call getpagesize instead like with FreeBSD.

Zend/zend.c Outdated
@@ -1275,6 +1279,10 @@ ZEND_API size_t zend_get_page_size(void)
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
return system_info.dwPageSize;
#elif defined(__APPLE__)
/* Is in fact the global vm_page_size which is a kernel global
Copy link
Contributor

Choose a reason for hiding this comment

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

If the purpose is to safe syscall, wouldn't it be better to cache the result like in https://github.com/apple-open-source-mirror/Libc/blob/5e566be7a7047360adfb35ffc44c6a019a854bea/gen/FreeBSD/getpagesize.c#L50-L64 for all platforms?

Copy link
Member Author

Choose a reason for hiding this comment

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

Some of the callsites already cache it., like here. If you mean in here to me windodws/posix cases would benefit it, for mac it is just a variable.

@TimWolla
Copy link
Member

So we save the whole syscall at first access basically.

That does not seem particularly worth it going into undocumented territory?

@devnexen
Copy link
Member Author

fair enough. with Mac it is often like this, someone figure something out and we share amongst oss projects :) Anyhow, would calling getpagesize like for FreeBSD case suit you ?

@devnexen devnexen requested a review from TimWolla August 21, 2025 06:46
Zend/zend.c Outdated
Comment on lines 1279 to 1280
/* This returns the value obtained from
* the auxv vector, avoiding a syscall. */
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment accurate for macOS? From your link https://github.com/apple-open-source-mirror/Libc/blob/5e566be7a7047360adfb35ffc44c6a019a854bea/gen/FreeBSD/sysconf.c#L296 it appears that sysconf(_SC_PAGESIZE) just calls getpagesize(), so we only save a single function call, not a syscall, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes I can correct the comment.

@devnexen devnexen force-pushed the zend_page_size_more_direct branch from 7f3ed3f to 1ea4995 Compare August 21, 2025 07:38
@devnexen devnexen requested a review from TimWolla August 23, 2025 16:50
@devnexen devnexen merged commit 30f73aa into php:master Aug 24, 2025
9 checks passed
@devnexen devnexen deleted the zend_page_size_more_direct branch August 24, 2025 12:53
Girgias pushed a commit to Girgias/php-src that referenced this pull request Aug 24, 2025
Using the getpagesize() call instead which saves one call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants