Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp132769rdb; Tue, 5 Dec 2023 00:19:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHD0wrC3Wo4kDZ8bPgvbfHFElSEEACQ5DKFTlQVZMinTmDTzXFjOudDBOGGOZitLsIOSnUz X-Received: by 2002:a05:6a20:104c:b0:18f:97c:5b8b with SMTP id gt12-20020a056a20104c00b0018f097c5b8bmr2011101pzc.89.1701764386695; Tue, 05 Dec 2023 00:19:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701764386; cv=none; d=google.com; s=arc-20160816; b=fM1g0shpGctbAb3YaYAGdbGvVCEcyJ4YjUZuonDG5gxilrD0xXhhJ7dbj6ern+4JA1 yTTnCgmdxEQkZWH1F9gqYuQ/TILJyIjIwJk+FfORXhNVwy7P3IKMTCJC+5mzXJ2Yr9vi 1G+U+BFNBRfzib/VW6esGInsuVZaHhAyPKbb+A41ICiv/kbpHISsTXwy7K5RRExTCPqO kQauGBiKyMtof8V6OGSAk83jCVj5SPoNasSgNGM/9b2SyUg2oIifiMAX5Zu886Kj+DnK 0TDoP9KrzOLGb76A1JTAOWPHMmxaTwBtgIKgDr80l2g+sOTp2GQgos/fwN8vsFL3WnG0 +7Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=1msEm8akAYRx9kjUOA91nsxPgIb6zvoJEQIqcVegQCI=; fh=zuD9N5pN5mzGyGYPnd9z08QWmYn9dfavasdtweZowiE=; b=0huALS07NffqGE26n3CK3FytgTFt6UusBHOziWDcrpzA3l8gG+aM8on6aCeNcTNl+h Y35FMUhl7qjwVQM4/p3HqblZNCqEE4JNsqJQGKEAozWNH9tJ5TDBKmzULVuujLaEcuQ5 2gbrG2tRo6kvDN54NGsqHvoFgrCpS6NGAjqjM1hsPUcArMtlBFK2PXdBx0LZ24dimXVN RBtikI8dBLBLhzTj0AW3DyVsc58lu4MTks8Qn0El9hWtRPDUaganhFFcVLSw/PH2VoaA pUREhCJUomnOhelYDczyJjlYDLMk1CydeKZ0uY59mPR1Yv2K4yHaLCcfqg6zL1OJaNEd CXmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=AtV3fzAe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id mh9-20020a17090b4ac900b00286bb6f1a91si2636204pjb.149.2023.12.05.00.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 00:19:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=AtV3fzAe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 130A38063D46; Tue, 5 Dec 2023 00:19:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231646AbjLEITa (ORCPT + 99 others); Tue, 5 Dec 2023 03:19:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjLEIT3 (ORCPT ); Tue, 5 Dec 2023 03:19:29 -0500 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [IPv6:2001:41d0:1004:224b::b4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CDB7BA for ; Tue, 5 Dec 2023 00:19:35 -0800 (PST) Message-ID: <30f88452-740b-441f-bb4f-a2d946e35cf5@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1701764373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1msEm8akAYRx9kjUOA91nsxPgIb6zvoJEQIqcVegQCI=; b=AtV3fzAeFmZ4JdXWxE03Prk3MZ1wZv43S0/xlV9BSbUTbS4gpzfPNZcJ8hnkvLbnvyQ/uu jdzhUwZUufJ0BcrKBBvLcMlMyveGsVUDjDk/FESYXgTpwridpsKWff7xPk+5s1zThdAMky 6MUHbCZDjgykCWbP9LXWTvdIX0CSgLM= Date: Tue, 5 Dec 2023 16:19:27 +0800 MIME-Version: 1.0 Subject: Re: [PATCH 2/4] mm/slub: introduce __kmem_cache_free_bulk() without free hooks Content-Language: en-US To: Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim Cc: Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Alexander Potapenko , Marco Elver , Dmitry Vyukov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com References: <20231204-slub-cleanup-hooks-v1-0-88b65f7cd9d5@suse.cz> <20231204-slub-cleanup-hooks-v1-2-88b65f7cd9d5@suse.cz> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20231204-slub-cleanup-hooks-v1-2-88b65f7cd9d5@suse.cz> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 05 Dec 2023 00:19:44 -0800 (PST) On 2023/12/5 03:34, Vlastimil Babka wrote: > Currently, when __kmem_cache_alloc_bulk() fails, it frees back the > objects that were allocated before the failure, using > kmem_cache_free_bulk(). Because kmem_cache_free_bulk() calls the free > hooks (KASAN etc.) and those expect objects that were processed by the > post alloc hooks, slab_post_alloc_hook() is called before > kmem_cache_free_bulk(). > > This is wasteful, although not a big concern in practice for the rare > error path. But in order to efficiently handle percpu array batch refill > and free in the near future, we will also need a variant of > kmem_cache_free_bulk() that avoids the free hooks. So introduce it now > and use it for the failure path. > > As a consequence, __kmem_cache_alloc_bulk() no longer needs the objcg > parameter, remove it. The objects may have been charged before, but it seems __kmem_cache_alloc_bulk() forget to uncharge them? I can't find "uncharge" in do_slab_free(), or maybe the bulk interface won't be used on chargeable slab? Thanks. > > Signed-off-by: Vlastimil Babka > --- > mm/slub.c | 33 ++++++++++++++++++++++++++------- > 1 file changed, 26 insertions(+), 7 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index d7b0ca6012e0..0742564c4538 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -4478,6 +4478,27 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, > return same; > } > > +/* > + * Internal bulk free of objects that were not initialised by the post alloc > + * hooks and thus should not be processed by the free hooks > + */ > +static void __kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p) > +{ > + if (!size) > + return; > + > + do { > + struct detached_freelist df; > + > + size = build_detached_freelist(s, size, p, &df); > + if (!df.slab) > + continue; > + > + do_slab_free(df.s, df.slab, df.freelist, df.tail, df.cnt, > + _RET_IP_); > + } while (likely(size)); > +} > + > /* Note that interrupts must be enabled when calling this function. */ > void kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p) > { > @@ -4499,7 +4520,7 @@ EXPORT_SYMBOL(kmem_cache_free_bulk); > > #ifndef CONFIG_SLUB_TINY > static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, > - size_t size, void **p, struct obj_cgroup *objcg) > + size_t size, void **p) > { > struct kmem_cache_cpu *c; > unsigned long irqflags; > @@ -4563,14 +4584,13 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, > > error: > slub_put_cpu_ptr(s->cpu_slab); > - slab_post_alloc_hook(s, objcg, flags, i, p, false, s->object_size); > - kmem_cache_free_bulk(s, i, p); > + __kmem_cache_free_bulk(s, i, p); > return 0; > > } > #else /* CONFIG_SLUB_TINY */ > static int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, > - size_t size, void **p, struct obj_cgroup *objcg) > + size_t size, void **p) > { > int i; > > @@ -4593,8 +4613,7 @@ static int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, > return i; > > error: > - slab_post_alloc_hook(s, objcg, flags, i, p, false, s->object_size); > - kmem_cache_free_bulk(s, i, p); > + __kmem_cache_free_bulk(s, i, p); > return 0; > } > #endif /* CONFIG_SLUB_TINY */ > @@ -4614,7 +4633,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, > if (unlikely(!s)) > return 0; > > - i = __kmem_cache_alloc_bulk(s, flags, size, p, objcg); > + i = __kmem_cache_alloc_bulk(s, flags, size, p); > > /* > * memcg and kmem_cache debug support and memory initialization. >