patchThe GNU Hurd - Patches: patch #4818, Dynamic memory allocation for...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #4818: Dynamic memory allocation for Linux Device drivers in glue.

Submitter:  Gianluca Guida <gianluca>
Submitted:  Sat 21 Jan 2006 07:39:54 PM UTC
   
 
Category:  GNU Mach Priority:  6
Status:  Postponed Privacy:  Public
Assigned to:  tschwinge Open/Closed:  Open
Planned Release:  GNU Mach 1.4
Wiki-like text discussion box: 


Thu 11 May 2006 06:01:53 AM UTC, comment #4: 

Hey Thomas, thanks for the followup.

I'll try to find some time to investigate this, doesn't seem to me such a complicated issue tho. Anyways, I already have a faster substitute code for the bitscanning stuff (which was legacy code).

Thanks,
Gianluca

Gianluca Guida <gianluca>
Tue 09 May 2006 05:35:05 PM UTC, comment #3: 

This patch fails to work together with Samuel's patch #7118 which is now applied to the gnumach-1-branch: http://lists.gnu.org/archive/html/commit-hurd/2006-05/msg00000.html

The problem occurs with RAM configurations somewhere above 970 MiB.  It can be reproduced in QEMU.

In linux/dev/init/main.c, linux_init(), `__get_free_pages (GFP_ATOMIC, CONTIG_ALLOC_ORDER, 1)' fails to allocate DMAable memory.

The following backtrace was gathered with printf() debugging:
__get_free_pages(DMAable)
vm_page_grab_contiguous_pages_flags(VM_PAGE_DMA)
vm_page_grab_contiguous_pages_queue(DMA queue) returns 6, which is `KERN_RESOURCE_SHORTAGE'.
In there, in the ``First loop. Scan the bit array for NPAGES contiguous bits'' loop, after ``Bitscan this one word'', `if (v)' is never true, as soon as the machine's memory configuration is somewhere above 970 MiB, so we fall through to returning KERN_RESOURCE_SHORTAGE.  I did further printf() debugging, tryinto to track this down, but have so far not been able to interpret my findings in a way to specify the problem.  Perhaps all DMAable is used up for not DMA related things?


Another tiny issue: the only time that vm_page_dma_last is set to `16*1024*1024' (16 MiB) is when phys_last_addr is exactly `16*1024*1024'.  If it is larger, vm_page_dma_last is set to `16*1024*1024 - 1'.  Is this intended?

Thomas Schwinge <tschwinge>
Group administrator
Fri 27 Jan 2006 09:41:04 PM UTC, comment #2: 

This is a new version of the zoned patch, which permits the linux glue to dynamically allocate memory.

Changes in this patch are a new function, linux_kmem_collect that now get called by vm_pageout_scan.

Here's the changelog entry:

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)
(linux_kmem_collect): 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.

  • vm/vm_pageout.c (vm_pageout_scan) [LINUX_DEV]: Call

linux_kmem_collect.

Gianluca Guida <gianluca>
Sun 22 Jan 2006 01:42:45 AM UTC, comment #1: 

This is a new version of the patch.

No major improvement, it's just a cleaning of the previous patch:

- Removed the rtl8139.c, which I forgot to remove in the previous patch;
- Removed some debugging printf that I forgot, in pure StoMach style;

Happy Testing,
Gianluca

Gianluca Guida <gianluca>
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.

Gianluca Guida <gianluca>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #9485:  vm_resident-zoned-patch-3.diff added by gianluca (43KiB - application/octet-stream - vm_resident zoned patch 3. Linux glue's unused memory is now collected by pageout daemon.)
file #9463:  vm_resident-zoned-patch-2.diff added by gianluca (43KiB - application/octet-stream - vm_resident zoned patch 2 (minor patch cleaning, no changelogs needed))
file #9461:  vm_resident-zoned-patch.diff added by gianluca (44KiB - application/octet-stream - vm_resident zoned patch 1)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

 

Follow 7 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-05-09 tschwinge StatusIn Progress Postponed
2006-05-04 tschwinge Planned ReleaseNone GNU Mach 1.4
2006-02-12 tschwinge StatusNone In Progress
    Assigned toNone tschwinge
2006-01-27 gianluca Attached File- Added vm_resident-zoned-patch-3.diff, #5831
2006-01-22 gianluca Attached File- Added vm_resident-zoned-patch-2.diff, #5798
2006-01-21 gianluca Attached File- Added vm_resident-zoned-patch.diff, #5795

Back to the top

Powered by Savane 3.14-3b9d.
Corresponding source code