Sat 21 Jan 2006 07:39:54 PM UTC, original submission:
This patches rewrite GNU Mach's physical page allocation routines and make glued linux drivers use these new routines instead of limited, specific and redundant routines existing in the actual linux glue.
vm/vm_resident.c now can handle (thanks to information given from the architecture-dependant component) two specific zones of physical memory: DMA capable and non-DMA capable.
In the x86 we suffer a limit from the ISA bus, that can just let its DMA chip access first 16Mb of memory. Thus, when ISA drivers need memory for DMA operation, we must be sure to supply pages below that limit.
GNU Mach didn't had support for special zones in the page, perhaps because when people were hacking it 16Mb seemed to be a far limit in x86 systems. Actual Linux glue solved the problem by allocating a fixed, unfreeable amount of ram below 16Mb at bootstrap and limiting the whole linux subsection to use that memory only, which in fact was stolen from the system. Furthermore, and this is very frequent in Mach, it added yet another fixed and arbitrary limit for memory usage to generic components.
What this patch basically does is to add multizone allocation (DMA and non-DMA) to GNUMach and hack the glue to make it uses this new feature, thus making allocation from linux drivers dynamical. As a result, linux glue code is simpler. As a side effect, some unused, obsolete native device drivers in Mach (i386/i386at ones) get broken, since they use a slow routine to allocate DMA memory that now has been removed.
This work is still unfinished (the pageout daemon has to free unused collected memory from kmalloc/kfree, but that's an easy task). I posted this patch for testing only. I actually had installed and normally used a Debian GNU/Hurd system with this patch, but I would be happy if people would test it.
Thanks for reading this,
Gianluca
2006-01-20 Gianluca Guida <glguida@gmail.com>
- vm/pmap.h (pmap_is_dma, pmap_is_normal): New functions.
- vm/page.h (VM_PAGE_DMA): New macro.
(vm_page_queue_free): Variable removed.
(vm_page_queue_free_dma, vm_page_queue_free_normal): New
variables.
(vm_page_physaddr_lookup, vm_page_grab_flags)
(vm_page_grab_contiguous_pages_flags): New functions.
(first_phys_addr, last_phys_addr): Declarations removed.
(phys_first_addr, phys_last_addr): New declarations.
- vm/vm_resident.c (vm_page_free_bitmap)
(vm_page_free_bitmap_bitsz): New variables.
(vm_page_free_bitmap_set, vm_page_free_bitmap_unset)
(vm_page_free_bitmap_alloc, vm_page_array_init, vm_page_array_add)
(vm_page_physaddr_lookup): New functions.
(vm_page_bootstrap): Initialize vm_page_queue_free_normal and
vm_page_queue_free_dma. Call vm_page_free_bitmap_alloc.
(pmap_startup): Call vm_page_array_init. Add page to vm_page_array
for physaddress-to-vm_page_t resolution. Do not release page in
any particular order.
(vm_page_create): Add page to vm_page_array.
(vm_page_grab_flags, vm_page_grab_contiguous_pages_queue)
(vm_page_grab_contiguous_flags): New functions.
(vm_page_grab, vm_page_grab_contiguous_pages): Function rewritten.
(vm_page_release): Select proper free list based on page type (DMA
or non-DMA). Use Mach's queue handling funcitons not .next and
.prev pointers manually. Set vm_page_free_bitmap when freeing a
page.
- i386/i386at/model_dep.c (use_all_mem): Always set to 1.
(init_alloc_aligned): Do not use any particular oder during
bootstrap allocation.
(alloc_dma_mem): Function removed.
- kern/startup.c: Include <vm/pmap.h>.
(setup_main): Calculate memory size using phys_last_addr and
phys_first_addr.
- i386/intel/pmap.c (vm_page_normal_first, vm_page_normal_last)
(vm_page_dma_first, vm_page_dma_last): New variables.
(pmap_bootstrap): Set proper values to vm_page_normal_* and
vm_page_dma_* based on system's memory.
(pmap_is_dma, pmap_is_normal): New functions.
- kern/startup.c: Removed /* XXX */ comments, since phys_last_addr
and phys_first_addr are exported by pmap.c now.
- linux/dev/glue/kmem.c: Include <mach/error.h>
(MEM_CHUNK_SIZE, MEM_CHUNKS, NBPW): Macro removed.
(pages_free, memlist, num_page_collect, linux_mem_avail):
Variables removed.
(memlist_dma, memlist_nml): New variables.
(linux_kmem_init): No initialization needed anymore (all code
removed).
(coalesce_blocks): Coalesce separately DMA memory blocks and
non-DMA memory blocks.
(linux_kmalloc): Check for DMA in priority argument. Select proper
memlist to get blocks from. Pass dma information to
__get_free_pages.
(linux_kfree): Select proper memlist to free memory into.
(collect_kmalloc_pages): Function removed.
(collect_kmalloc_pages_dma, collect_kmalloc_pages_nml): New
functions.
(__get_free_pages, free_pages): Functions rewritten.
- linux/dev/init/main.c (CONTIG_ALLOC, NBPW): Macro removed.
(CONTIG_ALLOC_ORDER): New macro.
(linux_init): Use __getfreepages to allocate PCI initialization
memory and free_pages to free it.
(alloc_contig_mem, free_contig_mem): Functions removed.
|