Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp75374pxu; Thu, 10 Dec 2020 18:53:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgiCuvOMf/A8TfCvFEXORT0jG5OMl4olzsdXwoojoBZ2fbhufxx0jHSiYm0b9lslmnmXFL X-Received: by 2002:a17:906:5952:: with SMTP id g18mr8791186ejr.506.1607655204487; Thu, 10 Dec 2020 18:53:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607655204; cv=none; d=google.com; s=arc-20160816; b=xNIrHDu8l951y3x0r0nz1/bcTaKTsAioti4Dz6d0TNR1L+839YPFZvwDYz9rrB90gE 0z/EH/zgc01fWyau+SBRTLOzR82GOaPNk5gERwapOcX+xTRb7SKRsdIp+jXeK30ZQKZN jjgCRvUJNC7ALLxQ7YyIGx2mr0JGP+ozGEY/8z2H0lioEZy5tV34rfsnrs9/n277Pz5+ M7meoVu3iWC6Qqz0sQ1SIFIsrdbazVIMfu0ZzM4ziL0OeNTHSYDVd92m36R/yp0U/iSg wIrU4rhohQK9DfXdkjbgGNID2CaShDSLu0yvcTSDtpB7FNGzyX+5QzD0emXRtXRooQYG dOJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=XqxODTdB+8DSv0freRHhc4sntqPniwwaIFa4Gov9az0=; b=pwPYTA+759fZjPV0C4kHfT13cbh5Mfbgdp7ha2fIvrBT5toom6jkLuv6jv2pc/T+yL pue85Nd0To8mNyFLXQGqxDP6J3xEbqxNwLIYvB6+MXRftP8sR8vSD2vgPoU1E4yxYJsf tXDSuJKDZv9hfuCsxznpIo2yEHu1jySltbd7QmYjAhXntWXLYT0A54IaPZQtRIlpYy1m oWoeiH84qizBTfYajqnZUkyGuYPfpcVxXM8OXOm/6UvoMexT8xg4g7kyGc7T87m38zTt QPQM1S7j9tMszikHnnTf0UZX8MrG6rqPgZcyjpBrNpjzD/v+Xzq7dL/PWkXyJyooDnAm eAWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l6si3942921edq.274.2020.12.10.18.53.01; Thu, 10 Dec 2020 18:53:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391149AbgLJQBX (ORCPT + 99 others); Thu, 10 Dec 2020 11:01:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:49092 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392170AbgLJQBP (ORCPT ); Thu, 10 Dec 2020 11:01:15 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A4ABFAE2E; Thu, 10 Dec 2020 16:00:34 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Matthew Wilcox , Vlastimil Babka Subject: [PATCH] mm, slab, slub: clear the slab_cache field when freeing page Date: Thu, 10 Dec 2020 17:00:20 +0100 Message-Id: <20201210160020.21562-1-vbabka@suse.cz> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Vlastimil Babka --- mm/slab.c | 3 ++- mm/slub.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 72b6743bdccf..b667f03095f1 100644 --- 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; diff --git a/mm/slub.c b/mm/slub.c index d3406ef65863..81c22f4c7e63 100644 --- 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); -- 2.29.2