Skip to contentSkip to conversation

Page allocation (get_free_pages)

DISCUSSION p.hamshere 5 participants 5 messages Oct 18, 2000 – Oct 19, 2000 Memory management

lore
Share & tools
lore

p.hamshere

author
#0 lore raw

Hi
I'm wondering why get_free_pages allocates contiguous pages for non-DMA transfers and why the kernel identity (ish) maps the whole (up to 1GB) of physical memory to its address space...
Surely only DMA requires physically contiguous memory, and everything else (such as kernel stack) could be allocated via a 'vmalloc' like function. If this could be done cleverly, contiguous blocks could be held for DMA and the rest would be allocated from the random free pages left throughout the system. Also, the kernel only *needs* to identity map its code and data, and all other free pages can be mapped anywhere at will - surely?
Given the large blocks may be more 'permanent' than single page allocation / deallocation (on the assumption they are needed to be present for DMA), then also the allocation could be slower and perhaps work on a best-fit algorithm. This then might remove the 'power of two' alignment dependency in the get_free_page allocation. I know I'm missing something (extra overhead of remapping physical memory in the kernel page tables, lack of identity mapping and the fact the kernel assumes this, tracking of physical memory, my Intel-centric view of the world misses the MIPS architecture -something)...but what is it? Reading some books on page allocation it seems that some oses do not allocate contiguous page ever, including NT by the looks of it - do they just fudge the DMA into smaller chunks - anyone know?
Paul

#1 lore raw

** Reply to message from "p.hamshere" <[email protected]> on Wed, 18 Oct 2000 21:12:26 +0100

Quoted 1 line

I'm wondering why get_free_pages allocates contiguous pages for non-DMA transfers and why the kernel identity (ish) maps the whole (up to 1GB) of physical memory to its address space...

I can't answer the question as to why, although I suspect because it's a lot easier,

I can say, however, that if gfp were to not return contiguous pages, it would break my driver.

Signature · 8 lines
Timur Tabi - [email protected]
Interactive Silicon - http://www.interactivesi.com

When replying to a mailing-list message, please direct the reply to the mailing list only.  Don't send another copy to me.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
#3 lore raw
In reply to p.hamshere

[ I inserted a few newlines in the quoted text ]

Quoted 4 lines · p.hamshere

Hi
I'm wondering why get_free_pages allocates contiguous pages for non-DMA transfers and why the kernel identity (ish) maps the whole (up to 1GB) of physical memory to its address space...

Messing with page tables is sloooow and you probably won't gain too much:
About 95% of all gfp allocations are single page anyway. A typical 2 page (order 1) allocation is the task struct of a new process.
Now look what happens if we implement your idea:
We allocate one ore more physical pages, search for some free space in the kernel's virtual address space and update the kernel page tables as needed. Compare this to just grabbing the page from the free list and toggling a few bits in the buddy bitmaps.

regards Christian

Signature · 5 lines
THAT'S ALL FOLKS!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
#4 lore raw
In reply to p.hamshere

Hello,

Quoted 4 lines

I'm wondering why get_free_pages allocates contiguous pages for non-DMA transfers and why the kernel identity (ish) maps the whole (up to 1GB) of physical memory to its address space...
Surely only DMA requires physically contiguous memory, and everything else (such as kernel stack) could be allocated via a 'vmalloc' like function. If this could be done cleverly, contiguous blocks could be held for DMA and the rest would be allocated from the random free pages left throughout the system. Also, the kernel only *needs* to identity map its code and data, and all other free pages can be mapped anywhere at will - surely?
Given the large blocks may be more 'permanent' than single page allocation / deallocation (on the assumption they are needed to be present for DMA), then also the allocation could be slower and perhaps work on a best-fit algorithm. This then might remove the 'power of two' alignment dependency in the get_free_page allocation.

The lower 1GB is mapped into the kernel address space for convenience-- unlike *BSD, Linux has access to kernel memory without mapping it below 1GB all the time, and only needs to create temporary mappings for accessing high memory. I'm not sure about non x86 differences since I am just beginning to play with those ports now.

Quoted 3 lines

I know I'm missing something (extra overhead of remapping physical memory in the kernel page tables, lack of identity mapping and the fact the kernel assumes this, tracking of physical memory, my Intel-centric view of the world misses the MIPS architecture -something)...but what is it? Reading some books on page allocation it seems that some oses do not allocate contiguous page ever, including NT by the looks of it - do they just fudge the DMA into smaller chunks - anyone know?
Paul

Creating mappings and destroying them is inefficient, mostly because of TLB flushes (which are _very_ expensive on 4+way CPU boxen). You'll find that the highmem code for Intel boxes use an LRU set of mappings to avoid TLB flushes unless absolutely necessary -- it waits until a map absolutely must be flushed to avoid corruption before doing it. If the rest of memory were not mapped and contiguous, this inefficiency would be propagated to code beyond the highmem case. If you really WANT virtual memory, you CAN get it with vmalloc(). However as noted >95% of all normal kernel allocations are for < PAGE_SIZE anyway.

--
Eric Lowe
Software Engineer, Systran Corporation
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/