From patchwork Wed Dec 1 18:14:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12650703 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 4F2E6C433F5 for ; Wed, 1 Dec 2021 18:21:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35E466B0088; Wed, 1 Dec 2021 13:15:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EAA826B0080; 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 9A2926B0089; Wed, 1 Dec 2021 13:15:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 487F06B0088 for ; Wed, 1 Dec 2021 13:15:29 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EF7B41811E9CF for ; Wed, 1 Dec 2021 18:15:18 +0000 (UTC) X-FDA: 78870027516.15.C455D7D Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf12.hostedemail.com (Postfix) with ESMTP id A9F5010000AE 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 E4D9C218A8; Wed, 1 Dec 2021 18:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1638382516; 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=58hfxBnYuwldOsS5RWPBlmkBh3kDaXQv2xFDmW4LndY=; b=n7Aolzg1ngl6J3WJTn7tfeV1zrjafRyiNC8W9St8QHyRGTPufwB5LNfzo9K8KianwcxUUN eCByQmVERil1dBcfH7FC8gq1dWQnLKMR19UkuSrYy8BRfW9QriLYN9bJJWbtaFSPjLBKE7 qCe2VD/8LIgh0tt1ZAn3NJQHs5b7DmI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1638382516; 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=58hfxBnYuwldOsS5RWPBlmkBh3kDaXQv2xFDmW4LndY=; b=SGYIASap+UQxfGOjK18SWyRWpMg/QwCkinBzlHx06/LVeGL/mhZs1oFr3uECgWdPo+Pxwg VEhvDhYLSj8qkfAg== 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 C142B13D9D; 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 6MWWLrS7p2HPSAAAMHmgww (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 10/33] mm/slub: Convert detached_freelist to use a struct slab Date: Wed, 1 Dec 2021 19:14:47 +0100 Message-Id: <20211201181510.18784-11-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=3747; i=vbabka@suse.cz; h=from:subject; bh=O8xdnfGnjh+DVAQGcXEOWgPRczsdJzoKygblRxlNB+s=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhp7tzg/mgthML8LjJOVCjvFddbzxDjhsfv+qvzBQR ydgUMweJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYae7cwAKCRDgIcpz8YmpEBBUB/ 9Oma5vnuxifv8h1Xevvyv2y3oePd5y8T7+aQNNLaJ2Fea1AtoHmTCmx3JcPpXlHVWjy5i2Jb7qnm3l y29ahDE+PR6/fK9Mq6hvTdECpuQQkogvXnjyzqokdX2EEMfSI+WMu4/5YotqqUhNGEfvPu48P6mrVP Xa/wWD3MwtG6cXDNQ7P09JeuBx5Tv8iOgdZVNfmoF82HYnLRx7G6IK5egOmkVT3ZHrYiQaw4H5sEd8 Vl7LMwyMsMAsaDHypRVTsCbKvSrVuIU2ecsWVnEODWFnTMnDIbqszzgpfx/z92I+VnIpewcgiJ4bbG 3FvjZqlSQhTLmpF8wgjyEIrBCN/s9B X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Stat-Signature: 4gwbg91e6fn3a38wdeu4bd8c6jp8nrhw X-Rspamd-Queue-Id: A9F5010000AE X-Rspamd-Server: rspam07 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=n7Aolzg1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=SGYIASap; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-HE-Tag: 1638382518-489097 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)" This gives us a little bit of extra typesafety as we know that nobody called virt_to_page() instead of virt_to_head_page(). [ vbabka@suse.cz: Use folio as intermediate step when filtering out large kmalloc pages ] Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Vlastimil Babka --- mm/slub.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 0d31274743d9..9bdb0a5d6ab2 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3532,7 +3532,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x) EXPORT_SYMBOL(kmem_cache_free); struct detached_freelist { - struct page *page; + struct slab *slab; void *tail; void *freelist; int cnt; @@ -3554,8 +3554,8 @@ static inline void free_nonslab_page(struct page *page, void *object) /* * This function progressively scans the array with free objects (with * a limited look ahead) and extract objects belonging to the same - * page. It builds a detached freelist directly within the given - * page/objects. This can happen without any need for + * slab. It builds a detached freelist directly within the given + * slab/objects. This can happen without any need for * synchronization, because the objects are owned by running process. * The freelist is build up as a single linked list in the objects. * The idea is, that this detached freelist can then be bulk @@ -3570,10 +3570,11 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, size_t first_skipped_index = 0; int lookahead = 3; void *object; - struct page *page; + struct folio *folio; + struct slab *slab; /* Always re-init detached_freelist */ - df->page = NULL; + df->slab = NULL; do { object = p[--size]; @@ -3583,17 +3584,19 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, if (!object) return 0; - page = virt_to_head_page(object); + folio = virt_to_folio(object); if (!s) { /* Handle kalloc'ed objects */ - if (unlikely(!PageSlab(page))) { - free_nonslab_page(page, object); + if (unlikely(!folio_test_slab(folio))) { + free_nonslab_page(folio_page(folio, 0), object); p[size] = NULL; /* mark object processed */ return size; } /* Derive kmem_cache from object */ - df->s = page->slab_cache; + slab = folio_slab(folio); + df->s = slab->slab_cache; } else { + slab = folio_slab(folio); df->s = cache_from_obj(s, object); /* Support for memcg */ } @@ -3605,7 +3608,7 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, } /* Start new detached freelist */ - df->page = page; + df->slab = slab; set_freepointer(df->s, object, NULL); df->tail = object; df->freelist = object; @@ -3617,8 +3620,8 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, if (!object) continue; /* Skip processed objects */ - /* df->page is always set at this point */ - if (df->page == virt_to_head_page(object)) { + /* df->slab is always set at this point */ + if (df->slab == virt_to_slab(object)) { /* Opportunity build freelist */ set_freepointer(df->s, object, df->freelist); df->freelist = object; @@ -3650,10 +3653,10 @@ void kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p) struct detached_freelist df; size = build_detached_freelist(s, size, p, &df); - if (!df.page) + if (!df.slab) continue; - slab_free(df.s, df.page, df.freelist, df.tail, df.cnt, _RET_IP_); + slab_free(df.s, slab_page(df.slab), df.freelist, df.tail, df.cnt, _RET_IP_); } while (likely(size)); } EXPORT_SYMBOL(kmem_cache_free_bulk);