From patchwork Wed Dec 1 18:14:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12650701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A83A8C4332F for ; Wed, 1 Dec 2021 18:20:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 003966B0083; Wed, 1 Dec 2021 13:15:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC3DE6B0088; Wed, 1 Dec 2021 13:15:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 842856B0083; Wed, 1 Dec 2021 13:15:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id 3FB8F6B0087 for ; Wed, 1 Dec 2021 13:15:29 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 084A089D37 for ; Wed, 1 Dec 2021 18:15:19 +0000 (UTC) X-FDA: 78870027558.06.60664DA Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf24.hostedemail.com (Postfix) with ESMTP id 36052B0000A1 for ; Wed, 1 Dec 2021 18:15:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 17607218A9; Wed, 1 Dec 2021 18:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1638382517; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kZxMyj6Wp8HA56QwK3f0tcjB2n7iq+1Of+4MuQIlFE8=; b=ZzPI8nUDggoCYrIrBCiVNqqJyxnDcsUU2840V+/OqeTwr9bVRfV9nhd5js9If5IUHDLAJ+ Q9xMSPX6PPsUBaihtOJGGfUCUnKJ1Q59s14riSFYCTTYmdOfY5YS2dkk758w6ARHQs1nGv 0ptlglcQOYdQgfyMeGV8VE6PDDwndYM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1638382517; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kZxMyj6Wp8HA56QwK3f0tcjB2n7iq+1Of+4MuQIlFE8=; b=Z56jISVIqoRA/EaTNYJMD4n4zO1d6Rtb3+K/57kxN2goH84pRtg/HafIlZDrtbhzJ4QzSY ZXnYsc9tkgaBhnCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E940214050; Wed, 1 Dec 2021 18:15:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WI9nOLS7p2HPSAAAMHmgww (envelope-from ); Wed, 01 Dec 2021 18:15:16 +0000 From: Vlastimil Babka To: Matthew Wilcox , Christoph Lameter , David Rientjes , Joonsoo Kim , Pekka Enberg Cc: linux-mm@kvack.org, Andrew Morton , patches@lists.linux.dev, Vlastimil Babka Subject: [PATCH v2 11/33] mm/slub: Convert kfree() to use a struct slab Date: Wed, 1 Dec 2021 19:14:48 +0100 Message-Id: <20211201181510.18784-12-vbabka@suse.cz> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211201181510.18784-1-vbabka@suse.cz> References: <20211201181510.18784-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2119; i=vbabka@suse.cz; h=from:subject; bh=MtR80ZILh+jqjffo/Kbuxz56SWHzzZyNMAh7fcGLzpk=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhp7t2hlVDUcX4WrIhp6ivzBG7+xn8yk3HfpPz9NXA 4rv1bRKJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYae7dgAKCRDgIcpz8YmpEKrgB/ wL5Qj23adTLhJRPSmKsNy+ZqU2ckI5jc7W2bfxAApMUPlGwMxfv1t1hKBey3aLL+W2RB/4fV7Ac+fX UjtWNsOr0wosh+1RorYwnb8YgSmYPA7Aacw2UM0CgFI8DUxwis8/TY+Bdp58zJxYLRUziV/UrVQxpC 5EMbpqJ0uBuKgejt08aD/fDvwkbIFrXcpJMZ1Yw9u7puB9Tj3cPKm+65Od1N5sEi4iPnGNkcgSVNi7 IdvfKi59+BV6x6sdf2k1tKiRJW0m8Ze3rECK+u1n/NrPGqfc2YrVntH1+8zhY16fqHRURaZ/CuiqTT t/B4m5POJuVATR9I3vyq1qxCIR1kiA X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Stat-Signature: mq179ojpuuwq65mhu74iq1nymm31qh96 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ZzPI8nUD; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Z56jISVI; dmarc=none; spf=pass (imf24.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 36052B0000A1 X-HE-Tag: 1638382518-412329 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Matthew Wilcox (Oracle)" Convert kfree(), kmem_cache_free() and ___cache_free() to resolve object addresses to struct slab, using folio as intermediate step where needed. Keep passing the result as struct page for now in preparation for mass conversion of internal functions. [ vbabka@suse.cz: Use folio as intermediate step when checking for large kmalloc pages ] Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Vlastimil Babka --- mm/slub.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 9bdb0a5d6ab2..2d9c1b3c9f37 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3517,7 +3517,7 @@ static __always_inline void slab_free(struct kmem_cache *s, struct page *page, #ifdef CONFIG_KASAN_GENERIC void ___cache_free(struct kmem_cache *cache, void *x, unsigned long addr) { - do_slab_free(cache, virt_to_head_page(x), x, NULL, 1, addr); + do_slab_free(cache, slab_page(virt_to_slab(x)), x, NULL, 1, addr); } #endif @@ -3527,7 +3527,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x) if (!s) return; trace_kmem_cache_free(_RET_IP_, x, s->name); - slab_free(s, virt_to_head_page(x), x, NULL, 1, _RET_IP_); + slab_free(s, slab_page(virt_to_slab(x)), x, NULL, 1, _RET_IP_); } EXPORT_SYMBOL(kmem_cache_free); @@ -4546,7 +4546,8 @@ EXPORT_SYMBOL(__ksize); void kfree(const void *x) { - struct page *page; + struct folio *folio; + struct slab *slab; void *object = (void *)x; trace_kfree(_RET_IP_, x); @@ -4554,12 +4555,13 @@ void kfree(const void *x) if (unlikely(ZERO_OR_NULL_PTR(x))) return; - page = virt_to_head_page(x); - if (unlikely(!PageSlab(page))) { - free_nonslab_page(page, object); + folio = virt_to_folio(x); + if (unlikely(!folio_test_slab(folio))) { + free_nonslab_page(folio_page(folio, 0), object); return; } - slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); + slab = folio_slab(folio); + slab_free(slab->slab_cache, slab_page(slab), object, NULL, 1, _RET_IP_); } EXPORT_SYMBOL(kfree);