3 ms·
x86 has 4k, 2MB, and 1GB page sizes. > This would reduce the amount of bookkeeping if the OS hands out physical memory in large contiguous tracts, but increas
by dragontamer 6y ago
x86 has 4k, 2MB, and 1GB page sizes.
> This would reduce the amount of bookkeeping if the OS hands out physical memory in large contiguous tracts, but increase it if it is shuffling around individual pages. I have no idea what OS behaviour here actually is.
On x86, large 2MB and 1GB __cannot__ be paged. The latency associated with a 2MB or 1GB read/write to disk is just too long to be reasonable.
These are called "huge pages" (2MB or larger). Memory-intensive applications see benefits from huge-pages, but the additional book-keeping to the user (in particular: huge pages CANNOT be paged, and therefore are a "rare-ish resource") has made HugePages somewhat uncommon on both Linux and Windows. (Windows only supports the 2MB hugepage, and ignores the 1GB option entirely)
> This would reduce the amount of bookkeeping if the OS hands out physical memory in large contiguous tracts
Note that all modern chips have a TLB-cache, to the point where the bookkeeping is largely handled by the CPU itself. This TLB-cache still has restrictions, so a huge-page reduces book-keeping and accelerates the speed of memory access slightly.
The OS sets up the table, but the CPU itself handles the whole shebang nearly transparently. That's why all of these memory-address and data-structure specific details show up when talking about page-tables, you've got to set up the data-structure precisely so that the dedicated hradware inside the CPU can traverse the table correctly.
- throwaway525142 6y ago> On x86, large 2MB and 1GB __cannot__ be paged. The latency associated with a 2MB or 1GB read/write to disk is just too long to be reasonable. Do you have a link where I can read about this? Couldn't find it quickly.
- dragontamer 6y agoDebian's hugepage docs are pretty good: https://wiki.debian.org/Hugepages https://wiki.debian.org/Hugepages Windows has Large-Page documentation: https://docs.microsoft.com/en-us/windows/win32/memory/large-page-support https://docs.microsoft.com/en-us/windows/win32/memory/large-... Linux kernel also has docs: https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt In my experience, most Linux distros have huge-pages enabled, but just doesn't use them unless the user sets some configuration flags in various locations.
- throwaway525142 6y agoThanks, that was interesting. :)
- marcan_42 6y ago> The latency associated with a 2MB or 1GB read/write to disk is just too long to be reasonable. On spinning rust, seek times are O(10ms) and speeds are O(100MB/s). That means in the time it takes to seek to page in a page, you could read about 1MB worth of data. That should make that order of page size vastly more efficient for paging in data than tiny 4kB pages, from an HDD. From an SSD, sure, the seek penalty is much lower so things should skew in favor of smaller reads.
- brandmeyer 6y agoThe seek penalty is lower, true. However, the peak throughput is also much higher, so SSDs share this behavior with HDDs.
- jasonwatkinspdx 6y agoYeah, that stated rationale is slightly confused. With server class spinning disks, you get something like 90% of sequential bandwidth when doing 8 MiB random reads. There's slight gains up to 32 MiB. So yes, overall bandwidth out of the disk is much better with 2 MiB than 4 KiB. But the question is: how much of that 2 MiB block is actually useful before it gets ejected out of the page cache? For 1 GiB of page cache memory, with 4 KiB pages we get ~260k different entries, but with 2 MiB we only get 512. So we'll end up with a lot of capacity conflicts on the cache unless our workload just happens to only work with a small number of huge memory blocks. That's likely to dominate performance even if we got "free" bandwidth with the large pages. All that said, 4 KiB is a bit painful on modern hardware. Current SSDs are happiest when writes are an integer multiple of around 32 to 64 KiB or so. It'd be nice if we had a medium size pages option.
- my123 6y agoOn Arm, the possible granule (base page size) sizes are 4KB, 16KB and 64KB. On iOS and macOS on Apple Silicon, the used page size is 16KB across the board. On RHEL/CentOS on Arm64, the used page size is 64KB. In other cases, it's generally 4KB (and is always 4KB on Android or Windows/arm64).
- throwaway_pdp09 6y agoThe guy's asking a different question I think, about extents. I've done a quick look but can't find a link to them, IIRC they were used early on, in multics, and had IIRC again, pages underlying them, but they weren't fixed length. Odd that I can't find anything instantly. - ok, they're called segments it seems. Look for the word "segment" here, you'll see it immediately. http://homepage.divms.uiowa.edu/~jones/opsys/notes/22.shtml http://homepage.divms.uiowa.edu/~jones/opsys/notes/22.shtml
- a1369209993 6y ago> large 2MB and 1GB __cannot__ be paged. Even without what marcan_42 said, this is still false: a 2MB page is made of 512 4KB pages; page one of those out and use the freed memory as a page table for the other 511 (then page those out individually). If you have a contiguous, aligned 2MB block, defragment physical memory and fuse it into a huge page. It may very well be the case that linux chooses not to support this, and that's plausibly the correct decision, but it's not remotely impossible.
- my123 6y agoLinux does support transparent hugepages.
- a1369209993 6y agoIf so, then I'm glad I qualified that part with "It may very well be the case that" (and "plausibly").
- my123 6y agoSee: https://www.kernel.org/doc/Documentation/vm/transhuge.txt https://www.kernel.org/doc/Documentation/vm/transhuge.txt