Skip to content

Commit f227f0f

Browse files
shakeelbtorvalds
authored andcommitted
slub: fix unreclaimable slab stat for bulk free
SLUB uses page allocator for higher order allocations and update unreclaimable slab stat for such allocations. At the moment, the bulk free for SLUB does not share code with normal free code path for these type of allocations and have missed the stat update. So, fix the stat update by common code. The user visible impact of the bug is the potential of inconsistent unreclaimable slab stat visible through meminfo and vmstat. Link: https://lkml.kernel.org/r/[email protected] Fixes: 6a486c0 ("mm, sl[ou]b: improve memory accounting") Signed-off-by: Shakeel Butt <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Roman Gushchin <[email protected]> Reviewed-by: Muchun Song <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: David Rientjes <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b5916c0 commit f227f0f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mm/slub.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,16 @@ struct detached_freelist {
32363236
struct kmem_cache *s;
32373237
};
32383238

3239+
static inline void free_nonslab_page(struct page *page)
3240+
{
3241+
unsigned int order = compound_order(page);
3242+
3243+
VM_BUG_ON_PAGE(!PageCompound(page), page);
3244+
kfree_hook(page_address(page));
3245+
mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order));
3246+
__free_pages(page, order);
3247+
}
3248+
32393249
/*
32403250
* This function progressively scans the array with free objects (with
32413251
* a limited look ahead) and extract objects belonging to the same
@@ -3272,9 +3282,7 @@ int build_detached_freelist(struct kmem_cache *s, size_t size,
32723282
if (!s) {
32733283
/* Handle kalloc'ed objects */
32743284
if (unlikely(!PageSlab(page))) {
3275-
BUG_ON(!PageCompound(page));
3276-
kfree_hook(object);
3277-
__free_pages(page, compound_order(page));
3285+
free_nonslab_page(page);
32783286
p[size] = NULL; /* mark object processed */
32793287
return size;
32803288
}
@@ -4250,13 +4258,7 @@ void kfree(const void *x)
42504258

42514259
page = virt_to_head_page(x);
42524260
if (unlikely(!PageSlab(page))) {
4253-
unsigned int order = compound_order(page);
4254-
4255-
BUG_ON(!PageCompound(page));
4256-
kfree_hook(object);
4257-
mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B,
4258-
-(PAGE_SIZE << order));
4259-
__free_pages(page, order);
4261+
free_nonslab_page(page);
42604262
return;
42614263
}
42624264
slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_);

0 commit comments

Comments
 (0)