-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add an API to the standard library to learn the system page size #11308
Comments
I've added this to the @AsahiLinux list of code that is known to have problems with a 16K page size, at https://github.com/AsahiLinux/docs/wiki/Software-known-to-have-issues-with-16k-page-size As a reference point, this particular issue was addressed in Go (golang) at golang/go#10180 by determining system page size at runtime. The side effect is to improve compatibility on a variety of platforms with non-4K page sizes. |
This only works specifically for Asahi Linux. Fixes ziglang#11308
@Vexu Why does this issue have an os-macos label, while it is specific of linux? also, any chance it could be assigned to an earlier milestone? |
I can put it on 0.11.0 but it doesn't mean much since it could be resolved earlier or later anyways. |
Would it be feasible to adopt for linux whatever solution zig already adopts for macos? |
@dkwo According to The Asahi Linux docs, macOS has its own way of letting programs "choose" their own page size, so I'm guessing Zig just uses 4K pages and lets macOS deal with it. Linux doesn't have its own way of working with varied page sizes, and "likely never will" (quote from the Asahi docs) So to answer your question, Zig doesn't need to worry about page sizes on macOS, so that's not really a solution that can be transferred to Linux. P.S. If I got something horribly wrong, feel free to correct me ;)! I'm not an expert, this is just my understanding. |
Makes sense, thanks. |
The kernel passes |
Duplicate of #4082.
I am unable to reproduce your steps:
Jokes aside, I'll change this issue into something that can actually address what I am guessing is your use case. |
What is the status of this issue? I can take a shot at it if someone provides instructions |
still a bug, as far as i know |
https://en.wikipedia.org/wiki/Page_(computer_memory)#Getting_page_size_programmatically sounds like the most pragmatic approach, so YAGNI: #include <stdio.h>
#include <unistd.h> /* sysconf(3) */
int main(void)
{
printf("The page size for this system is %ld bytes.\n",
sysconf(_SC_PAGESIZE)); /* _SC_PAGE_SIZE is OK too. */
return 0;
} #include <stdio.h>
#include <windows.h>
int main(void)
{
SYSTEM_INFO si;
GetSystemInfo(&si);
printf("The page size for this system is %u bytes.\n", si.dwPageSize);
return 0;
} |
@andrewrk Why was the bug label removed? if I cannot use zig to build e.g. river on aarch64 linux on my 16k page size kernel, this looks like a bug to me, not enhancement. |
If you want the bug label you need to fill out the bug template. This issue does not provide steps to reproduce, observed behavior, or actual behavior. Perhaps you are interested in #16331 which is labeled as a bug. |
I see. Would the following be acceptable? I'm using Void Linux on an Apple m1 machine (aarch64-glibc), which has a 16k page-size kernel, but any Linux with these requirements https://github.com/void-linux/void-packages#requirements and a non-standard (but perfectly fine) page-size kernel should be able to reproduce. Clone the repo
Then build
Then build (e.g.)
The build process fails with
More details:
|
Rather, that bug looks like a duplicate of this one :) since that was opened 3 weeks ago (vs 1+ year), and this bug is also tracked by asahi-linux, which is kind of useful. |
If you have time to argue with me on the issue tracker, you have time to submit a patch :P |
Reproduce abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://github.com/freebsd/freebsd-src git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
The Kernel provides each program with the default page size, which this function reads. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
The Kernel provides each program with the default page size, which this function reads. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
The Kernel provides each program with the default page size, which this function reads. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
The Kernel provides each program with the default page size, which this function reads. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris git clone --depth=1 https://github.com/apple-open-source-mirror/Libc rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
sysconf() abstracts posix sysconf for comptime- and runtime probing. getDefaultPageSize() reads the Kernel provided default page size, which remains constant from program start to end. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris git clone --depth=1 https://github.com/apple-open-source-mirror/Libc rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
sysconf() abstracts posix sysconf for comptime- and runtime probing. getDefaultPageSize() reads the Kernel provided default page size, which remains constant from program start to end. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris git clone --depth=1 https://github.com/apple-open-source-mirror/Libc rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
sysconf() abstracts posix sysconf for comptime- and runtime probing. getDefaultPageSize() reads the Kernel provided default page size, which remains constant from program start to end. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris git clone --depth=1 https://github.com/apple-open-source-mirror/Libc rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
sysconf() abstracts posix sysconf for comptime- and runtime probing. getDefaultPageSize() reads the Kernel provided default page size, which remains constant from program start to end. Reproduce added abi bits with: git clone --depth=1 https://github.com/DragonFlyBSD/DragonFlyBSD git clone --depth=1 https://git.FreeBSD.org/src.git freebsd git clone --depth=1 https://fuchsia.googlesource.com/fuchsia git clone --depth=1 https://github.com/haiku/haiku git clone --depth=1 https://github.com/Stichting-MINIX-Research-Foundation/minix/ git clone --depth=1 https://github.com/NetBSD/src netbsd git clone --depth=1 https://github.com/openbsd/src openbsd git clone --depth=1 https://github.com/kofemann/opensolaris git clone --depth=1 https://github.com/apple-open-source-mirror/Libc rg 'define.*_SC_PAGE_SIZE' -B 1 --vimgrep Closes ziglang#11308.
I have applied the same patch to Zig UpdateI have compiled Zig |
I've managed to add a function for checking the page size at runtime in #17382. It seems like this issue somewhat is related to my PR. It supports setting the page size for a target so cross compiling would work. The only issue atm is it works best when your compiling on the device your using it for. This means prebuilt Zig versions won't work on Apple Silicon without a specific build. But I hope to fix that somewhat soon by replacing some of the |
It is worthwhile to note that the new Pi 5 also has 16K pages by default, so it's likely that code running on it will be affected by this issue. https://www.raspberrypi.com/documentation/computers/config_txt.html#kernel is the Pi 5 kernel config doc that's relevant. |
@vielmetti Yeah, I won't be able to get a Pi 5 to test out #17382 on it but since I have an Apple Silicon device which the PR works for, this should work. Though Windows on ARM may not support the Pi 5, the code should work as soon as I add the Windows code today. But Linux does work so that should mean it will work. I'm working on adding CPU-specific cross-compile to change the page size so if you specify the Pi CPU and Zig detects it then it should be able to use 16k pages. Though, the functionality might break programs if a non-16k page sized kernel is used. Work to detect this better could be done. |
wait, sorry that it isn't the most related to this discussion, but how are you running void, natively or in a VM? |
@RoundDuckKira native, as you figured out :) |
Zig Version
0.10.0-dev.1434+676652865
Steps to Reproduce
I am running Linux on a MacBook Pro which uses 16 KiB pages; however, Zig's std lib always assumes 4 KiB pages on Linux running on aarch64.
Expected Behavior
Zig should infer/detect the correct page size.
Actual Behavior
Zig assumes 4 KiB pages, which results in errors in calls to
msync
ormmap
(e.g. instd.debug.captureStackTrace
).#4082 is mentioned in the source code, so I'm guessing that is the long term solution. That issue also mentions a "hacky" solution of using
madvise
to check for a valid page size. A short term solution could be to checkmadvise
at compile time when running Linux on aarch64 to check between all possible page sizes (ARM64 can also support 64 KiB pages).If this is acceptable I can open a PR.EDIT: It looks like syscalls can't run at comptime so I don't think this would work.The text was updated successfully, but these errors were encountered: