Skip to content
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 #4082

Open
andrewrk opened this issue Jan 5, 2020 · 6 comments · May be fixed by #20511
Open

Replace mem.page_size with mem.min_page_size and mem.max_page_size #4082

andrewrk opened this issue Jan 5, 2020 · 6 comments · May be fixed by #20511
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jan 5, 2020

Quoting @daurnimator from #3815:

This PR removes mem.page_size and replaces it with minimums and maximums. Originally I attempted to create a global variable page_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 that madvise returns EINVAL 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 constant BUFSIZ.

Additionally, on linux we now assert that the page size in the auxiliary vector matches expectations.

This proposal solves #2564

@andrewrk andrewrk added standard library This issue involves writing Zig code for the standard library. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Jan 5, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Jan 5, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@mikdusan
Copy link
Member

mikdusan commented Jan 19, 2021

how about:

// page_sizes.len is guaranteed  > 0
// page_sizes guaranteed in order smallest to largest
// "max" and "min" is page_sizes[0] and page_sizes[page_sizes.len-1] 

// on arm with 4 page sizes
const page_sizes: []const usize = [_]usize{ 0x1000, 0x10000, 0x100000, 0x1000000 }; // 4K, 65K, 1M, 1G

// a default is always needed could be comptime set to something other than smallest
const default_page_size = page_sizes[0];

posix BUFSIZ is for io and doesn't belong in std.mem . Maybe std.io.bufsiz. For example, when working with pathnames and naturally using std.mem functions, I don't want to use BUFSIZ.

@dkwo
Copy link

dkwo commented Sep 8, 2022

What is the status of this proposal?
Would it fix the wrong page size for Linux on Apple Silicon?

@nektro
Copy link
Contributor

nektro commented Sep 9, 2022

no the linked issue explains that page_size needs to become a runtime value for that to work properly

@andrewrk andrewrk added the accepted This proposal is planned. label Jan 3, 2023
@andrewrk
Copy link
Member Author

andrewrk commented Jan 3, 2023

Along with the original proposal I am tagging along this change as well:

  • move it from std.mem to std.heap.

@andrewrk andrewrk modified the milestones: 0.14.0, 0.12.0 Jul 25, 2023
@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Jul 25, 2023
@Parzival-3141
Copy link
Contributor

Parzival-3141 commented Aug 15, 2023

Taking a swing at this but I have a couple questions.

  • Is the original proposal accepted as is? Is bufsiz included as well?
  • What about @mikdusan's proposal? Seems wise to offer more information to users.
  • Should be page size info be part of the target os/arch instead?

I'm leaning more towards @mikdusan and this comment's ideas.

@matu3ba
Copy link
Contributor

matu3ba commented Aug 21, 2023

Additionally, on linux we now assert that the page size in the auxiliary vector matches expectations.

I wonder, where those expectations come from. Kernels provide the default size and, if available, a user-configurable size for large pages and one needs Kernel or CPU-level privilege to do stuff in the MMU etc.

I would propose instead a 1. portable large table abstraction (which are unfortunately named different in different Kernels), 2. making possible page sizes from the hardware available at comptime and 3. provide probing functionality for such large page abstractions.

Background: One can configure or compile Kernels with different page size support and not all Kernels provide the page API: Hermit has no reliable page size and neither an api for it. See hermit-os/kernel#815.
If one wants to take them into account in a portable way (cross-compiling etc), one has to do runtime probing.

@alexrp alexrp linked a pull request Aug 17, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants