Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2492092pxb; Wed, 9 Feb 2022 21:31:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFYH8dcVYt46VtNTGgvmwMhCuk0FqVYj2kvoAY6kkI9nzpaUKmsaFjmFF4NyLcwWW7KTcR X-Received: by 2002:a17:90b:1e05:: with SMTP id pg5mr1064916pjb.86.1644471106623; Wed, 09 Feb 2022 21:31:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644471106; cv=none; d=google.com; s=arc-20160816; b=kJsCBMY3novixQyHqX+zVx0h5JpUnfis/Y0Y2+1IKFoVx8VBo7I5UQzg5nOOy0dPkL LJUbLTJyvoNHopB37zMcxifGDMVdt/IicKcMgVlLv7hd1VSxYALkrMyMr8ujtKuyHlX0 s8B3dwv0/sP/iXwmBRtYDLhSnGAn/vaIygwC60AVHBQKeBdysVFikTUIG4mecypPo+/H wneiPyFYwTyl234w3rJSxPgQ4YAGeScy4pZ84X9QSa9QKNkDAVXQ9TcNaycOcA9UhGWY NXXxKp9wit654qMfkWYajHmbhVrSFWTlPEjhb1AjMP3V8BBCWlG1vxjtrvZB0b6AbERo CeSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=6jDClNWnve2JUiIy6BSOsVh2Mqu8dbuEQOWMqtfHtP0=; b=C8HlqKZ8pPcMP32wwmMURf4926HIH6LRYyRIIoEdOv6vC+reqfNn4auRrpaGeS6xQf GPwH5KlFEjO+DpwRMNKQRDoX3H2rnfK2hC7e4VT1yLbdYpXWWn3+4AsEVI8g4zn9icAF 3UOO+YUOhY7qEe7odGCpLZpd3jGI1ezuI798Y81i7QO2kRTxqSetzkDM9ZkNJ0yvs5lL 1r98mc/e1xeee2S5hncFGnGCt9GZBxZgCg8fYA4Z7yo08TJaCi55LFj/23W91v+4lWiO xhniF9qmqBOCZfrsXgzHM3jrmTQYwT7EksPc2lMT+GG4m67Edh55sYCkz3q4c4i+jNCk ASjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id az23si478574pjb.54.2022.02.09.21.31.31; Wed, 09 Feb 2022 21:31:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231645AbiBJFIF (ORCPT + 99 others); Thu, 10 Feb 2022 00:08:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbiBJFIA (ORCPT ); Thu, 10 Feb 2022 00:08:00 -0500 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5551628C; Wed, 9 Feb 2022 21:08:00 -0800 (PST) Received: from cwcc.thunk.org (pool-108-7-220-252.bstnma.fios.verizon.net [108.7.220.252]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 21A57X4O005422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Feb 2022 00:07:34 -0500 Received: by cwcc.thunk.org (Postfix, from userid 15806) id 96ED815C0040; Thu, 10 Feb 2022 00:07:33 -0500 (EST) Date: Thu, 10 Feb 2022 00:07:33 -0500 From: "Theodore Ts'o" To: "Paul E. McKenney" Cc: Jan Kara , Qian Cai , Jan Kara , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , linux-ext4@vger.kernel.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] jbd2: avoid __GFP_ZERO with SLAB_TYPESAFE_BY_RCU Message-ID: References: <20220209165742.5659-1-quic_qiancai@quicinc.com> <20220209181010.gfn66rvip56i54df@quack3.lan> <20220209201137.GY4285@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220209201137.GY4285@paulmck-ThinkPad-P17-Gen-1> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 09, 2022 at 12:11:37PM -0800, Paul E. McKenney wrote: > On Wed, Feb 09, 2022 at 07:10:10PM +0100, Jan Kara wrote: > > > > No, the performance impact of this would be just horrible. Can you > > ellaborate a bit why SLAB_TYPESAFE_BY_RCU + __GFP_ZERO is a problem and why > > synchronize_rcu() would be needed here before the memset() please? I mean > > how is zeroing here any different from the memory just being used? > > Suppose a reader picks up a pointer to a memory block, then that memory > is freed. No problem, given that this is a SLAB_TYPESAFE_BY_RCU slab, > so the memory won't be freed while the reader is accessing it. But while > the reader is in the process of validating the block, it is zeroed. > > How does the validation step handle this in all cases? > > If you have a way of handling this, I will of course drop the patch. > And learn something new, which is always a good thing. ;-) I must be missing something. The change is on the allocation path, and why would kmem_cache_[z]alloc() return a memory chunk which could still be in use by a reader? Shouldn't the allocator _not_ return a particular chunk until it is sure there aren't any readers left that would be discombobulated by that memory being used for some new use case? Otherwise we would have to add synchronize_rcu(); after every single kmem_cache allocation which might be using RCU, and that would be terrible, no? - Ted > > > --- > > > fs/jbd2/journal.c | 9 ++++++--- > > > 1 file changed, 6 insertions(+), 3 deletions(-) > > > > > > diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c > > > index c2cf74b01ddb..323112de5921 100644 > > > --- a/fs/jbd2/journal.c > > > +++ b/fs/jbd2/journal.c > > > @@ -2861,15 +2861,18 @@ static struct journal_head *journal_alloc_journal_head(void) > > > #ifdef CONFIG_JBD2_DEBUG > > > atomic_inc(&nr_journal_heads); > > > #endif > > > - ret = kmem_cache_zalloc(jbd2_journal_head_cache, GFP_NOFS); > > > + ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS); > > > if (!ret) { > > > jbd_debug(1, "out of memory for journal_head\n"); > > > pr_notice_ratelimited("ENOMEM in %s, retrying.\n", __func__); > > > - ret = kmem_cache_zalloc(jbd2_journal_head_cache, > > > + ret = kmem_cache_alloc(jbd2_journal_head_cache, > > > GFP_NOFS | __GFP_NOFAIL); > > > } > > > - if (ret) > > > + if (ret) { > > > + synchronize_rcu(); > > > + memset(ret, 0, sizeof(*ret)); > > > spin_lock_init(&ret->b_state_lock); > > > + } > > > return ret; > > > } > > > > > > -- > > > 2.30.2 > > > > > -- > > Jan Kara > > SUSE Labs, CR