]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
mm, slab, slub: clear the slab_cache field when freeing page
authorVlastimil Babka <vbabka@suse.cz>
Tue, 15 Dec 2020 03:04:29 +0000 (19:04 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 15 Dec 2020 20:13:37 +0000 (12:13 -0800)
The page allocator expects that page->mapping is NULL for a page being
freed.  SLAB and SLUB use the slab_cache field which is in union with
mapping, but before freeing the page, the field is referenced with the
"mapping" name when set to NULL.

It's IMHO more correct (albeit functionally the same) to use the
slab_cache name as that's the field we use in SL*B, and document why we
clear it in a comment (we don't clear fields such as s_mem or freelist, as
page allocator doesn't care about those).  While using the 'mapping' name
would automagically keep the code correct if the unions in struct page
changed, such changes should be done consciously and needed changes
evaluated - the comment should help with that.

Link: https://lkml.kernel.org/r/20201210160020.21562-1-vbabka@suse.cz
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/slab.c
mm/slub.c

index b1113561b98b17e76a509c667a16351c467e69bd..2e67a513b0c9a22583e6cfb9703fc70810a278e2 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1399,7 +1399,8 @@ static void kmem_freepages(struct kmem_cache *cachep, struct page *page)
        __ClearPageSlabPfmemalloc(page);
        __ClearPageSlab(page);
        page_mapcount_reset(page);
-       page->mapping = NULL;
+       /* In union with page->mapping where page allocator expects NULL */
+       page->slab_cache = NULL;
 
        if (current->reclaim_state)
                current->reclaim_state->reclaimed_slab += 1 << order;
index 34dcc09e2ec9b0fb746942002d26c65a8be21a56..2098a544c4e24144e3037ad9c6cd03a6e94189df 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1836,8 +1836,8 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
 
        __ClearPageSlabPfmemalloc(page);
        __ClearPageSlab(page);
-
-       page->mapping = NULL;
+       /* In union with page->mapping where page allocator expects NULL */
+       page->slab_cache = NULL;
        if (current->reclaim_state)
                current->reclaim_state->reclaimed_slab += pages;
        unaccount_slab_page(page, order, s);