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 79995C43334 for ; Thu, 9 Jun 2022 03:04:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D34FA6B0073; Wed, 8 Jun 2022 23:04:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBE406B0074; Wed, 8 Jun 2022 23:04:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B37786B0075; Wed, 8 Jun 2022 23:04:08 -0400 (EDT) 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 9EE546B0073 for ; Wed, 8 Jun 2022 23:04:08 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 6DC63602FE for ; Thu, 9 Jun 2022 03:04:08 +0000 (UTC) X-FDA: 79557203376.14.9919BDF Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf24.hostedemail.com (Postfix) with ESMTP id EF3F018005F for ; Thu, 9 Jun 2022 03:04:06 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LJTRP3qGZzjXNL; Thu, 9 Jun 2022 11:02:41 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 9 Jun 2022 11:04:02 +0800 Subject: Re: [PATCH v2] mm/vmscan: don't try to reclaim freed folios To: Matthew Wilcox CC: , , References: <20220608141432.23258-1-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: Date: Thu, 9 Jun 2022 11:04:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654743848; 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; bh=1Tb6zM4zdR8yXRpo631RYcIv/ocg85HCwH8x1G95TmY=; b=ANqqYV81y+a8Wx8SRMvea2HqDpMqSNVR0RyniWpFBehtzoXkPPObe4U0qmA8EA0UnWb99L go06DUpjvCAHxAEfv7ODNiWTT6/0QjTit6ytXxIzbbgcc/NgbJKoltqHiRZ0aaXHfhh5Mc G3ARB+E9EzPUeUYBoQD9UzqfpN24GXI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654743848; a=rsa-sha256; cv=none; b=W5rBAQoanuSgnv4PM/bJxaEPtVB65TrgwtEttEvlJTsmq11qvGHUE+gQe8W6xIP8rvk1Nf CxnokHgwCeNoE1PPFCex6/QXuGLlqut7H63LvhzSUrlHmNfRKwzzWHWeJaDG83IXkGJFAo mCnzFDyMZKK5xXZE9yZSpmG3ylkt7qY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam08 X-Rspam-User: X-Stat-Signature: ayuwyp7jwqgk66jw1qsuqjoqh86z1gne X-Rspamd-Queue-Id: EF3F018005F X-HE-Tag: 1654743846-5382 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 2022/6/9 2:47, Matthew Wilcox wrote: > 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 This is just like the page_count == 1 case when doing page migration in unmap_and_move(). > 400 LOC already any longer. I'm fine to resend this patch until your work is done (It will be really grateful if I will be notified when that work is done). Thanks! > >> 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 >> > > . >