Skip to contentSkip to conversation

reduce fragmentation due to kmem_cache_alloc_node

PATCH In review Manfred Spraul 2 participants 5 messages Oct 9, 2004 – Oct 15, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reduce fragmentation due to kmem_cache_alloc_node

Hi Andrew,

attached is a patch that fixes the fragmentation that Badri noticed with kmem_cache_alloc_node. Could you add it to the mm tree? The patch is against 2.6.9-rc3-mm3.

Description:
kmem_cache_alloc_node tries to allocate memory from a given node. The current implementation contains two bugs:
- the node aware code was used even for !CONFIG_NUMA systems. Fix: inline function that redefines kmem_cache_alloc_node as kmem_cache_alloc for !CONFIG_NUMA.
- the code always allocated a new slab for each new allocation. This caused severe fragmentation. Fix: walk the slabp lists and search for a matching page instead of allocating a new page.
- the patch also adds a new statistics field for node-local allocs. They should be rare - the codepath is quite slow, especially compared to the normal kmem_cache_alloc.

Badri: Could you test it?
Andrew, could you add the patch to the next -mm kernel? I'm running it right now, no obvious problems.

// $Header$
// Kernel Version:

//  VERSION = 2
//  PATCHLEVEL = 6
//  SUBLEVEL = 9
//  EXTRAVERSION = -rc3-mm3
include/linux/slab.h +7 -0
@@ -61,7 +61,14 @@
 extern int kmem_cache_destroy(kmem_cache_t *);
 extern int kmem_cache_shrink(kmem_cache_t *);
 extern void *kmem_cache_alloc(kmem_cache_t *, int);
+#ifdef CONFIG_NUMA
 extern void *kmem_cache_alloc_node(kmem_cache_t *, int);
+#else
+static inline void *kmem_cache_alloc_node(kmem_cache_t *cachep, int node)
+{
+	return kmem_cache_alloc(cachep, GFP_KERNEL);
+}
+#endif
 extern void kmem_cache_free(kmem_cache_t *, void *);
 extern unsigned int kmem_cache_size(kmem_cache_t *);
 
mm/slab.c +65 -48

204 lines not on this page · raw message

#1 lore raw

Manfred,

This patch seems to work fine on my AMD machine.
I tested your patch on 2.6.9-rc2-mm3.

It seemed to have fixed fragmentation problem I was observing, but I don't think it fixed the problem completely. I still see some fragmentation, with repeated tests of scsi-debug, but it could be due to the test. I will collect more numbers..

Thanks,
Badari

Quoted 19 lines · Manfred Spraul

Hi Andrew,

attached is a patch that fixes the fragmentation that Badri noticed with kmem_cache_alloc_node. Could you add it to the mm tree? The patch is against 2.6.9-rc3-mm3.

Description:
kmem_cache_alloc_node tries to allocate memory from a given node. The current implementation contains two bugs:
- the node aware code was used even for !CONFIG_NUMA systems. Fix:
inline function that redefines kmem_cache_alloc_node as kmem_cache_alloc for !CONFIG_NUMA.
- the code always allocated a new slab for each new allocation. This caused severe fragmentation. Fix: walk the slabp lists and search for a matching page instead of allocating a new page.
- the patch also adds a new statistics field for node-local allocs. They should be rare - the codepath is quite slow, especially compared to the normal kmem_cache_alloc.

Quoted 8 lines

Badri: Could you test it?
Andrew, could you add the patch to the next -mm kernel? I'm running it right now, no obvious problems.

______________________________________________________________________

--
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 13 lines · Badari Pulavarty

Manfred,

This patch seems to work fine on my AMD machine. I tested your patch on 2.6.9-rc2-mm3.

It seemed to have fixed fragmentation problem I was observing, but I don't think it fixed the problem completely. I still see some fragmentation, with repeated tests of scsi-debug, but it could be due to the test. I will collect more numbers..

Did you disable the !CONFIG_NUMA block from <linux/slab.h> or leave it enabled? If the CONFIG_NUMA test is in the header file, then my patch is identical to you proposal, except that I've changed the global declaration instead of just the call from alloc_percpu.

--
Manfred
--
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
In reply to Manfred Spraul

Manfred & Andrew,

I am happy with the patch.This seems to have fixed slab fragmentation problem with scsi_debug tests.

But I still have issue with my scsi-debug tests. I don't think they are related to this patch. When I do,

while :
do
simulate 1000 scsi-debug disks
freeup 1000 scsi-debug disks
done

I see size-64 "inuse" objects increasing. Eventually, it fills up entire low-mem. I guess while freeing up scsi-debug disks, is not cleaning up all the allocations :(

But one question I have is - Is it possible to hold size-64 slab, because it has a management allocation (slabp - 40 byte allocations) from alloc_slabmgmt() ? I remember seeing this earlier. Is it worth moving all managment allocations to its own slab ? should I try it ?

Thanks,
Badari

Quoted 19 lines · Manfred Spraul

Hi Andrew,

attached is a patch that fixes the fragmentation that Badri noticed with kmem_cache_alloc_node. Could you add it to the mm tree? The patch is against 2.6.9-rc3-mm3.

Description:
kmem_cache_alloc_node tries to allocate memory from a given node. The current implementation contains two bugs:
- the node aware code was used even for !CONFIG_NUMA systems. Fix:
inline function that redefines kmem_cache_alloc_node as kmem_cache_alloc for !CONFIG_NUMA.
- the code always allocated a new slab for each new allocation. This caused severe fragmentation. Fix: walk the slabp lists and search for a matching page instead of allocating a new page.
- the patch also adds a new statistics field for node-local allocs. They should be rare - the codepath is quite slow, especially compared to the normal kmem_cache_alloc.

Quoted 5 lines

Badri: Could you test it?
Andrew, could you add the patch to the next -mm kernel? I'm running it right now, no obvious problems.

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

#4 lore raw
Quoted 9 lines · Badari Pulavarty

I see size-64 "inuse" objects increasing. Eventually, it fills up entire low-mem. I guess while freeing up scsi-debug disks, is not cleaning up all the allocations :(

But one question I have is - Is it possible to hold size-64 slab, because it has a management allocation (slabp - 40 byte allocations) from alloc_slabmgmt() ? I remember seeing this earlier. Is it worth moving all managment allocations to its own slab ? should I try it ?

Nope. Moving "slabp" allocations to its own slab, didn't fix anything. I guess scsi-debug is not cleaning up properly :(

Thanks,
Badari

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