-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Replace mem.page_size with mem.min_page_size and mem.max_page_size #3815
Conversation
.aarch64, .aarch64_be => 1 * 1024 * 1024 * 1024, // ARM64 supports 4K, 16K, 64K, 2M, 32M, 512M, 1G pages | ||
.mips, .mipsel, .mips64, .mips64el => 64 * 1024, // Every MIPS III, MIPS IV, MIPS32 and MIPS64 processor supports 4K, 16K and 64K page sizes. | ||
.powerpc64, .powerpc64le => 64 * 1024, | ||
.s390x => 2 * 1024 * 1024 * 1024, // 4K, 1M, 2G pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact: this doesn't fit in a u29
!
.wasm32, .wasm64 => 64 * 1024, | ||
else => 4 * 1024, | ||
}; | ||
|
||
pub const max_page_size = switch (builtin.arch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you justify the inclusion of this constant? The one place you used it, I disagree with. That test should be using actual page size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "actual page size"?
@@ -139,7 +139,7 @@ pub fn updateFileMode(source_path: []const u8, dest_path: []const u8, mode: ?Fil | |||
|
|||
const in_stream = &src_file.inStream().stream; | |||
|
|||
var buf: [mem.page_size * 6]u8 = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this * 6
... it seemed oddly arbitrary.
Hopefully this is the right place for this question. If I am missing the intent of the patch, please ignore this comment. CPU hardware does not generally support arbitrary page sizes. Hardware supports a very limited set of sizes (as you note in one of the comments in the patch). Rather than mix/max would it not be closer to reality to have arrays containing the valid page sizes for a given CPU? E.g.. 4k, 16k, 64k, 2M, 1G for some fictitious processor. This intersects with the support in the OS. For instance, as far as I know most Linux systems on AMD64 support 4k and one or more of 2M and 1G (if the CPU supports it). So perhaps the array needs to be based on both the OS and CPU. IIRC iOS uses 16k but I do not remember if it supports any kind of huge pages. Then if you want to have suggestions of buffer sizes, you can check that array and find the next largest page size than the initial ask. I.e. if the user code wants 12k, suggest 16k on many processors. Or look for multiples of a smaller page size and use 3x 4k pages. |
I don't think anyone cares about those details. Really the important one is the minimum page size, which is used when APIs (like
|
For the latter (max page size): Databases. DBs use huge pages all over the place and do their own internal fragmentation. Page size is very important for those applications. I have seen some large language VMs use big pages too, but I think the current trend there is in the opposite direction (smaller pages). And now that I am thinking about this, perhaps this should be in the std.os library rather than here because it is the OS that ultimately determines what page sizes are supported.
OK. Fair enough. |
I'm not ready to decide one way or another on this, but I have converted it into a proposal here: #4082 |
This PR removes
mem.page_size
and replaces it with minimums and maximums. Originally I attempted to create a global variablepage_size
, but I realised that this would not work when zig's own startup routines are not used (e.g. when zig is used to create a static library). There is no linux syscall to get the current page size if you don't have access to the auxiliary vector, so a hacky solution would be required (e.g. using the knowledge thatmadvise
returnsEINVAL
on non-page aligned arguments, and doing a search for the page size)This PR introduces
mem.bufsiz
as a reasonable "default size" for buffers. The name is taken from the posix constantBUFSIZ
.Additionally, on linux we now
assert
that the page size in the auxiliary vector matches expectations.Closes #2564