Skip to contentSkip to conversation

Early kmalloc/kfree

PATCH New Bob Picco 1 participant 1 message Jul 8, 2005

Subsystems (3)
lore
Share & tools
lore

Bob Picco

author
#0 lore raw

PATCH 1/1 Early kmalloc/kfree

We have a requirement on IA64 to run the ACPI interpreter in the setup_arch function before paging_init examines the maximum DMA physical address which is limited by the IOMMU. One obstacle is the use of kmalloc/kfree by ACPI. Using the bootmem allocator is unacceptable because > 20Mb of memory is wastefully allocated. As an alternative, I investigated what would be required to optionally make the slab allocator available early in boot and work in an almost seamless way.

The patch below is a solution for early kmalloc/kfree. An architecture which requires kmalloc/kfree use before kmem_cache_init has normally completed can perform the initialization as early as pfn_to_page is a valid operation. Like the bootmem allocator this point in execution is well known. An arch that requires early kmalloc/kfree chooses the CONFIG_EARLY_KMALLOC option and must call kmem_cache_init at the appropriate place in setup_arch.

The known deficiencies of this solution are similar to the bootmem allocator. The placement of the call to kmem_cache_init requires arch dependent code knowlege and possibly manipulation of arch dependent code for enablement. kmalloc/kmfree can't be called between when mem_init calls bootmem to free pages and the second call to kmem_cache_init made from start_kernel. A NUMA deficiency, like bootmem allocator, exists for CPU only nodes. The NUMA node distance information isn't interrogated by bootmem allocator for memory less nodes.

The slab API hasn't been modified. All hot code paths are untouched by this patch. The patch has been tested on a 2 CPU SMP box, two node NUMA simulated machine with and without memory less nodes. All testing has been done on ia64 but nothing prevents other architectures from using the patch.

Manfred provided valuable early review feedback.

Alex is responsible for the early ACPI changes and helping me test the patch.

thanks,

bob

 Kconfig      |    6 +++
 page_alloc.c |    4 ++
 slab.c       |   99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 105 insertions(+), 4 deletions(-)
mm/Kconfig +6 -0
Index: linux-2.6.13-rc2-mm1/mm/Kconfig
===================================================================
@@ -98,3 +98,9 @@ config HAVE_MEMORY_PRESENT
 config ARCH_SPARSEMEM_EXTREME
 	def_bool n
 	depends on SPARSEMEM && 64BIT
+#
+# For early use of kmalloc and kfree.  This requires architecture dependent
+# code calling kmem_cache_init when pfn_to_page is safe to call. 
+#
+config	EARLY_KMALLOC
+	def_bool n
mm/page_alloc.c +4 -0
Index: linux-2.6.13-rc2-mm1/mm/page_alloc.c
===================================================================
@@ -1712,6 +1712,10 @@ void __init memmap_init_zone(unsigned lo
 			continue;
 		page = pfn_to_page(pfn);
 		set_page_links(page, zone, nid, pfn);
+#ifdef CONFIG_EARLY_KMALLOC
+		if (PageSlab(page))
+			continue;
+#endif
 		set_page_count(page, 0);
 		reset_page_mapcount(page);
 		SetPageReserved(page);
mm/slab.c +95 -4

143 lines not on this page · raw message

--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>