Skip to content

Commit 1fe00d5

Browse files
JoonsooKimtorvalds
authored andcommitted
slab: factor out initialization of array cache
Factor out initialization of array cache to use it in following patch. Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Acked-by: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Acked-by: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 97654df commit 1fe00d5

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

‎mm/slab.c‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -791,29 +791,34 @@ static void start_cpu_timer(int cpu)
791791
}
792792
}
793793

794-
static struct array_cache *alloc_arraycache(int node, int entries,
795-
int batchcount, gfp_t gfp)
794+
static void init_arraycache(struct array_cache *ac, int limit, int batch)
796795
{
797-
int memsize = sizeof(void *) * entries + sizeof(struct array_cache);
798-
struct array_cache *nc = NULL;
799-
800-
nc = kmalloc_node(memsize, gfp, node);
801796
/*
802797
* The array_cache structures contain pointers to free object.
803798
* However, when such objects are allocated or transferred to another
804799
* cache the pointers are not cleared and they could be counted as
805800
* valid references during a kmemleak scan. Therefore, kmemleak must
806801
* not scan such objects.
807802
*/
808-
kmemleak_no_scan(nc);
809-
if (nc) {
810-
nc->avail = 0;
811-
nc->limit = entries;
812-
nc->batchcount = batchcount;
813-
nc->touched = 0;
814-
spin_lock_init(&nc->lock);
803+
kmemleak_no_scan(ac);
804+
if (ac) {
805+
ac->avail = 0;
806+
ac->limit = limit;
807+
ac->batchcount = batch;
808+
ac->touched = 0;
809+
spin_lock_init(&ac->lock);
815810
}
816-
return nc;
811+
}
812+
813+
static struct array_cache *alloc_arraycache(int node, int entries,
814+
int batchcount, gfp_t gfp)
815+
{
816+
int memsize = sizeof(void *) * entries + sizeof(struct array_cache);
817+
struct array_cache *ac = NULL;
818+
819+
ac = kmalloc_node(memsize, gfp, node);
820+
init_arraycache(ac, entries, batchcount);
821+
return ac;
817822
}
818823

819824
static inline bool is_slab_pfmemalloc(struct page *page)

0 commit comments

Comments
 (0)