From patchwork Tue Nov 16 00:16:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12620691 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F28EC433EF for ; Tue, 16 Nov 2021 00:16:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFD9663252 for ; Tue, 16 Nov 2021 00:16:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DFD9663252 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1440D6B0088; Mon, 15 Nov 2021 19:16:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC26A6B0092; Mon, 15 Nov 2021 19:16:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4A956B008A; Mon, 15 Nov 2021 19:16:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id B3E5D6B0088 for ; Mon, 15 Nov 2021 19:16:41 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 785141815BBE5 for ; Tue, 16 Nov 2021 00:16:41 +0000 (UTC) X-FDA: 78812877402.24.E91EADA Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf30.hostedemail.com (Postfix) with ESMTP id B3D62E001981 for ; Tue, 16 Nov 2021 00:16:15 +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 9E0D02195D; Tue, 16 Nov 2021 00:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1637021798; 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=901G9lHh8QoBsmlgOaXUWAFbaL5G5UrBB/PVC093ZJg=; b=N3rxVDFlSsLu43uVRDSWW3w+MMGMV5h2qJKo1WLZBog0o/EJx4vqwyGJzzsd64ydzetX+Y hMAMDlWdssJoHWc1wOBLBDuQqPWMKqdu+aClDLijMjou0vCYKVfc5uJ8hOAU6AaoTvJ8AX a29cfyZAFTqf6ZGSoiTbKBvYYZPF7RI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1637021798; 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=901G9lHh8QoBsmlgOaXUWAFbaL5G5UrBB/PVC093ZJg=; b=LfoqBiMS+mDNLccXiwUYmKIS2rz9aGpTodkzTEW9R/J5tbu/NIsQmWRSYXg5IYqf28vVsv Oi0LD2s1zJtfMeCA== 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 7290E139DB; Tue, 16 Nov 2021 00:16:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GBcVG2b4kmFjXAAAMHmgww (envelope-from ); Tue, 16 Nov 2021 00:16:38 +0000 From: Vlastimil Babka To: Matthew Wilcox , linux-mm@kvack.org, Christoph Lameter , David Rientjes , Joonsoo Kim , Pekka Enberg Cc: Vlastimil Babka Subject: [RFC PATCH 10/32] mm/slub: Convert kfree() to use a struct slab Date: Tue, 16 Nov 2021 01:16:06 +0100 Message-Id: <20211116001628.24216-11-vbabka@suse.cz> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211116001628.24216-1-vbabka@suse.cz> References: <20211116001628.24216-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2156; i=vbabka@suse.cz; h=from:subject; bh=DS22wbajAYxABI8wHw0tZPT37MJjfkoDrsE06HCWkfI=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhkvgyuOIlGd7hqKWZSl6aFlKFz4hkCsOpx3+wCi4I 67zZQDSJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYZL4MgAKCRDgIcpz8YmpEJ7rB/ 9Rz0PzftSOgh348aliRBVQiN2Htl0XN4xaPV0O/YGjzGYdXQJoNySwQE+6/3+pCO6GlN5IY3XhbUbi 3BPMWeQczCAmjoL/LUAvlcs+3ZsKq6xCOWSCUA6QGwxZFfbNR+x4c/MH0m/2KEA4Y7XDXLb1FOWtGQ i2mxZah94ODA+G1PMuvVsprXhNXGp9Me8i906yroPZUzhgLRO/v+mFiqD174D3NPcs8pfbMv7dtz9t k8LsoArSCo252wDR4tHqC3c0VTs/6d9eFlITlJ8+wKy2PN7iSAkNYn00nc2MnAkiOlaeNG0uFAadNA //N66pdsTWFxwQnjzjd5uFibwomWxq X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Stat-Signature: cszhzu6p1ip6gr8uaoe8t3tg7y9wzgaa Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=N3rxVDFl; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=LfoqBiMS; spf=pass (imf30.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B3D62E001981 X-HE-Tag: 1637021775-845629 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 d3e7c776227f..641e6fe2dbc0 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 @@ -3526,7 +3526,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x) s = cache_from_obj(s, x); if (!s) return; - 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_); trace_kmem_cache_free(_RET_IP_, x, s->name); } 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 = page_folio(virt_to_page(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);