SLUB: The unqueued slab allocator V6
Subsystems (3)
cover SLUB: The unqueued slab allocator V6
[PATCH] SLUB The unqueued slab allocator v6
Note that the definition of the return type of ksize() is currently different between mm and Linus' tree. Patch is conforming to mm. This patch also needs sprint_symbol() support from mm.
V5->V6:
- Straighten out various coding issues u.a. to make the hot path clearer in slab_alloc and slab_free. This adds more gotos. sigh.
- Detailed alloc / free tracking including pid, cpu, time of alloc / free if SLAB_STORE_USER is enabled or slub_debug=U specified on boot.
- sysfs support via /sys/slab. Drop /proc/slubinfo support. Include slabinfo tool that produces an output similar to what /proc/slabinfo does. Tool needs to be made more sophisticated to allow control of various slub options at runtime. Currently reports total slab sizes, slab fragmentation and slab effectiveness (actual object use vs. slab space use).
- Runtime debug option changes per slab via /sys/slab/<slabcache>. All slab debug options can be configured via sysfs provided that no objects have been allocated yet.
- Deal with i386 use of slab page structs. Main patch disables slub for i386 (CONFIG_ARCH_USES_SLAB_PAGE_STRUCT). Then a special patch removes the page sized slabs and removes that setting. See the caveats in that patch for further details.
V4->V5:
- Single object slabs only for slabs > slub_max_order otherwise generate sufficient objects to avoid frequent use of the page allocator. This is necessary to compensate for fragmentation caused by frequent uses of the page allocator. We expect slabs of PAGE_SIZE from this rule since multi object slabs require uses of fields that are in use on i386 and x86_64. See the quicklist patchset for a way to fix that issue and a patch to get rid of the PAGE_SIZE special casing.
- Drop pass through to page allocator due to page allocator fragmenting memory. The buffering through large order allocations is done in SLUB. Infrequent larger order allocations cause less fragmentation than frequent small order allocations.
- We need to update object sizes when merging slabs otherwise kzalloc will not initialize the full object (this caused the failure on various platforms).
- Padding checks before redzone checks so that we get messages about the corruption of whole slab and not about a single object.
V3->V4
- Rename /proc/slabinfo to /proc/slubinfo. We have a different format after all.
- More bug fixes and stabilization of diagnostic functions. This seems to be finally something that works wherever we test it.
- Serialize kmem_cache_create and kmem_cache_destroy via slub_lock (Adrian's idea)
- Add two new modifications (separate patches) to guarantee
a mininum number of objects per slab and to pass through large allocations.
V2->V3
- Debugging and diagnostic support. This is runtime enabled and not compile time enabled. Runtime debugging can be controlled via kernel boot options on an individual slab cache basis or globally.
- Slab Trace support (For individual slab caches).
- Resiliency support: If basic sanity checks are enabled (via F f.e.) (boot option) then SLUB will do the best to perform diagnostics and then continue (i.e. mark corrupted objects as used).
- Fix up numerous issues including clash of SLUBs use of page flags with i386 arch use for pmd and pgds (which are managed as slab caches, sigh).
- Dynamic per CPU array sizing.
- Explain SLUB slabcache flags
V1->V2
- Fix up various issues. Tested on i386 UP, X86_64 SMP, ia64 NUMA.
- Provide NUMA support by splitting partial lists per node.
- Better Slab cache merge support (now at around 50% of slabs)
- List slab cache aliases if slab caches are merged.
- Updated descriptions /proc/slabinfo output
This is a new slab allocator which was motivated by the complexity of the existing code in mm/slab.c. It attempts to address a variety of concerns with the existing implementation.
A. Management of object queues
A particular concern was the complex management of the numerous object queues in SLAB. SLUB has no such queues. Instead we dedicate a slab for each allocating CPU and use objects from a slab directly instead of queueing them up.
B. Storage overhead of object queues
SLAB Object queues exist per node, per CPU. The alien cache queue even has a queue array that contain a queue for each processor on each node. For very large systems the number of queues and the number of objects that may be caught in those queues grows exponentially. On our systems with 1k nodes / processors we have several gigabytes just tied up for storing references to objects for those queues This does not include the objects that could be on those queues. One fears that the whole memory of the machine could one day be consumed by those queues.
C. SLAB meta data overhead
SLAB has overhead at the beginning of each slab. This means that data cannot be naturally aligned at the beginning of a slab block. SLUB keeps all meta data in the corresponding page_struct. Objects can be naturally aligned in the slab. F.e. a 128 byte object will be aligned at 128 byte boundaries and can fit tightly into a 4k page with no bytes left over. SLAB cannot do this.
D. SLAB has a complex cache reaper
SLUB does not need a cache reaper for UP systems. On SMP systems the per CPU slab may be pushed back into partial list but that operation is simple and does not require an iteration over a list of objects. SLAB expires per CPU, shared and alien object queues during cache reaping which may cause strange hold offs.
E. SLAB has complex NUMA policy layer support
SLUB pushes NUMA policy handling into the page allocator. This means that allocation is coarser (SLUB does interleave on a page level) but that situation was also present before 2.6.13. SLABs application of policies to individual slab objects allocated in SLAB is certainly a performance concern due to the frequent references to memory policies which may lead a sequence of objects to come from one node after another. SLUB will get a slab full of objects from one node and then will switch to the next.
F. Reduction of the size of partial slab lists
SLAB has per node partial lists. This means that over time a large number of partial slabs may accumulate on those lists. These can only be reused if allocator occur on specific nodes. SLUB has a global pool of partial slabs and will consume slabs from that pool to decrease fragmentation.
G. Tunables
SLAB has sophisticated tuning abilities for each slab cache. One can manipulate the queue sizes in detail. However, filling the queues still requires the uses of the spin lock to check out slabs. SLUB has a global parameter (min_slab_order) for tuning. Increasing the minimum slab order can decrease the locking overhead. The bigger the slab order the less motions of pages between per CPU and partial lists occur and the better SLUB will be scaling.
G. Slab merging
We often have slab caches with similar parameters. SLUB detects those on boot up and merges them into the corresponding general caches. This leads to more effective memory use. About 50% of all caches can be eliminated through slab merging. This will also decrease slab fragmentation because partial allocated slabs can be filled up again. Slab merging can be switched off by specifying slub_nomerge on boot up.
Note that merging can expose heretofore unknown bugs in the kernel because corrupted objects may now be placed differently and corrupt differing neighboring objects. Enable sanity checks to find those.
H. Diagnostics
The current slab diagnostics are difficult to use and require a recompilation of the kernel. SLUB contains debugging code that is always available (but is kept out of the hot code paths). SLUB diagnostics can be enabled via the "slab_debug" option. Parameters can be specified to select a single or a group of slab caches for diagnostics. This means that the system is running with the usual performance and it is much more likely that race conditions can be reproduced.
I. Resiliency
If basic sanity checks are on then SLUB is capable of detecting common error conditions and recover as best as possible to allow the system to continue.
J. Tracing
Tracing can be enabled via the slab_debug=T,<slabcache> option during boot. SLUB will then protocol all actions on that slabcache and dump the object contents on free.
K. On demand DMA cache creation.
Generally DMA caches are not needed. If a kmalloc is used with __GFP_DMA then just create this single slabcache that is needed. For systems that have no ZONE_DMA requirement the support is completely eliminated.
L. Performance increase
Some benchmarks have shown speed improvements on kernbench in the range of 5-10%. The locking overhead of slub is based on the underlying base allocation size. If we can reliably allocate larger order pages then it is possible to increase slub performance much further. The anti-fragmentation patches may enable further performance increases.
Tested on:
i386 UP + SMP, x86_64 UP + SMP + NUMA emulation, IA64 NUMA + Simulator
SLUB Boot options
slub_nomerge Disable merging of slabs
slub_min_order=x Require a minimum order for slab caches. This
increases the managed chunk size and therefore reduces meta data and locking overhead.
slub_min_objects=x Mininum objects per slab. Default is 8.
slub_max_order=x Avoid generating slabs larger than order specified.slub_debug Enable all diagnostics for all caches
slub_debug=<options> Enable selective options for all caches
slub_debug=<o>,<cache> Enable selective options for a certain set of
caches
Available Debug options
F Double Free checking, sanity and resiliency
R Red zoning
P Object / padding poisoning
U Track last free / alloc
T Trace all allocs / frees (only use for individual slabs).
To use SLUB: Apply this patch and then select SLUB as the default slab allocator.
--
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>
PATCH 1/2 SLUB core
SLUB Core patch V6
This provides basic SLUB functionality and allows a choice of slab allocators during kernel configuration. The default is still slab. SLUB has been tested in various configurations but I think we can be quite sure that there are still remaining issues.
SLUB is not selectable on platforms that modify the page structs of slab memory (i386, FRV) but see the next patch for a i386 fix.
include/linux/mm_types.h +15 -2
@@ -19,10 +19,16 @@ struct page {unsigned long flags;/* Atomic flags, some possibly * updated asynchronously */ atomic_t _count;/* Usage count, see below. */ -atomic_t _mapcount;/* Count of ptes mapped in mms, +union { +atomic_t _mapcount;/* Count of ptes mapped in mms, * to show when page is mapped * & limit reverse map searches. */ +struct {/* SLUB uses */ +short unsigned int inuse; +short unsigned int offset; + }; + }; union { struct { unsigned long private; /* Mapping-private opaque data:
@@ -43,8 +49,15 @@ struct page {#if NR_CPUS >=CONFIG_SPLIT_PTLOCK_CPUS spinlock_t ptl;#endif +struct {/* SLUB uses */ +struct page *first_page;/* Compound pages */ +struct kmem_cache *slab;/* Pointer to slab */ + }; + }; +union { +pgoff_t index;/* Our offset within mapping. */ +void *freelist;/* SLUB: pointer to free object */ }; -pgoff_t index;/* Our offset within mapping. */ struct list_head lru;/* Pageout list, eg. active_list * protected by zone->lru_lock ! */
include/linux/slab.h +10 -4
@@ -32,6 +32,7 @@ typedef struct kmem_cache kmem_cache_t _#define SLAB_PANIC 0x00040000UL/* Panic if kmem_cache_create() fails */ #define SLAB_DESTROY_BY_RCU 0x00080000UL/* Defer freeing slabs to RCU */ #define SLAB_MEM_SPREAD 0x00100000UL/* Spread some memory over cpuset */ +#define SLAB_TRACE 0x00200000UL/* Trace allocations and frees */ /* Flags passed to a constructor functions */ #define SLAB_CTOR_CONSTRUCTOR 0x001UL/* If not set, then deconstructor */
@@ -42,7 +43,7 @@ typedef struct kmem_cache kmem_cache_t _* struct kmem_cache related prototypes */ void __init kmem_cache_init (void ); -extern int slab_is_available (void ); +int slab_is_available (void ); struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, unsigned long,
@@ -95,9 +96,14 @@ static inline void *kcalloc(size_t n, si* the appropriate general cache at compile time. */ -#ifdef CONFIG_SLAB +#if defined(CONFIG_SLAB ) || defined(CONFIG_SLUB ) +#ifdef CONFIG_SLUB +#include <linux/slub_def.h> +#else #include <linux/slab_def.h> +#endif /* !CONFIG_SLUB */ #else +/* * Fallback definitions for an allocator not wanting to provide * its own optimized kmalloc definitions (like SLOB).
@@ -184,7 +190,7 @@ static inline void *__kmalloc_node(size_* allocator where we care about the real place the memory allocation * request comes from. */ -#ifdef CONFIG_DEBUG_SLAB +#if defined(CONFIG_DEBUG_SLAB ) || defined(CONFIG_SLUB )extern void *__kmalloc_track_caller (size_t ,gfp_t ,void *);#define kmalloc_track_caller (size, flags) \ __kmalloc_track_caller(size, flags, __builtin_return_address(0))
@@ -202,7 +208,7 @@ extern void *__kmalloc_track_caller(size* standard allocator where we care about the real place the memory * allocation request comes from. */ -#ifdef CONFIG_DEBUG_SLAB +#if defined(CONFIG_DEBUG_SLAB ) || defined(CONFIG_SLUB )extern void *__kmalloc_node_track_caller (size_t ,gfp_t ,int ,void *);#define kmalloc_node_track_caller (size, flags, node) \ __kmalloc_node_track_caller(size, flags, node, \
include/linux/slub_def.h new file +206 -0
206 lines not on this page · raw message
init/Kconfig +40 -13
71 lines not on this page · raw message
mm/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_a obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o obj-$(CONFIG_SLOB) += slob.o obj-$(CONFIG_SLAB) += slab.o +obj-$(CONFIG_SLUB) += slub.o obj-$(CONFIG_MEMORY_HOTPLUG) += memory_hotplug.o obj-$(CONFIG_FS_XIP) += filemap_xip.o obj-$(CONFIG_MIGRATION) += migrate.o
mm/slub.c new file +2831 -0
2,637 lines not on this page · raw message
The rest of this diff is not shown. View the 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>
Part of the diff is not shown here. View the raw message.
PATCH 2/2 i386 arch page size slab fixes
In reply to Christoph LameterFixup i386 arch for SLUB support
i386 arch code currently uses the page struct of slabs for various purposes. This interferes with slub and so SLUB has been disabled for i386 by setting ARCH_USES_SLAB_PAGE_STRUCT.
This patch removes the use of page sized slabs for maintaining pgds and pmds.
Patch by William Irwin with only very minor modifications by me which are
1. Removal of HIGHMEM64G slab caches. It seems that virtualization hosts require a a full pgd page.
2. Add missing virtualization hook. Seems that we need a new way of serializing paravirt_alloc(). It may need to do its own serialization.
3. Remove ARCH_USES_SLAB_PAGE_STRUCT
Note that this makes things work without debugging on.
The arch still fails to boot properly if full SLUB debugging is on with a cryptic message:
CPU: AMD Athlon(tm) 64 Processor 3000+ stepping 00 Checking 'hlt' instruction... OK.
ACPI: Core revision 20070126
ACPI: setting ELCR to 0200 (from 1ca0)
BUG: at kernel/sched.c:3417 sub_preempt_count() [<c0342d43>] _spin_unlock_irq+0x13/0x30 [<c01160e6>] schedule_tail+0x36/0xd0 [<c0102df8>] __switch_to+0x28/0x180 [<c0103f9a>] ret_from_fork+0x6/0x1c [<c012acf0>] kthread+0x0/0xe0
This may have a coule of reasons:
1. SLUB breakage. kmalloc caches have been initialized but maybe debugging uses a facility that is not available that early (can find nothing).
2. SLAB does not enable full debugging for page order slabs. SLUB does. So we were so far unable to verify that the code is clean for these slabs. There could be some unsolved slab issues. i386 fails to boot if any of the debug options that require additional metadata at the end of an object or poisoning is enabled. Boot will work with sanity checks only.
arch/i386/mm/init.c +0 -25
@@ -696,31 +696,6 @@ int remove_memory(u64 start, u64 size)EXPORT_SYMBOL_GPL (remove_memory);#endif -struct kmem_cache *pgd_cache; -struct kmem_cache *pmd_cache; - -void __init pgtable_cache_init (void ) -{ -if (PTRS_PER_PMD >1 ) { - pmd_cache =kmem_cache_create ("pmd" , -PTRS_PER_PMD *sizeof (pmd_t), -PTRS_PER_PMD *sizeof (pmd_t), -0 , - pmd_ctor, -NULL ); -if (!pmd_cache) -panic ("pgtable_cache_init(): cannot create pmd cache" ); - } - pgd_cache =kmem_cache_create ("pgd" , -PTRS_PER_PGD *sizeof (pgd_t), -PTRS_PER_PGD *sizeof (pgd_t), -0 , - pgd_ctor, -PTRS_PER_PMD ==1 ? pgd_dtor :NULL ); -if (!pgd_cache) -panic ("pgtable_cache_init(): Cannot create pgd cache" ); -} -/* * This function cannot be __init, since exceptions don't work in that * section. Put this after the callers, so that it cannot be inlined.
arch/i386/mm/pageattr.c +6 -7
@@ -87,24 +87,23 @@ static void flush_kernel_map(void *arg)static void set_pmd_pte (pte_t *kpte,unsigned long address,pte_t pte) { -struct page *page; -unsigned long flags; +struct mm_struct *mm;set_pte_atomic (kpte, pte);/* change init_mm */ if (PTRS_PER_PMD >1 )return ; -spin_lock_irqsave (&pgd_lock, flags); -for (page = pgd_list; page; page = (struct page *)page->index) { -pgd_t *pgd; +spin_lock (&mmlist_lock); +list_for_each_entry (mm, &init_mm.mmlist, mmlist) { +pgd_t *pgd = mm->pgd;pud_t *pud;pmd_t *pmd; - pgd = (pgd_t *)page_address (page) +pgd_index (address); + pud =pud_offset (pgd, address); pmd =pmd_offset (pud, address);set_pte_atomic ((pte_t *)pmd, pte); } -spin_unlock_irqrestore (&pgd_lock, flags); +spin_unlock (&mmlist_lock); }/*
arch/i386/mm/pgtable.c +20 -99
146 lines not on this page · raw message
include/asm-i386/pgalloc.h +16 -2
@@ -35,8 +35,22 @@ do { \extern pgd_t *pgd_alloc (struct mm_struct *);extern void pgd_free (pgd_t *pgd); -extern pte_t *pte_alloc_one_kernel (struct mm_struct *,unsigned long ); -extern struct page *pte_alloc_one (struct mm_struct *,unsigned long ); +static inline pte_t *pte_alloc_one_kernel (struct mm_struct *mm,unsigned long uvaddr) +{ +return (pte_t *)get_zeroed_page (GFP_KERNEL |__GFP_REPEAT); +} + +#ifdef CONFIG_HIGHPTE +static inline struct page *pte_alloc_one (struct mm_struct *mm,unsigned long uvaddr) +{ +return alloc_page (GFP_KERNEL |__GFP_HIGHMEM|__GFP_REPEAT|__GFP_ZERO); +} +#else /* !CONFIG_HIGHPTE */ +static inline struct page *pte_alloc_one (struct mm_struct *mm,unsigned long uvaddr) +{ +return alloc_page (GFP_KERNEL |__GFP_REPEAT|__GFP_ZERO); +} +#endif /* !CONFIG_HIGHPTE */ static inline void pte_free_kernel (pte_t *pte) {
include/asm-i386/pgtable.h +0 -9
@@ -35,15 +35,6 @@ struct vm_area_struct;#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page))extern unsigned long empty_zero_page[1024 ];extern pgd_t swapper_pg_dir[1024 ]; -extern struct kmem_cache *pgd_cache; -extern struct kmem_cache *pmd_cache; -extern spinlock_t pgd_lock; -extern struct page *pgd_list; - -void pmd_ctor (void *,struct kmem_cache *,unsigned long ); -void pgd_ctor (void *,struct kmem_cache *,unsigned long ); -void pgd_dtor (void *,struct kmem_cache *,unsigned long ); -void pgtable_cache_init (void );void paging_init (void );/*
include/asm-i386/pgtable-2level.h +1 -0
@@ -67,5 +67,6 @@ static inline int pte_exec_kernel(pte_t#define __swp_entry_to_pte (x) ((pte_t) { (x).val })void vmalloc_sync_all (void ); +#define pgtable_cache_init () do { } while (0)#endif /* _I386_PGTABLE_2LEVEL_H */
include/asm-i386/pgtable-3level.h +1 -0
@@ -188,5 +188,6 @@ static inline pmd_t pfn_pmd(unsigned lon#define __pmd_free_tlb (tlb, x) do { } while (0)#define vmalloc_sync_all () ((void)0) +void pgtable_cache_init (void );#endif /* _I386_PGTABLE_3LEVEL_H */
arch/i386/mm/fault.c +12 -12
@@ -618,19 +618,19 @@ void vmalloc_sync_all(void)BUILD_BUG_ON (TASK_SIZE & ~PGDIR_MASK );for (address = start; address >=TASK_SIZE ; address +=PGDIR_SIZE ) {if (!test_bit (pgd_index (address), insync)) { -unsigned long flags; -struct page *page; +struct mm_struct *mm; +int broken =0 ; -spin_lock_irqsave (&pgd_lock, flags); -for (page = pgd_list; page; page = - (struct page *)page->index) -if (!vmalloc_sync_one (page_address (page), - address)) { -BUG_ON (page != pgd_list); -break ; - } -spin_unlock_irqrestore (&pgd_lock, flags); -if (!page) +spin_lock (&mmlist_lock); +list_for_each_entry (mm, &init_mm.mmlist, mmlist) { +if (vmalloc_sync_one (mm->pgd, address)) +continue ; +BUG_ON (mm->mmlist.prev != &init_mm.mmlist); + broken =1 ; +break ; + } +spin_unlock (&mmlist_lock); +if (!broken)set_bit (pgd_index (address), insync); }if (address == start &&test_bit (pgd_index (address), insync))
arch/i386/Kconfig +0 -4
@@ -79,10 +79,6 @@ config ARCH_MAY_HAVE_PC_FDC bool default y -config ARCH_USES_SLAB_PAGE_STRUCT - bool - default y - config DMI bool default y
--
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>
[SLUB tool] slabinfo: Display slab statistics
In reply to Christoph Lameter/*
* Slabinfo: Tool to get reports about slabs *
* (C) 2007 sgi, Christoph Lameter <[email protected]> *
* Compile by doing:
*
* gcc -o slabinfo slabinfo.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
char buffer[200];
int show_alias = 0;
int show_slab = 1;
int show_parameter = 0;
int skip_zero = 1;
int page_size;
void fatal(const char *x, ...)
{
va_list ap;
va_start(ap, x);
vfprintf(stderr, x, ap);
va_end(ap);
exit(1);
}/*
* Get the contents of an attribute
*/
unsigned long get_obj(char *name)
{
FILE *f = fopen(name, "r");
unsigned long result = 0;
if (!f) {
getcwd(buffer, sizeof(buffer));
fatal("Cannot open file '%s/%s'\n", buffer, name);
}
if (fgets(buffer,sizeof(buffer), f))
result = atol(buffer);
fclose(f);
return result;
}/*
* Put a size string together
*/
int store_size(char *buffer, unsigned long value)
{
unsigned long divisor = 1;
char trailer = 0;
int n;
if (value > 1000000000UL) {
divisor = 100000000UL;
trailer = 'G';
} else if (value > 1000000UL) {
divisor = 100000UL;
trailer = 'M';
} else if (value > 1000UL) {
divisor = 100;
trailer = 'K';
}
value /= divisor;
n = sprintf(buffer, "%ld",value);
if (trailer) {
buffer[n] = trailer;
n++;
buffer[n] = 0;
}
if (divisor != 1) {
memmove(buffer + n - 2, buffer + n - 3, 4);
buffer[n-2] = '.';
n++;
}
return n;
}void alias(const char *name)
{
char *target;
if (!show_alias)
return;
/* Read link target */
printf("%20s -> %s", name, target);
}int line = 0;
void first_line(void)
{
printf("Name Objects Objsize Space "
"Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n");
}void slab(const char *name)
{
unsigned long aliases, align, cache_dma, cpu_slabs, destroy_by_rcu;
unsigned long hwcache_align, object_size, objects, objs_per_slab;
unsigned long order, partial, poison, reclaim_account, red_zone;
unsigned long sanity_checks, slab_size, slabs, store_user, trace;
char size_str[20];
char dist_str[40];
char flags[20];
char *p = flags;
if (!show_slab)
return;
if (chdir(name))
fatal("Unable to access slab %s\n", name);
aliases = get_obj("aliases");
align = get_obj("align");
cache_dma = get_obj("cache_dma");
cpu_slabs = get_obj("cpu_slabs");
destroy_by_rcu = get_obj("destroy_by_rcu");
hwcache_align = get_obj("hwcache_align");
object_size = get_obj("object_size");
objects = get_obj("objects");
objs_per_slab = get_obj("objs_per_slab");
order = get_obj("order");
partial = get_obj("partial");
poison = get_obj("poison");
reclaim_account = get_obj("reclaim_account");
red_zone = get_obj("red_zone");
sanity_checks = get_obj("sanity_checks");
slab_size = get_obj("slab_size");
slabs = get_obj("slabs");
store_user = get_obj("store_user");
trace = get_obj("trace");
if (skip_zero && !slabs)
goto out;
store_size(size_str, slabs * page_size);
sprintf(dist_str,"%lu/%lu/%lu", slabs, partial, cpu_slabs);
if (!line++)
first_line();
if (aliases)
*p++ = '*';
if (cache_dma)
*p++ = 'd';
if (hwcache_align)
*p++ = 'A';
if (poison)
*p++ = 'P';
if (reclaim_account)
*p++ = 'a';
if (red_zone)
*p++ = 'Z';
if (sanity_checks)
*p++ = 'F';
if (store_user)
*p++ = 'U';
if (trace)
*p++ = 'T';
*p = 0;
printf("%-20s %8ld %7d %8s %14s %3ld %1ld %3d %3d %s\n",
name, objects, object_size, size_str, dist_str,
objs_per_slab, order,
slabs ? (partial * 100) / slabs : 100,
slabs ? (objects * object_size * 100) / (slabs * (page_size << order)) : 100,
flags);
out:
chdir("..");
}void parameter(const char *name)
{
if (!show_parameter)
return;
}int main(int argc, char *argv[])
{
DIR *dir;
struct dirent *de;
page_size = getpagesize();
if (chdir("/sys/slab"))
fatal("This kernel does not have SLUB support.\n");
dir = opendir(".");
while ((de = readdir(dir))) {
if (de->d_name[0] == '.')
continue;
switch (de->d_type) {
case DT_LNK:
alias(de->d_name);
break;
case DT_DIR:
slab(de->d_name);
break;
case DT_REG:
parameter(de->d_name);
break;
default :
fatal("Unknown file type %lx\n", de->d_type);
}
}
closedir(dir);
return 0;
}--
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>
Andrew Morton
maintainerRe: [SLUB 2/2] i386 arch page size slab fixes
In reply to Christoph LameterQuoted 26 lines · On Sat, 31 Mar 2007 11:31:07 -0800 (PST) Christoph Lameter <[email protected]>…
Fixup i386 arch for SLUB support
i386 arch code currently uses the page struct of slabs for various purposes. This interferes with slub and so SLUB has been disabled for i386 by setting
ARCH_USES_SLAB_PAGE_STRUCT.This patch removes the use of page sized slabs for maintaining pgds and pmds.
Patch by William Irwin with only very minor modifications by me which are
1. Removal of HIGHMEM64G slab caches. It seems that virtualization hosts require a a full pgd page.
2. Add missing virtualization hook. Seems that we need a new way of serializing
paravirt_alloc(). It may need to do its own serialization.3. Remove
ARCH_USES_SLAB_PAGE_STRUCTNote that this makes things work without debugging on.
The arch still fails to boot properly if full SLUB debugging is on with a cryptic message:CPU: AMD Athlon(tm) 64 Processor 3000+ stepping 00 Checking 'hlt' instruction... OK.
ACPI: Core revision 20070126
ACPI: setting ELCR to 0200 (from 1ca0)
Quoted 6 lines
BUG: at kernel/sched.c:3417 sub_preempt_count() [<c0342d43>] _spin_unlock_irq+0x13/0x30 [<c01160e6>] schedule_tail+0x36/0xd0 [<c0102df8>] __switch_to+0x28/0x180 [<c0103f9a>] ret_from_fork+0x6/0x1c [<c012acf0>] kthread+0x0/0xe0
This all has the potential to make my inbox hurt.
Can we disable SLUB on i386 in Kconfig until it gets sorted out?
--
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>
Re: [SLUB 2/2] i386 arch page size slab fixes
Quoted 1 line · Andrew Morton
Can we disable SLUB on i386 in
Kconfiguntil it gets sorted out?
Yes just do not apply this patch. The first one disables SLUB on i386.
--
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>
Re: [SLUB 2/2] i386 arch page size slab fixes
In reply to Andrew MortonQuoted 1 line · Andrew Morton
Can we disable SLUB on i386 in
Kconfiguntil it gets sorted out?
Found it. Another issue with relying on page size special casing in the SLAB.
i386: Another case of i386 exploiting page sized slab cache special casing
i386 uses kmalloc to allocate the thread structure assuming that the allocation results in a page size aligned allocation. That has worked so far because SLAB exempts page sized slabs from debugging and aligns them in special ways that gobeyond the restrictions imposed by KMALLOC_ARCH_MINALIGN (which are valid for all other kmalloc caches).
SLUB also works fine since the page sized allocations neatly align at page boundaries. However, if debugging is switched on then SLUB have to add additional debugging information after the object increasing the slab size. The total object only be aligned following the requirements imposed by KMALLOC_ARCH_MINALIGN. There is nothing there that would require a page size alignment.
The solution here is to replace the calls to kmalloc with calls into the page allocator. An alternate solution may be to create a custom slab cache and setting the alignment is to PAGE_SIZE (works with SLUB. There is no problem here with page_struct modifications). That would allow slub debugging to be used on the threadinfo structure.
But this is a page sized allocation after all and for efficiencies sake we should call directly into the page allocator and not use slab.
include/asm-i386/thread_info.h +5 -3
@@ -95,12 +95,14 @@/* thread information allocation */ #ifdef CONFIG_DEBUG_STACK_USAGE -#define alloc_thread_info (tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) +#define alloc_thread_info (tsk) ((struct thread_info *) \ + __get_free_pages(GFP_KERNEL| __GFP_ZERO, get_order(THREAD_SIZE)))#else -#define alloc_thread_info (tsk) kmalloc(THREAD_SIZE, GFP_KERNEL) +#define alloc_thread_info (tsk) ((struct thread_info *) \ + __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE)))#endif -#define free_thread_info (info) kfree(info) +#define free_thread_info (info) free_pages((unsigned long)(info), get_order(THREAD_SIZE))#else /* !__ASSEMBLY__ */
--
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>
Re: [SLUB 2/2] i386 arch page size slab fixes
In reply to Christoph LameterQuoted 3 lines · Christoph Lameter
Patch by William Irwin with only very minor modifications by me which are
1. Removal of HIGHMEM64G slab caches. It seems that virtualization hosts require a a full pgd page.
The HIGHMEM64G slab allocations are meaningfully performant vs. page-sized allocations where virtualization is absent. I would personally rather whip Xen into shape enough to be able to handle the minimal pgd allocations than retain the oversized pgd allocations even in only the Xen case. Also, the entire unshared kernel pmd shenanigan in Xen is an artifact of its recursive pagetable affair, which can also be done away with a SMOP.
Quoted 3 lines · Christoph Lameter
2. Add missing virtualization hook. Seems that we need a new way of serializing
paravirt_alloc(). It may need to do its own serialization.
3. RemoveARCH_USES_SLAB_PAGE_STRUCT
This doesn't quite cover all bases. The changes to pageattr.c and fault.c are dubious and need verification at the very least. They were largely slapped together to get the files past the compiler for the performance comparisons that were never properly done.
-- wli
--
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>
Re: [SLUB 2/2] i386 arch page size slab fixes
Quoted 4 lines · William Lee Irwin III
This doesn't quite cover all bases. The changes to
pageattr.candfault.care dubious and need verification at the very least. They were largely slapped together to get the files past the compiler for the performance comparisons that were never properly done.
I looked through them but then I am no i386 specialist though. Looked fine.
--
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>
Re: [SLUB 1/2] SLUB core
In reply to Christoph LameterQuoted 41 lines · Christoph Lameter
SLUB Core patch V6
This provides basic SLUB functionality and allows a choice of slab allocators during kernel configuration. The default is still slab. SLUB has been tested in various configurations but I think we can be quite sure that there are still remaining issues.
SLUB is not selectable on platforms that modify the page structs of slab memory (i386, FRV) but see the next patch for a i386 fix.
Signed-off-by Christoph Lameter <[email protected]>Index:
linux-2.6.21-rc5-mm3/include/linux/mm_types.h
===================================================================include/linux/mm_types.h +10
-1@@ -19,10 +19,16 @@ struct page {unsigned long flags;/* Atomic flags, some possibly * updated asynchronously */ atomic_t _count;/* Usage count, see below. */ -atomic_t _mapcount;/* Count of ptes mapped in mms, +union { +atomic_t _mapcount;/* Count of ptes mapped in mms, * to show when page is mapped * & limit reverse map searches. */ +struct {/* SLUB uses */ +short unsigned int inuse; +short unsigned int offset; + }; + }; union { struct { unsigned long private; /* Mapping-private opaque data:@@ -43,8 +49,15 @@ struct page {#if NR_CPUS >=CONFIG_SPLIT_PTLOCK_CPUS spinlock_t ptl;#endif +struct {/* SLUB uses */ +struct page *first_page;/* Compound pages */ +struct kmem_cache *slab;/* Pointer to slab */
include/linux/mm_types.h struct page { · line 63
Quoted 10 lines
include/linux/mm_types.h +5
-1+ }; + }; +union { +pgoff_t index;/* Our offset within mapping. */ +void *freelist;/* SLUB: pointer to free object */ }; -pgoff_t index;/* Our offset within mapping. */ struct list_head lru;/* Pageout list, eg. active_list * protected by zone->lru_lock ! */
I have an alternate suggestion for the struct page overloading issue.
I think anonymous unions are probably better than nothing, because they make the .c code more readable, but they clutter up the header badly and don't provide so strong type checking as we could implement.
This is just an incomplete RFC patch, because it actually requires a fair amount of types in .c code to be changed if we are to implement it (which I didn't want to do if nobody likes the idea).
(sorry it's an attachment, this mailer is broken)
Signature · 1 line
SUSE Labs, Novell Inc.
include/linux/mm_types.h +55 -21
@@ -23,27 +23,20 @@ struct page {* to show when page is mapped * & limit reverse map searches. */ -union { -struct { -unsigned long private;/* Mapping-private opaque data: -* usually used for buffer_heads -* if PagePrivate set; used for -* swp_entry_t if PageSwapCache; -* indicates order in the buddy -* system if PG_buddy is set. -*/ -struct address_space *mapping;/* If low bit clear, points to -* inode address_space, or NULL. -* If page mapped as anonymous -* memory, low bit is set, and -* it points to anon_vma object: -* see PAGE_MAPPING_ANON below. -*/ - }; -#if NR_CPUS >=CONFIG_SPLIT_PTLOCK_CPUS -spinlock_t ptl; -#endif - }; +unsigned long private;/* Mapping-private opaque data: +* usually used for buffer_heads +* if PagePrivate set; used for +* swp_entry_t if PageSwapCache; +* indicates order in the buddy +* system if PG_buddy is set. +*/ +struct address_space *mapping;/* If low bit clear, points to +* inode address_space, or NULL. +* If page mapped as anonymous +* memory, low bit is set, and +* it points to anon_vma object: +* see PAGE_MAPPING_ANON below. +*/ pgoff_t index;/* Our offset within mapping. */ struct list_head lru;/* Pageout list, eg. active_list * protected by zone->lru_lock !
@@ -64,4 +57,45 @@ struct page {#endif /* WANT_PAGE_VIRTUAL */ }; +/* +* We can provide alternate delcarations for 'struct page', instead of +* overloading fields that we would like to use for non-pagecache (eg. +* page tables or slab pages). However flags and _count must always be +* in the correct position, and not overloaded, because they might be +* accessed by thing without a direct reference (eg. buddy allocator, +* swsusp). So flags and _count get defined for us, and our struct is +* automatically padded out to the size of struct page. A compile time +* check ensures that this size isn't exceeded. +*/ +#define DEFINE_PAGE_STRUCT (name) \ +struct name { \ + union { \ + struct { \ + unsigned long flags; \ + atomic_t _count; \ + struct + +#define END_PAGE_STRUCT (name) \ + ; \ + }; \ + struct page ___page; \ + }; \ +}; \ + \ +static inline void struct_##name##_build_bug_on(void) \ +{ \ + BUILD_BUG_ON(sizeof(struct name) > sizeof(struct page)); \ +} + +DEFINE_PAGE_STRUCT (pt_page) { +#if NR_CPUS >=CONFIG_SPLIT_PTLOCK_CPUS +spinlock_t ptl; +#endif +}END_PAGE_STRUCT (pt_page) + +DEFINE_PAGE_STRUCT (buddy_page ) { +unsigned int order; +struct list_head list; +} END_PAGE_STRUCT(buddy_page) +#endif /* _LINUX_MM_TYPES_H */
mm/slab.c +5 -0
@@ -446,6 +446,11 @@ struct kmem_cache {#endif }; +DEFINE_PAGE_STRUCT (slab_page) { +struct list_head *cache; +struct list_head *slab; +} END_PAGE_STRUCT(slab_page) +#define CFLGS_OFF_SLAB (0x80000000UL)#define OFF_SLAB (x) ((x)->flags & CFLGS_OFF_SLAB)