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

Weird handling of huge pages on *nix inside map_anon() #137

Open
gim913 opened this issue Jan 10, 2025 · 0 comments
Open

Weird handling of huge pages on *nix inside map_anon() #137

gim913 opened this issue Jan 10, 2025 · 0 comments

Comments

@gim913
Copy link

gim913 commented Jan 10, 2025

I found it as a part of #136, but moving discussion here:

Rust doc string for linux part says:

The size of the requested page can be specified in page bits. If not provided, the system
default is requested. The requested length should be a multiple of this, or the mapping
will fail.

There seems to be some kind of mix up here:

  • it seems the length doesn't have to be multiple of page size, per man page:

    For mmap(), offset must be a multiple of the underlying huge page
    size. The system automatically aligns length to be a multiple of
    the underlying huge page size.

  • the doc doesn't really mention that the page_bits option is used to encode OFFSET https://github.com/gim913/memmap2-rs/blob/windows-large-page-support/src/unix.rs#L287-L289 - and yes, offset on linux needs to be aligned, but as you can see, it does something weird (or maybe I'm not understanding how it's supposed to be used on linux):
    (u64::from(mask) & (MAP_HUGE_MASK as u64)) << MAP_HUGE_SHIFT
    If I understand correctly, MAP_HUGE_SHIFT should be used to encode THE FLAG passed to mmap, NOT the offset!
    There's even sample in manpage:
#define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
#define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant