aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slub.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-12-31 02:14:29 -0500
committerIngo Molnar <mingo@elte.hu>2008-12-31 02:14:29 -0500
commit5fdf7e5975a0b0f6a0370655612c5dca3fd6311b (patch)
tree639c536e818c6ace974aa285ba94576df0353b01 /mm/slub.c
parent7a51cffbd10886c0557677dd916c090097c691ef (diff)
parent6a94cb73064c952255336cc57731904174b2c58f (diff)
Merge branch 'linus' into tracing/kmemtrace
Conflicts: mm/slub.c
Diffstat (limited to 'mm/slub.c')
-rw-r--r--mm/slub.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/mm/slub.c b/mm/slub.c
index cc4001fee7ac..121acd17de97 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -25,6 +25,7 @@
25#include <linux/kallsyms.h> 25#include <linux/kallsyms.h>
26#include <linux/memory.h> 26#include <linux/memory.h>
27#include <linux/math64.h> 27#include <linux/math64.h>
28#include <linux/fault-inject.h>
28 29
29/* 30/*
30 * Lock order: 31 * Lock order:
@@ -154,6 +155,10 @@
154#define ARCH_SLAB_MINALIGN __alignof__(unsigned long long) 155#define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
155#endif 156#endif
156 157
158#define OO_SHIFT 16
159#define OO_MASK ((1 << OO_SHIFT) - 1)
160#define MAX_OBJS_PER_PAGE 65535 /* since page.objects is u16 */
161
157/* Internal SLUB flags */ 162/* Internal SLUB flags */
158#define __OBJECT_POISON 0x80000000 /* Poison object */ 163#define __OBJECT_POISON 0x80000000 /* Poison object */
159#define __SYSFS_ADD_DEFERRED 0x40000000 /* Not yet visible via sysfs */ 164#define __SYSFS_ADD_DEFERRED 0x40000000 /* Not yet visible via sysfs */
@@ -291,7 +296,7 @@ static inline struct kmem_cache_order_objects oo_make(int order,
291 unsigned long size) 296 unsigned long size)
292{ 297{
293 struct kmem_cache_order_objects x = { 298 struct kmem_cache_order_objects x = {
294 (order << 16) + (PAGE_SIZE << order) / size 299 (order << OO_SHIFT) + (PAGE_SIZE << order) / size
295 }; 300 };
296 301
297 return x; 302 return x;
@@ -299,12 +304,12 @@ static inline struct kmem_cache_order_objects oo_make(int order,
299 304
300static inline int oo_order(struct kmem_cache_order_objects x) 305static inline int oo_order(struct kmem_cache_order_objects x)
301{ 306{
302 return x.x >> 16; 307 return x.x >> OO_SHIFT;
303} 308}
304 309
305static inline int oo_objects(struct kmem_cache_order_objects x) 310static inline int oo_objects(struct kmem_cache_order_objects x)
306{ 311{
307 return x.x & ((1 << 16) - 1); 312 return x.x & OO_MASK;
308} 313}
309 314
310#ifdef CONFIG_SLUB_DEBUG 315#ifdef CONFIG_SLUB_DEBUG
@@ -693,7 +698,7 @@ static int check_object(struct kmem_cache *s, struct page *page,
693 if (!check_valid_pointer(s, page, get_freepointer(s, p))) { 698 if (!check_valid_pointer(s, page, get_freepointer(s, p))) {
694 object_err(s, page, p, "Freepointer corrupt"); 699 object_err(s, page, p, "Freepointer corrupt");
695 /* 700 /*
696 * No choice but to zap it and thus loose the remainder 701 * No choice but to zap it and thus lose the remainder
697 * of the free objects in this slab. May cause 702 * of the free objects in this slab. May cause
698 * another error because the object count is now wrong. 703 * another error because the object count is now wrong.
699 */ 704 */
@@ -765,8 +770,8 @@ static int on_freelist(struct kmem_cache *s, struct page *page, void *search)
765 } 770 }
766 771
767 max_objects = (PAGE_SIZE << compound_order(page)) / s->size; 772 max_objects = (PAGE_SIZE << compound_order(page)) / s->size;
768 if (max_objects > 65535) 773 if (max_objects > MAX_OBJS_PER_PAGE)
769 max_objects = 65535; 774 max_objects = MAX_OBJS_PER_PAGE;
770 775
771 if (page->objects != max_objects) { 776 if (page->objects != max_objects) {
772 slab_err(s, page, "Wrong number of objects. Found %d but " 777 slab_err(s, page, "Wrong number of objects. Found %d but "
@@ -1592,6 +1597,11 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
1592 unsigned long flags; 1597 unsigned long flags;
1593 unsigned int objsize; 1598 unsigned int objsize;
1594 1599
1600 might_sleep_if(gfpflags & __GFP_WAIT);
1601
1602 if (should_failslab(s->objsize, gfpflags))
1603 return NULL;
1604
1595 local_irq_save(flags); 1605 local_irq_save(flags);
1596 c = get_cpu_slab(s, smp_processor_id()); 1606 c = get_cpu_slab(s, smp_processor_id());
1597 objsize = c->objsize; 1607 objsize = c->objsize;
@@ -1766,7 +1776,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
1766} 1776}
1767EXPORT_SYMBOL(kmem_cache_free); 1777EXPORT_SYMBOL(kmem_cache_free);
1768 1778
1769/* Figure out on which slab object the object resides */ 1779/* Figure out on which slab page the object resides */
1770static struct page *get_object_page(const void *x) 1780static struct page *get_object_page(const void *x)
1771{ 1781{
1772 struct page *page = virt_to_head_page(x); 1782 struct page *page = virt_to_head_page(x);
@@ -1838,8 +1848,8 @@ static inline int slab_order(int size, int min_objects,
1838 int rem; 1848 int rem;
1839 int min_order = slub_min_order; 1849 int min_order = slub_min_order;
1840 1850
1841 if ((PAGE_SIZE << min_order) / size > 65535) 1851 if ((PAGE_SIZE << min_order) / size > MAX_OBJS_PER_PAGE)
1842 return get_order(size * 65535) - 1; 1852 return get_order(size * MAX_OBJS_PER_PAGE) - 1;
1843 1853
1844 for (order = max(min_order, 1854 for (order = max(min_order,
1845 fls(min_objects * size - 1) - PAGE_SHIFT); 1855 fls(min_objects * size - 1) - PAGE_SHIFT);
@@ -2104,8 +2114,7 @@ static inline int alloc_kmem_cache_cpus(struct kmem_cache *s, gfp_t flags)
2104 * when allocating for the kmalloc_node_cache. This is used for bootstrapping 2114 * when allocating for the kmalloc_node_cache. This is used for bootstrapping
2105 * memory on a fresh node that has no slab structures yet. 2115 * memory on a fresh node that has no slab structures yet.
2106 */ 2116 */
2107static struct kmem_cache_node *early_kmem_cache_node_alloc(gfp_t gfpflags, 2117static void early_kmem_cache_node_alloc(gfp_t gfpflags, int node)
2108 int node)
2109{ 2118{
2110 struct page *page; 2119 struct page *page;
2111 struct kmem_cache_node *n; 2120 struct kmem_cache_node *n;
@@ -2143,7 +2152,6 @@ static struct kmem_cache_node *early_kmem_cache_node_alloc(gfp_t gfpflags,
2143 local_irq_save(flags); 2152 local_irq_save(flags);
2144 add_partial(n, page, 0); 2153 add_partial(n, page, 0);
2145 local_irq_restore(flags); 2154 local_irq_restore(flags);
2146 return n;
2147} 2155}
2148 2156
2149static void free_kmem_cache_nodes(struct kmem_cache *s) 2157static void free_kmem_cache_nodes(struct kmem_cache *s)
@@ -2175,8 +2183,7 @@ static int init_kmem_cache_nodes(struct kmem_cache *s, gfp_t gfpflags)
2175 n = &s->local_node; 2183 n = &s->local_node;
2176 else { 2184 else {
2177 if (slab_state == DOWN) { 2185 if (slab_state == DOWN) {
2178 n = early_kmem_cache_node_alloc(gfpflags, 2186 early_kmem_cache_node_alloc(gfpflags, node);
2179 node);
2180 continue; 2187 continue;
2181 } 2188 }
2182 n = kmem_cache_alloc_node(kmalloc_caches, 2189 n = kmem_cache_alloc_node(kmalloc_caches,
@@ -3176,8 +3183,12 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
3176 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *))); 3183 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
3177 up_write(&slub_lock); 3184 up_write(&slub_lock);
3178 3185
3179 if (sysfs_slab_alias(s, name)) 3186 if (sysfs_slab_alias(s, name)) {
3187 down_write(&slub_lock);
3188 s->refcount--;
3189 up_write(&slub_lock);
3180 goto err; 3190 goto err;
3191 }
3181 return s; 3192 return s;
3182 } 3193 }
3183 3194
@@ -3187,8 +3198,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
3187 size, align, flags, ctor)) { 3198 size, align, flags, ctor)) {
3188 list_add(&s->list, &slab_caches); 3199 list_add(&s->list, &slab_caches);
3189 up_write(&slub_lock); 3200 up_write(&slub_lock);
3190 if (sysfs_slab_add(s)) 3201 if (sysfs_slab_add(s)) {
3202 down_write(&slub_lock);
3203 list_del(&s->list);
3204 up_write(&slub_lock);
3205 kfree(s);
3191 goto err; 3206 goto err;
3207 }
3192 return s; 3208 return s;
3193 } 3209 }
3194 kfree(s); 3210 kfree(s);
@@ -4412,7 +4428,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
4412 4428
4413/* 4429/*
4414 * Need to buffer aliases during bootup until sysfs becomes 4430 * Need to buffer aliases during bootup until sysfs becomes
4415 * available lest we loose that information. 4431 * available lest we lose that information.
4416 */ 4432 */
4417struct saved_alias { 4433struct saved_alias {
4418 struct kmem_cache *s; 4434 struct kmem_cache *s;