|
@@ -211,6 +211,8 @@ static inline void ClearSlabDebug(struct page *page)
|
|
|
/* Internal SLUB flags */
|
|
|
#define __OBJECT_POISON 0x80000000 /* Poison object */
|
|
|
#define __SYSFS_ADD_DEFERRED 0x40000000 /* Not yet visible via sysfs */
|
|
|
+#define __KMALLOC_CACHE 0x20000000 /* objects freed using kfree */
|
|
|
+#define __PAGE_ALLOC_FALLBACK 0x10000000 /* Allow fallback to page alloc */
|
|
|
|
|
|
/* Not all arches define cache_line_size */
|
|
|
#ifndef cache_line_size
|
|
@@ -308,7 +310,7 @@ static inline int is_end(void *addr)
|
|
|
return (unsigned long)addr & PAGE_MAPPING_ANON;
|
|
|
}
|
|
|
|
|
|
-void *slab_address(struct page *page)
|
|
|
+static void *slab_address(struct page *page)
|
|
|
{
|
|
|
return page->end - PAGE_MAPPING_ANON;
|
|
|
}
|
|
@@ -1078,14 +1080,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
|
|
|
struct page *page;
|
|
|
int pages = 1 << s->order;
|
|
|
|
|
|
- if (s->order)
|
|
|
- flags |= __GFP_COMP;
|
|
|
-
|
|
|
- if (s->flags & SLAB_CACHE_DMA)
|
|
|
- flags |= SLUB_DMA;
|
|
|
-
|
|
|
- if (s->flags & SLAB_RECLAIM_ACCOUNT)
|
|
|
- flags |= __GFP_RECLAIMABLE;
|
|
|
+ flags |= s->allocflags;
|
|
|
|
|
|
if (node == -1)
|
|
|
page = alloc_pages(flags, s->order);
|
|
@@ -1546,7 +1541,6 @@ load_freelist:
|
|
|
unlock_out:
|
|
|
slab_unlock(c->page);
|
|
|
stat(c, ALLOC_SLOWPATH);
|
|
|
-out:
|
|
|
#ifdef SLUB_FASTPATH
|
|
|
local_irq_restore(flags);
|
|
|
#endif
|
|
@@ -1581,8 +1575,24 @@ new_slab:
|
|
|
c->page = new;
|
|
|
goto load_freelist;
|
|
|
}
|
|
|
- object = NULL;
|
|
|
- goto out;
|
|
|
+#ifdef SLUB_FASTPATH
|
|
|
+ local_irq_restore(flags);
|
|
|
+#endif
|
|
|
+ /*
|
|
|
+ * No memory available.
|
|
|
+ *
|
|
|
+ * If the slab uses higher order allocs but the object is
|
|
|
+ * smaller than a page size then we can fallback in emergencies
|
|
|
+ * to the page allocator via kmalloc_large. The page allocator may
|
|
|
+ * have failed to obtain a higher order page and we can try to
|
|
|
+ * allocate a single page if the object fits into a single page.
|
|
|
+ * That is only possible if certain conditions are met that are being
|
|
|
+ * checked when a slab is created.
|
|
|
+ */
|
|
|
+ if (!(gfpflags & __GFP_NORETRY) && (s->flags & __PAGE_ALLOC_FALLBACK))
|
|
|
+ return kmalloc_large(s->objsize, gfpflags);
|
|
|
+
|
|
|
+ return NULL;
|
|
|
debug:
|
|
|
object = c->page->freelist;
|
|
|
if (!alloc_debug_processing(s, c->page, object, addr))
|
|
@@ -2329,10 +2339,33 @@ static int calculate_sizes(struct kmem_cache *s)
|
|
|
size = ALIGN(size, align);
|
|
|
s->size = size;
|
|
|
|
|
|
- s->order = calculate_order(size);
|
|
|
+ if ((flags & __KMALLOC_CACHE) &&
|
|
|
+ PAGE_SIZE / size < slub_min_objects) {
|
|
|
+ /*
|
|
|
+ * Kmalloc cache that would not have enough objects in
|
|
|
+ * an order 0 page. Kmalloc slabs can fallback to
|
|
|
+ * page allocator order 0 allocs so take a reasonably large
|
|
|
+ * order that will allows us a good number of objects.
|
|
|
+ */
|
|
|
+ s->order = max(slub_max_order, PAGE_ALLOC_COSTLY_ORDER);
|
|
|
+ s->flags |= __PAGE_ALLOC_FALLBACK;
|
|
|
+ s->allocflags |= __GFP_NOWARN;
|
|
|
+ } else
|
|
|
+ s->order = calculate_order(size);
|
|
|
+
|
|
|
if (s->order < 0)
|
|
|
return 0;
|
|
|
|
|
|
+ s->allocflags = 0;
|
|
|
+ if (s->order)
|
|
|
+ s->allocflags |= __GFP_COMP;
|
|
|
+
|
|
|
+ if (s->flags & SLAB_CACHE_DMA)
|
|
|
+ s->allocflags |= SLUB_DMA;
|
|
|
+
|
|
|
+ if (s->flags & SLAB_RECLAIM_ACCOUNT)
|
|
|
+ s->allocflags |= __GFP_RECLAIMABLE;
|
|
|
+
|
|
|
/*
|
|
|
* Determine the number of objects per slab
|
|
|
*/
|
|
@@ -2484,11 +2517,11 @@ EXPORT_SYMBOL(kmem_cache_destroy);
|
|
|
* Kmalloc subsystem
|
|
|
*******************************************************************/
|
|
|
|
|
|
-struct kmem_cache kmalloc_caches[PAGE_SHIFT] __cacheline_aligned;
|
|
|
+struct kmem_cache kmalloc_caches[PAGE_SHIFT + 1] __cacheline_aligned;
|
|
|
EXPORT_SYMBOL(kmalloc_caches);
|
|
|
|
|
|
#ifdef CONFIG_ZONE_DMA
|
|
|
-static struct kmem_cache *kmalloc_caches_dma[PAGE_SHIFT];
|
|
|
+static struct kmem_cache *kmalloc_caches_dma[PAGE_SHIFT + 1];
|
|
|
#endif
|
|
|
|
|
|
static int __init setup_slub_min_order(char *str)
|
|
@@ -2536,7 +2569,7 @@ static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
|
|
|
|
|
|
down_write(&slub_lock);
|
|
|
if (!kmem_cache_open(s, gfp_flags, name, size, ARCH_KMALLOC_MINALIGN,
|
|
|
- flags, NULL))
|
|
|
+ flags | __KMALLOC_CACHE, NULL))
|
|
|
goto panic;
|
|
|
|
|
|
list_add(&s->list, &slab_caches);
|
|
@@ -2670,9 +2703,8 @@ void *__kmalloc(size_t size, gfp_t flags)
|
|
|
{
|
|
|
struct kmem_cache *s;
|
|
|
|
|
|
- if (unlikely(size > PAGE_SIZE / 2))
|
|
|
- return (void *)__get_free_pages(flags | __GFP_COMP,
|
|
|
- get_order(size));
|
|
|
+ if (unlikely(size > PAGE_SIZE))
|
|
|
+ return kmalloc_large(size, flags);
|
|
|
|
|
|
s = get_slab(size, flags);
|
|
|
|
|
@@ -2688,9 +2720,8 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
|
|
|
{
|
|
|
struct kmem_cache *s;
|
|
|
|
|
|
- if (unlikely(size > PAGE_SIZE / 2))
|
|
|
- return (void *)__get_free_pages(flags | __GFP_COMP,
|
|
|
- get_order(size));
|
|
|
+ if (unlikely(size > PAGE_SIZE))
|
|
|
+ return kmalloc_large(size, flags);
|
|
|
|
|
|
s = get_slab(size, flags);
|
|
|
|
|
@@ -3001,7 +3032,7 @@ void __init kmem_cache_init(void)
|
|
|
caches++;
|
|
|
}
|
|
|
|
|
|
- for (i = KMALLOC_SHIFT_LOW; i < PAGE_SHIFT; i++) {
|
|
|
+ for (i = KMALLOC_SHIFT_LOW; i <= PAGE_SHIFT; i++) {
|
|
|
create_kmalloc_cache(&kmalloc_caches[i],
|
|
|
"kmalloc", 1 << i, GFP_KERNEL);
|
|
|
caches++;
|
|
@@ -3028,7 +3059,7 @@ void __init kmem_cache_init(void)
|
|
|
slab_state = UP;
|
|
|
|
|
|
/* Provide the correct kmalloc names now that the caches are up */
|
|
|
- for (i = KMALLOC_SHIFT_LOW; i < PAGE_SHIFT; i++)
|
|
|
+ for (i = KMALLOC_SHIFT_LOW; i <= PAGE_SHIFT; i++)
|
|
|
kmalloc_caches[i]. name =
|
|
|
kasprintf(GFP_KERNEL, "kmalloc-%d", 1 << i);
|
|
|
|
|
@@ -3057,6 +3088,9 @@ static int slab_unmergeable(struct kmem_cache *s)
|
|
|
if (slub_nomerge || (s->flags & SLUB_NEVER_MERGE))
|
|
|
return 1;
|
|
|
|
|
|
+ if ((s->flags & __PAGE_ALLOC_FALLBACK))
|
|
|
+ return 1;
|
|
|
+
|
|
|
if (s->ctor)
|
|
|
return 1;
|
|
|
|
|
@@ -3218,9 +3252,9 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, void *caller)
|
|
|
{
|
|
|
struct kmem_cache *s;
|
|
|
|
|
|
- if (unlikely(size > PAGE_SIZE / 2))
|
|
|
- return (void *)__get_free_pages(gfpflags | __GFP_COMP,
|
|
|
- get_order(size));
|
|
|
+ if (unlikely(size > PAGE_SIZE))
|
|
|
+ return kmalloc_large(size, gfpflags);
|
|
|
+
|
|
|
s = get_slab(size, gfpflags);
|
|
|
|
|
|
if (unlikely(ZERO_OR_NULL_PTR(s)))
|
|
@@ -3234,9 +3268,9 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
|
|
|
{
|
|
|
struct kmem_cache *s;
|
|
|
|
|
|
- if (unlikely(size > PAGE_SIZE / 2))
|
|
|
- return (void *)__get_free_pages(gfpflags | __GFP_COMP,
|
|
|
- get_order(size));
|
|
|
+ if (unlikely(size > PAGE_SIZE))
|
|
|
+ return kmalloc_large(size, gfpflags);
|
|
|
+
|
|
|
s = get_slab(size, gfpflags);
|
|
|
|
|
|
if (unlikely(ZERO_OR_NULL_PTR(s)))
|