From patchwork Tue Mar 26 06:50:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13603627 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 3768FC54E58 for ; Tue, 26 Mar 2024 06:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AED7E6B0098; Tue, 26 Mar 2024 02:51:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A75C46B009D; Tue, 26 Mar 2024 02:51:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 916B76B009E; Tue, 26 Mar 2024 02:51:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7B4CA6B0098 for ; Tue, 26 Mar 2024 02:51:02 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2A75C80713 for ; Tue, 26 Mar 2024 06:51:02 +0000 (UTC) X-FDA: 81938267964.12.B4E5B6D Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf28.hostedemail.com (Postfix) with ESMTP id 4243AC0007 for ; Tue, 26 Mar 2024 06:50:58 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711435860; 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=iv0y0t95EeiPm4zh0CGejymNkWw2yt3Ij9cbj653ANU=; b=O3F9bcOhsAUF/gBTHq+YniHmRGrd9c3gLaqiMuBhDcINGfmy0+1G4wgs6JQECIgk92EqA6 QpxqsVIlYlIAsPXOW2w1XvYurf5tT3USqZTbhbhUdtUZ1EugJ7t6uuV38Y2hdWBRDY2hmn uwTjNgs+BGFTCBq6ycNFnJUP7YPg1ZY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711435860; a=rsa-sha256; cv=none; b=exqfSDbYP8r6ui5+N+ckhzzpldcbPEdHKWgWEQFvpP5sOytSqSPiR5phJexluQIbNx9ejr gY2mjhv3rg0WlCoccABbcAmpH8m4sERLSIuakndt4EltR2PWY0t9smcdpkAWRNBJRMtFSx n9HM9HI3pzymedmuPI2vPEMjeyqQZ/c= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4V3gNp0L0KzXjlK; Tue, 26 Mar 2024 14:48:10 +0800 (CST) Received: from dggpemd200004.china.huawei.com (unknown [7.185.36.141]) by mail.maildlp.com (Postfix) with ESMTPS id 64C5A1400DD; Tue, 26 Mar 2024 14:50:55 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemd200004.china.huawei.com (7.185.36.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Tue, 26 Mar 2024 14:50:54 +0800 From: Liu Shixin To: Andrew Morton CC: Jan Kara , Matthew Wilcox , Alexander Viro , Christian Brauner , , , , Liu Shixin Subject: [PATCH v3] mm/filemap: don't decrease mmap_miss when folio has workingset flag Date: Tue, 26 Mar 2024 14:50:26 +0800 Message-ID: <20240326065026.1910584-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240322093555.226789-3-liushixin2@huawei.com> References: <20240322093555.226789-3-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemd200004.china.huawei.com (7.185.36.141) X-Rspamd-Queue-Id: 4243AC0007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: x3oaf85igpyufj49fs7ruzpqf4rm7e8q X-HE-Tag: 1711435858-523478 X-HE-Meta: U2FsdGVkX1/ntseFMRvREpyfTNxqLP4YedOrQY7q4AqQ+3ROS0Y/qobYtvfrx8JAHfiKHnf/S3x8YiQ7mvLc054D9khbJZCxJBcyafZDxkgp+iYIWN0fCbX92xdbuB6KlfdX9Tb+2/FSx2Lx2EjrMSwZj2dlPahxJTktJn+mTBosNGvtjg9M5I+poyiyKWZeqAJzq8F4x9bZv9G1+ZFO70KF75i/PT8jPy+vg0t23mKgpVgnu/cXJd3d7IBPjadcach229PcPopsVhmmSkPD5ecRzVlYEfZ4JJ4wkvzdOH4BZhncKJle7Th5+WgC1Hz3n1VTYPue+g6w25rWIZ77BfsQlNV6Lp0yKoGn9SEAE+uSfi3qBcUj3Gtb7IfqJYidhJoY1iwETbGAf7B+g+xhRyxjTsEhFRWKzICrDhXktK/Dz0TGs863lY3nCI6RPUt0yhZhhOUxKrSAZi5nN6iMMHnns+EBI6ADVN2/Hk0Gp7JLOMITCmqSFBJSKrtn4ri136dXOx+37uunALQrFxmxtbFeqwQ4GgD6ElwsTAQslAcu28PGgTVUXRi+B40vmKBEvjU9p7O0HwnDywXhSJJQthjTlVHtQFLM9dI3YsDysIyv/yjm5PwphvBgx6GrsfagRxcl1hBB95VTCtuzmelA3BSvEbsfqE3ew3ZuCOAEvcBpnMExRpyO2IoYxfcfh1bh1r6/U4Ms6OMTCeAqzQ5tGG1BhbFVou3ISnu3kmy4JnjgusTHIYiygrRpeZ0GDvT2TQfGxVbX59TlxAgsmMZ/9ALwfnyXpkFBnQvBx5865L0ONS8DaATZAgM+sgyueAUET1eu6BUqeHz0L2yTuubmrhUB6e4DRqUUU07gFdrw+r4nf5RCPb2XlrPMg8SUcGQbAnJTwZSJTumSTW2OfE9Rcl1odpVncQXGq/lusai1RhYXYD/5Cee1cne5ctQ+Rvv/5JBRKGjXKQbLXWiqMA4 YFMN9jGg 7/FX1jjz72JYu4bsAPptUI7WSfsthLJBW/Qm3kRRuUQehZ9YepHluawN9dRwp0+dhGcXwr77igYVVu06rHJZ3JcLWf8H2F1BQhvS7kSa7Zq8R7/ce3jNtSiyzIRijoqi19beVXTRnRlc3AA/45mx6lCxe/Lmb5R5X1wmdIUHbB7t5WrqK0aZ90gqQ6DtHQ3jpBSov 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: List-Subscribe: List-Unsubscribe: If there are too many folios that are recently evicted in a file, then they will probably continue to be evicted. In such situation, there is no positive effect to read-ahead this file since it is only a waste of IO. The mmap_miss is increased in do_sync_mmap_readahead() and decreased in both do_async_mmap_readahead() and filemap_map_pages(). In order to skip read-ahead in above scenario, the mmap_miss have to increased exceed MMAP_LOTSAMISS. This can be done by stop decreased mmap_miss when folio has workingset flag. The async path is not to care because in above scenario, it's hard to run into the async path. Signed-off-by: Liu Shixin Reviewed-by: Jan Kara --- v2->v3: Update the title and comment. And add reviewed-by from Jan. Andrew, please update patch[2] with this new patch, thanks. mm/filemap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 8df4797c5287..780aad026b26 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3439,7 +3439,15 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, if (PageHWPoison(page + count)) goto skip; - (*mmap_miss)++; + /* + * If there are too many folios that are recently evicted + * in a file, they will probably continue to be evicted. + * In such situation, read-ahead is only a waste of IO. + * Don't decrease mmap_miss in this scenario to make sure + * we can stop read-ahead. + */ + if (!folio_test_workingset(folio)) + (*mmap_miss)++; /* * NOTE: If there're PTE markers, we'll leave them to be @@ -3488,7 +3496,9 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf, if (PageHWPoison(page)) return ret; - (*mmap_miss)++; + /* See comment of filemap_map_folio_range() */ + if (!folio_test_workingset(folio)) + (*mmap_miss)++; /* * NOTE: If there're PTE markers, we'll leave them to be