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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4142FC433EF for ; Fri, 15 Oct 2021 12:37:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BFABF60F44 for ; Fri, 15 Oct 2021 12:37:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BFABF60F44 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2D167900002; Fri, 15 Oct 2021 08:37:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 281776B0089; Fri, 15 Oct 2021 08:37:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 147AB900002; Fri, 15 Oct 2021 08:37:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 04EBC6B0088 for ; Fri, 15 Oct 2021 08:37:23 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B2B048249980 for ; Fri, 15 Oct 2021 12:37:22 +0000 (UTC) X-FDA: 78698622324.11.3163F8C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 6600B50000A8 for ; Fri, 15 Oct 2021 12:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=bLMlIGZRWtJG5pdz8uzZaobV5511jJzZGIeS5RrEQlA=; b=dTvSQqRlNUuDdupsVJe/26lTrb sqieoyjQM+BFfZ2yQhFU/HiRNOpjWcaiFp4nb7+h/qFQ0Jun5nCI9Pcp1v78/KHTwt51ZAuMpNHsV R9LT5vv4gWpbM1KSLNtxXbOJsoM2XCi/1N/uQG2En82V8smzln0tV8pH4Fnlxl2c9WKumeDEqoYuY OCn92q7gM2EFnBSMZzGFFT3TiGPROBJS+9zTgVT9JO51NfQeG3DvrwhrFW2n3F8/Ia/YAdZhhWgfk qNrcwTOfu1PRElsZtS8Y6pzt5tE9y1efVwpHSiM661d+htuXZ+GsuMz7QwL5wUeiV3LCEQh+g/jsD MqXlJQWg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbMRJ-0090ze-0Z; Fri, 15 Oct 2021 12:36:11 +0000 Date: Fri, 15 Oct 2021 13:35:56 +0100 From: Matthew Wilcox To: Zqiang Cc: hch@infradead.org, akpm@linux-foundation.org, sunhao.th@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mikulas Patocka , Jens Axboe , Tejun Heo Subject: Re: [PATCH] mm: backing-dev: use kfree_rcu() instead of synchronize_rcu_expedited() Message-ID: References: <20211014082433.30733-1-qiang.zhang1211@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6600B50000A8 X-Stat-Signature: ner5y4grack5ywmrrug1ggbqpnjf4ci1 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dTvSQqRl; spf=none (imf04.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1634301441-156321 Content-Transfer-Encoding: quoted-printable 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 Fri, Oct 15, 2021 at 01:06:02PM +0800, Zqiang wrote: >=20 > On 2021/10/15 =E4=B8=8A=E5=8D=8810:57, Qiang Zhang wrote: > >=20 > >=20 > > Matthew Wilcox > > > =E4=BA=8E2021=E5=B9=B410=E6=9C=8814=E6=97=A5=E5=91=A8=E5=9B=9B =E4=B8= =8B=E5=8D=887:26=E5=86=99=E9=81=93=EF=BC=9A > >=20 > > On Thu, Oct 14, 2021 at 04:24:33PM +0800, Zqiang wrote: > > > The bdi_remove_from_list() is called in RCU softirq, however th= e > > > synchronize_rcu_expedited() will produce sleep action, use > > kfree_rcu() > > > instead of it. > > > > > > Reported-by: Hao Sun > > > > > Signed-off-by: Zqiang > > > > > --- > > >=C2=A0 include/linux/backing-dev-defs.h | 1 + > > >=C2=A0 mm/backing-dev.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0| 4 +--- > > >=C2=A0 2 files changed, 2 insertions(+), 3 deletions(-) > > > > > > diff --git a/include/linux/backing-dev-defs.h > > b/include/linux/backing-dev-defs.h > > > index 33207004cfde..35a093384518 100644 > > > --- a/include/linux/backing-dev-defs.h > > > +++ b/include/linux/backing-dev-defs.h > > > @@ -202,6 +202,7 @@ struct backing_dev_info { > > >=C2=A0 #ifdef CONFIG_DEBUG_FS > > >=C2=A0 =C2=A0 =C2=A0 =C2=A0struct dentry *debug_dir; > > >=C2=A0 #endif > > > +=C2=A0 =C2=A0 =C2=A0struct rcu_head rcu; > > >=C2=A0 }; > >=20 > > >Instead of growing struct backing_dev_info, it seems to me this > > rcu_head > > >could be placed in a union with rb_node, since it will have been > > removed > > >from the bdi_tree by this point and the tree is never walked und= er > > >RCU protection? > >=20 > >=20 > > Thanks for your advice, I find this bdi_tree=C2=A0is traversed under = the > > protection of a spin lock, not under the protection of RCU. > > I find this modification does not avoid the problem described in patc= h, > > the=C2=A0flush_delayed_work() may be called in=C2=A0release_bdi() > > The same will cause problems. > > may be=C2=A0 we can replace queue_rcu_work() of call_rcu(&inode->i_rc= u, > > i_callback) or do you have any better suggestions? What? All I was suggesting was: +++ b/include/linux/backing-dev-defs.h @@ -168,7 +168,10 @@ struct bdi_writeback { =20 struct backing_dev_info { u64 id; - struct rb_node rb_node; /* keyed by ->id */ + union { + struct rb_node rb_node; /* keyed by ->id */ + struct rcu_head rcu; + }; struct list_head bdi_list; unsigned long ra_pages; /* max readahead in PAGE_SIZE units */ unsigned long io_pages; /* max allowed IO size */ Christoph, independent of the inode lifetime problem, this actually seems like a good approach to take. I don't see why we should synchronize_rcu(= ) here? Adding Jens (original introducer of the synchronize_rcu()), Mikula= s (converted it to use _expedited) and Tejun (worked around a problem when using _expedited).