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 24887C43334 for ; Wed, 8 Jun 2022 18:47:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85A916B0071; Wed, 8 Jun 2022 14:47:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 809626B0072; Wed, 8 Jun 2022 14:47:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F7B16B0073; Wed, 8 Jun 2022 14:47:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5D17A6B0071 for ; Wed, 8 Jun 2022 14:47:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 280C912042E for ; Wed, 8 Jun 2022 18:47:28 +0000 (UTC) X-FDA: 79555951776.17.4672FC4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf11.hostedemail.com (Postfix) with ESMTP id C7B674005C for ; Wed, 8 Jun 2022 18:47:27 +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-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=9F7WTlgt6YBamSKHdVJHkNHJLYpsk/TcsWBV6+0KbOs=; b=qbW6RhB5j1D316MyVabU+CxWUB CEuaPvI2yXgLZLp3YxLiPbZFv9zrvSuS2ajTI31F26R25Kv/sGgOdGVxKB0eImPWPmVpCz+3N0Qjx 8TrJuMETdfvXCWPE2Tov/ZJkNalg7M1/uQs8rqZ4moR48zyevoE0j565MwLCXn297gZB1QpsetNED QIil6e64FOXMWt0cLxN4Inoo0wy1mf7TBtXr8S8JCcrGxir2Nt0XgRXCpFAIhxRadQIOD3diqgORy zVg6meYxvNZgvymQQwgDjYjWzUk7upvGjGjTpeaEmLtBxFlFA04iMoHpFUyhxfXWP+zGDvlbpAFYh q0guEHWg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nz0iB-00CsmT-Gd; Wed, 08 Jun 2022 18:47:23 +0000 Date: Wed, 8 Jun 2022 19:47:23 +0100 From: Matthew Wilcox To: Miaohe Lin Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/vmscan: don't try to reclaim freed folios Message-ID: References: <20220608141432.23258-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220608141432.23258-1-linmiaohe@huawei.com> Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qbW6RhB5; dmarc=none; spf=none (imf11.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C7B674005C X-Rspam-User: X-Stat-Signature: tsm7zu5wnd77skmepg1xk4tiz4inngrc X-HE-Tag: 1654714047-880551 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 Wed, Jun 08, 2022 at 10:14:32PM +0800, Miaohe Lin wrote: > If folios were freed from under us, there's no need to reclaim them. Skip > these folios to save lots of cpu cycles and avoid possible unnecessary > disk I/O. Yes, but I asked how often this happened, and you said you didn't know. Do you have any data? I'm reluctant to make a function which is over 400 LOC already any longer. > Signed-off-by: Miaohe Lin > --- > v2: > use folio_ref_freeze to guard against race with GUP (fast). Many thanks > Matthew for pointing this out. > --- > mm/vmscan.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 13d34d9593bb..547ae7ae6ab1 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -1610,13 +1610,19 @@ static unsigned int shrink_page_list(struct list_head *page_list, > folio = lru_to_folio(page_list); > list_del(&folio->lru); > > + nr_pages = folio_nr_pages(folio); > + > + if (folio_ref_count(folio) == 1 && > + folio_ref_freeze(folio, 1)) { > + /* folio was freed from under us. So we are done. */ > + goto free_it; > + } > + > if (!folio_trylock(folio)) > goto keep; > > VM_BUG_ON_FOLIO(folio_test_active(folio), folio); > > - nr_pages = folio_nr_pages(folio); > - > /* Account the number of base pages */ > sc->nr_scanned += nr_pages; > > -- > 2.23.0 >