User: Password:
|
|
Subscribe / Log in / New account

What's your problem then ?

What's your problem then ?

Posted Oct 11, 2007 19:59 UTC (Thu) by khim (subscriber, #9252)
In reply to: Memory part 3: Virtual Memory by addw
Parent article: Memory part 3: Virtual Memory

If there is an allocation several pages long then the last page will be, on average, 1/2 wasted, or, in other words, each mapping wastes half the page size in physical memory for each mapping. You've said the same thing Drepper said but in different words as far as I can see...


(Log in to post comments)

What's your problem then ?

Posted Oct 11, 2007 23:25 UTC (Thu) by jzbiciak (subscriber, #5246) [Link]

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.)

What's your problem then ?

Posted Oct 15, 2007 13:13 UTC (Mon) by mgedmin (subscriber, #34497) [Link]

I do not think the work "mapping" means what you think it means, at least in the context of this article.

Here's what the manual page of mmap says: "mmap() creates a new mapping in the virtual address space of the calling process. The starting address for the new mapping is specified in start. The length argument specifies the length of the mapping."

That's how I understand "mapping": a contiguous range of virtual memory addresses in the address space of a particular process.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds