From mboxrd@z Thu Jan 1 00:00:00 1970 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 73F84C4332F for ; Sun, 27 Nov 2022 23:01:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B578F6B0072; Sun, 27 Nov 2022 18:01:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE06D6B0073; Sun, 27 Nov 2022 18:01:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95BC96B0074; Sun, 27 Nov 2022 18:01:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 83DA96B0072 for ; Sun, 27 Nov 2022 18:01:42 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 03F5F1A0BA1 for ; Sun, 27 Nov 2022 23:01:41 +0000 (UTC) X-FDA: 80180746044.04.32C6BFB Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf04.hostedemail.com (Postfix) with ESMTP id 601E140012 for ; Sun, 27 Nov 2022 23:01:41 +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-out2.suse.de (Postfix) with ESMTPS id C670A1F8C2; Sun, 27 Nov 2022 23:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1669590099; h=from:from:reply-to: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=a29l7jcLu+VPTYRVin0cjX4H/D4GVLR0xYwLr3AIEfQ=; b=y1sZ+ZHybILLz2FC6B/JLdp86WU/cq/2L96+ln8bLhI9cchuLRXheXYwQcltG3iBENpJUB sv7VKXPx8pcqa8BpWPkrTzO4Vmha0aJjTs/5IITezQnEmAdd20wIiZ5gkKPVJrZi+ksFoK okZ6NW3SIY6c056Dchsg3b6obd2Shp4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1669590099; h=from:from:reply-to: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=a29l7jcLu+VPTYRVin0cjX4H/D4GVLR0xYwLr3AIEfQ=; b=z19YFeJ9xDX80bbJb30hCWwCplNFsc5s08/6baxW9I8xprSzp2/5e33ZseL4QZE9k05njq 3DTH2N7nlmHRuaAw== 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 90D4B134CE; Sun, 27 Nov 2022 23:01:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rxGZIlPsg2NBfwAAMHmgww (envelope-from ); Sun, 27 Nov 2022 23:01:39 +0000 Message-ID: <863dfdbb-2efc-a1d4-3cb1-3edaa67f67bd@suse.cz> Date: Mon, 28 Nov 2022 00:01:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH 09/12] mm, slub: split out allocations from pre/post hooks Content-Language: en-US To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Christoph Lameter , David Rientjes , Joonsoo Kim , Pekka Enberg , Roman Gushchin , Andrew Morton , Linus Torvalds , Matthew Wilcox , patches@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20221121171202.22080-1-vbabka@suse.cz> <20221121171202.22080-10-vbabka@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669590101; h=from:from:sender: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:dkim-signature; bh=a29l7jcLu+VPTYRVin0cjX4H/D4GVLR0xYwLr3AIEfQ=; b=fiuUX0pFYW57KLF2aCmnsNFxRTwWubTatosOynUZzXUP+pWlRH5qnbvdFBzf46qIyN6UTB XZcm/0mb56q4abpf247Ax7O/LXRuIXu/X0y4vxZ28QO3uYkNuwoziQicMDC/5DNQz8YLzP 9Pht86yhPcTNvhAfT5ndilvMBvKONSU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=y1sZ+ZHy; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=z19YFeJ9; spf=pass (imf04.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669590101; a=rsa-sha256; cv=none; b=5mazsGvDspnhMNVaiFvJtWeN4hQbP64TOZV8vAHIfBBWhmjYKDzdinBtBZKXyP7SDBpEbW baSkJNNL/vAOzq3nyczrNE/LcX44Q3pWR21ZgznLaVZkDsBHfzsv+W1U+iml89Zt5USCOg yj25pwfvun47miqMKrVMMVtsu87unrU= X-Rspamd-Queue-Id: 601E140012 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=y1sZ+ZHy; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=z19YFeJ9; spf=pass (imf04.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 9px9t9c76jdwobsf7nw33t95y388n71a X-HE-Tag: 1669590101-893135 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: On 11/27/22 11:54, Hyeonggon Yoo wrote: > On Mon, Nov 21, 2022 at 06:11:59PM +0100, Vlastimil Babka wrote: >> In the following patch we want to introduce CONFIG_SLUB_TINY allocation >> paths that don't use the percpu slab. To prepare, refactor the >> allocation functions: >> >> Split out __slab_alloc_node() from slab_alloc_node() where the former >> does the actual allocation and the latter calls the pre/post hooks. >> >> Analogically, split out __kmem_cache_alloc_bulk() from >> kmem_cache_alloc_bulk(). >> >> Signed-off-by: Vlastimil Babka >> --- >> mm/slub.c | 127 +++++++++++++++++++++++++++++++++--------------------- >> 1 file changed, 77 insertions(+), 50 deletions(-) > > [...] > >> + >> +/* Note that interrupts must be enabled when calling this function. */ >> +int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, >> + void **p) >> +{ >> + int i; >> + struct obj_cgroup *objcg = NULL; >> + >> + /* memcg and kmem_cache debug support */ >> + s = slab_pre_alloc_hook(s, NULL, &objcg, size, flags); >> + if (unlikely(!s)) >> + return false; >> + >> + i = __kmem_cache_alloc_bulk(s, flags, size, p, objcg); >> + >> + /* >> + * memcg and kmem_cache debug support and memory initialization. >> + * Done outside of the IRQ disabled fastpath loop. >> + */ >> + if (i != 0) >> + slab_post_alloc_hook(s, objcg, flags, size, p, >> + slab_want_init_on_alloc(flags, s)); > > This patch looks mostly good but wondering what happens if someone calls it with size == 0 > so it does not call slab_post_alloc_hook()? Hmm looks like in that case we miss doing obj_cgroup_put(objcg) in memcg_slab_post_alloc_hook(). Good catch, thanks! Fixing up, also a "return false" from int function (existed also before this patch). ----8<---- diff --git a/mm/slub.c b/mm/slub.c index b74c4664160e..88f0ce49caab 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3888,10 +3888,13 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, int i; struct obj_cgroup *objcg = NULL; + if (!size) + return 0; + /* memcg and kmem_cache debug support */ s = slab_pre_alloc_hook(s, NULL, &objcg, size, flags); if (unlikely(!s)) - return false; + return 0; i = __kmem_cache_alloc_bulk(s, flags, size, p, objcg);