Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1343800
| From | js1304@gmail.com |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 11/17] mm/slab: clean up cache type determination |
| Date | 2016-02-26 07:10 +0100 |
| Message-ID | <r6jLc-7pr-13@gated-at.bofh.it> (permalink) |
| References | <r6jLb-7pr-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Current cache type determination code is open-code and looks not
understandable. Following patch will introduce one more cache type and it
would make code more complex. So, before it happens, this patch abstracts
these codes.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/slab.c | 105 ++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 71 insertions(+), 34 deletions(-)
diff --git a/mm/slab.c b/mm/slab.c
index d5dffc8..9b56685 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2023,6 +2023,64 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
return cachep;
}
+static bool set_off_slab_cache(struct kmem_cache *cachep,
+ size_t size, unsigned long flags)
+{
+ size_t left;
+
+ cachep->num = 0;
+
+ /*
+ * Determine if the slab management is 'on' or 'off' slab.
+ * (bootstrapping cannot cope with offslab caches so don't do
+ * it too early on. Always use on-slab management when
+ * SLAB_NOLEAKTRACE to avoid recursive calls into kmemleak)
+ */
+ if (size < OFF_SLAB_MIN_SIZE)
+ return false;
+
+ if (slab_early_init)
+ return false;
+
+ if (flags & SLAB_NOLEAKTRACE)
+ return false;
+
+ /*
+ * Size is large, assume best to place the slab management obj
+ * off-slab (should allow better packing of objs).
+ */
+ left = calculate_slab_order(cachep, size, flags | CFLGS_OFF_SLAB);
+ if (!cachep->num)
+ return false;
+
+ /*
+ * If the slab has been placed off-slab, and we have enough space then
+ * move it on-slab. This is at the expense of any extra colouring.
+ */
+ if (left >= cachep->num * sizeof(freelist_idx_t))
+ return false;
+
+ cachep->colour = left / cachep->colour_off;
+
+ return true;
+}
+
+static bool set_on_slab_cache(struct kmem_cache *cachep,
+ size_t size, unsigned long flags)
+{
+ size_t left;
+
+ cachep->num = 0;
+
+ left = calculate_slab_order(cachep, size, flags);
+ if (!cachep->num)
+ return false;
+
+ cachep->colour = left / cachep->colour_off;
+
+ return true;
+}
+
/**
* __kmem_cache_create - Create a cache.
* @cachep: cache management descriptor
@@ -2047,7 +2105,6 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
int
__kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
{
- size_t left_over, freelist_size;
size_t ralign = BYTES_PER_WORD;
gfp_t gfp;
int err;
@@ -2098,6 +2155,10 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
* 4) Store it.
*/
cachep->align = ralign;
+ cachep->colour_off = cache_line_size();
+ /* Offset must be a multiple of the alignment. */
+ if (cachep->colour_off < cachep->align)
+ cachep->colour_off = cachep->align;
if (slab_is_available())
gfp = GFP_KERNEL;
@@ -2152,43 +2213,18 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
}
#endif
- /*
- * Determine if the slab management is 'on' or 'off' slab.
- * (bootstrapping cannot cope with offslab caches so don't do
- * it too early on. Always use on-slab management when
- * SLAB_NOLEAKTRACE to avoid recursive calls into kmemleak)
- */
- if (size >= OFF_SLAB_MIN_SIZE && !slab_early_init &&
- !(flags & SLAB_NOLEAKTRACE)) {
- /*
- * Size is large, assume best to place the slab management obj
- * off-slab (should allow better packing of objs).
- */
+ if (set_off_slab_cache(cachep, size, flags)) {
flags |= CFLGS_OFF_SLAB;
+ goto done;
}
- left_over = calculate_slab_order(cachep, size, flags);
-
- if (!cachep->num)
- return -E2BIG;
-
- freelist_size = cachep->num * sizeof(freelist_idx_t);
+ if (set_on_slab_cache(cachep, size, flags))
+ goto done;
- /*
- * If the slab has been placed off-slab, and we have enough space then
- * move it on-slab. This is at the expense of any extra colouring.
- */
- if (flags & CFLGS_OFF_SLAB && left_over >= freelist_size) {
- flags &= ~CFLGS_OFF_SLAB;
- left_over -= freelist_size;
- }
+ return -E2BIG;
- cachep->colour_off = cache_line_size();
- /* Offset must be a multiple of the alignment. */
- if (cachep->colour_off < cachep->align)
- cachep->colour_off = cachep->align;
- cachep->colour = left_over / cachep->colour_off;
- cachep->freelist_size = freelist_size;
+done:
+ cachep->freelist_size = cachep->num * sizeof(freelist_idx_t);
cachep->flags = flags;
cachep->allocflags = __GFP_COMP;
if (CONFIG_ZONE_DMA_FLAG && (flags & SLAB_CACHE_DMA))
@@ -2209,7 +2245,8 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
#endif
if (OFF_SLAB(cachep)) {
- cachep->freelist_cache = kmalloc_slab(freelist_size, 0u);
+ cachep->freelist_cache =
+ kmalloc_slab(cachep->freelist_size, 0u);
/*
* This is a possibility for one of the kmalloc_{dma,}_caches.
* But since we go off slab only for object size greater than
--
1.9.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 00/17] mm/slab: introduce new freed objects management way, OBJFREELIST_SLAB js1304@gmail.com - 2016-02-26 07:10 +0100
[PATCH v2 16/17] mm/slab: introduce new slab management type, OBJFREELIST_SLAB js1304@gmail.com - 2016-02-26 07:10 +0100
Re: [PATCH v2 16/17] mm/slab: introduce new slab management type, OBJFREELIST_SLAB Christoph Lameter <cl@linux.com> - 2016-02-26 17:30 +0100
Re: [PATCH v2 16/17] mm/slab: introduce new slab management type, OBJFREELIST_SLAB Joonsoo Kim <js1304@gmail.com> - 2016-02-26 18:10 +0100
[PATCH v2 11/17] mm/slab: clean up cache type determination js1304@gmail.com - 2016-02-26 07:10 +0100
[PATCH v2 03/17] mm/slab: remove the checks for slab implementation bug js1304@gmail.com - 2016-02-26 07:10 +0100
Re: [PATCH v2 03/17] mm/slab: remove the checks for slab implementation bug Christoph Lameter <cl@linux.com> - 2016-02-26 17:10 +0100
[PATCH v2 01/17] mm/slab: fix stale code comment js1304@gmail.com - 2016-02-26 07:10 +0100
[PATCH v2 04/17] mm/slab: activate debug_pagealloc in SLAB when it is actually enabled js1304@gmail.com - 2016-02-26 07:10 +0100
Re: [PATCH v2 04/17] mm/slab: activate debug_pagealloc in SLAB when it is actually enabled Christoph Lameter <cl@linux.com> - 2016-02-26 17:10 +0100
[PATCH v2 05/17] mm/slab: use more appropriate condition check for debug_pagealloc js1304@gmail.com - 2016-02-26 07:10 +0100
Re: [PATCH v2 05/17] mm/slab: use more appropriate condition check for debug_pagealloc Christoph Lameter <cl@linux.com> - 2016-02-26 17:10 +0100
[PATCH v2 09/17] mm/slab: put the freelist at the end of slab page js1304@gmail.com - 2016-02-26 07:10 +0100
[PATCH v2 07/17] mm/slab: alternative implementation for DEBUG_SLAB_LEAK js1304@gmail.com - 2016-02-26 07:10 +0100
[PATCH v2 13/17] mm/slab: make criteria for off slab determination robust and simple js1304@gmail.com - 2016-02-26 07:10 +0100
[PATCH v2 12/17] mm/slab: do not change cache size if debug pagealloc isn't possible js1304@gmail.com - 2016-02-26 07:10 +0100
Re: [PATCH v2 12/17] mm/slab: do not change cache size if debug pagealloc isn't possible Christoph Lameter <cl@linux.com> - 2016-02-26 17:20 +0100
Re: [PATCH v2 12/17] mm/slab: do not change cache size if debug pagealloc isn't possible Joonsoo Kim <js1304@gmail.com> - 2016-02-26 18:10 +0100
[PATCH v2 17/17] mm/slab: avoid returning values by reference js1304@gmail.com - 2016-02-26 07:10 +0100
Re: [PATCH v2 17/17] mm/slab: avoid returning values by reference Christoph Lameter <cl@linux.com> - 2016-02-26 17:30 +0100
[PATCH v2 06/17] mm/slab: clean up DEBUG_PAGEALLOC processing code js1304@gmail.com - 2016-02-26 07:10 +0100
[PATCH v2 08/17] mm/slab: remove object status buffer for DEBUG_SLAB_LEAK js1304@gmail.com - 2016-02-26 07:10 +0100
csiph-web