Skip to contentSkip to conversation

Early kmalloc/kfree

PATCH Andi Kleen 3 participants 3 messages Jul 8, 2005 – Jul 11, 2005 1 message not in the archive Memory management

lore
Share & tools
lore

Andi Kleen

author
#1 lore raw
In reply to a message not in the archive
Quoted 24 lines · Bob Picco

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.

Quoted 7 lines

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.

I think that is a really really bad idea. slab is already complex enough
and adding scary hacks like this will probably make it collapse under its own weight at some point.

And the ACPI interpreter is big enough and has other kernel interactions that when you start like this you'll probably end with adding more and more and more such early hacks all over the kernel longer term. e.g. what happens when the AML creates mutexes and the interpreter wants to schedule? Or use PCI config space accesses? Or something else in the osl layer? Your early AML might not need this right now, but longer term someone will write some that needs it.

It's better to just not go down that slippery path.

I think you need to solve this in some other way.

-Andi
--
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>

#2 lore raw
Quoted 3 lines · Andi Kleen

I think that is a really really bad idea. slab is already complex enough
and adding scary hacks like this will probably make it collapse under its own weight at some point.

Seconded.

Maybe we can solve this by bringing the system up in a limited configuration and then discover additional capabilities during ACPI discovery and reconfigure.
--
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>

#3 lore raw
Quoted 11 lines · Christoph Lameter
Quoted 3 lines · Andi Kleen

I think that is a really really bad idea. slab is already complex enough
and adding scary hacks like this will probably make it collapse under its own weight at some point.

Seconded.

Maybe we can solve this by bringing the system up in a limited configuration and then discover additional capabilities during ACPI discovery and reconfigure.

From a user perspective of the memory allocators, I liked this idea
of making the transition from bootmem to slab be transparent. It's currently extremely difficult to have any kind of service span the transition when there doesn't even appear to be a programmatic way to know which one to use.

The original problem Bob and I were trying to solve is simply how to
automatically deal with a system that may or may not have an IOMMU that if it exists, is only discoverable in ACPI namespace. Getting ACPI namespace available by paginig_init() makes this relatively easy because the memory zones can be setup properly for the hardware available. If we wait till after that point, we'll need to figure out how to re-balance the dma and normal zones to make memory allocations efficient.

I agree that ACPI is potentially a slippery slope, and many pieces of
it are impractical for early use. I think this can be controlled by using common early setup services in the ACPI subsystem that limit what components get initialized. That said, I'm open to other suggestions on how we might reconfigure the system later to accomplish this task. Thanks,

Alex

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