What's your problem then ?
Posted Oct 11, 2007 23:25 UTC (Thu) by
jzbiciak (
✭ supporter ✭, #5246)
In reply to:
What's your problem then ? by khim
Parent article:
Memory part 3: Virtual Memory
There's a pretty big difference between the "last page" of "an allocation several pages long", and "each mapping". Each page has a mapping, and so the allocation mentioned has multiple mappings associated with it because it involves multiple pages. Suppose I allocate 62K, and I need to carve it into 4K pages. I end up allocating 64K total (16 pages). 15 of the 16 pages are fully utilized, and the last page is half-wasted.
Consider an allocation of N bytes that does not share pages with any other allocation--for example, an allocation via mmap.
- It requires ceil(N / PAGE_SIZE) pages (and therefore mappings).
- It will waste (PAGE_SIZE - (N % PAGE_SIZE)) bytes total.
- There will be floor(N / PAGE_SIZE) fully utilized pages.
The amount of wasted bytes depends on the distribution of N. As N grows larger (and the number of mappings per allocation goes up), the number of wasted bytes per mapping goes down.
(And yes, that's pseudo-code. The actual C code to compute those quantities isn't much different, but it's a little noisier.)
(
Log in to post comments)