From patchwork Fri Mar 22 09:35:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13599847 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 1726AC54E71 for ; Fri, 22 Mar 2024 09:36:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B2356B0092; Fri, 22 Mar 2024 05:36:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 756966B008C; Fri, 22 Mar 2024 05:36:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61D2A6B0092; Fri, 22 Mar 2024 05:36:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 54AD76B008A for ; Fri, 22 Mar 2024 05:36:26 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 299121A0D4C for ; Fri, 22 Mar 2024 09:36:26 +0000 (UTC) X-FDA: 81924169572.05.91617B7 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf15.hostedemail.com (Postfix) with ESMTP id CB774A000A for ; Fri, 22 Mar 2024 09:36:23 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711100184; 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=hOgjlK55Rk2PYJt5Fh+4dQXPv5aYLN4GHj/g4tJVCB0=; b=H6aeMCmNl2vc/DChZVjn+RaWe2rgEkA21HApWtcINN/BMTnh4HglKuet/bqPhSFtZ0NwmH ryVszXXoNq9T2hG37gRowtGm8AA0UTNYOlv6VdCEf87k2O8uzPSyZf3vJTi3U01o364u07 LwpugjnTVQK4ZJuMjHWB/MEyxoBAflY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711100184; a=rsa-sha256; cv=none; b=LWioByxiyJ/GjJeu8ERHksoiRYw4p/Vz/RDpSOIv7wjGmeYczzt5jisUkzI9KaobgsX1xl kcKcvd4RQo55TEGJS2SZmiAYg3P7utDDrjBiKylR1UbB1zdkXCr3nXdeGT2EnZ5+et/sQv RSdYnD45JQG+zvNTjbvSyPjMswQC8ws= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4V1HGS0pCyzNm8T; Fri, 22 Mar 2024 17:34:24 +0800 (CST) Received: from dggpemd200004.china.huawei.com (unknown [7.185.36.141]) by mail.maildlp.com (Postfix) with ESMTPS id 8079A18007D; Fri, 22 Mar 2024 17:36:19 +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; Fri, 22 Mar 2024 17:36:18 +0800 From: Liu Shixin To: Jan Kara , Matthew Wilcox , Andrew Morton , Alexander Viro , Christian Brauner CC: , , , Liu Shixin Subject: [PATCH v2 1/2] mm/readahead: break read-ahead loop if filemap_add_folio return -ENOMEM Date: Fri, 22 Mar 2024 17:35:54 +0800 Message-ID: <20240322093555.226789-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240322093555.226789-1-liushixin2@huawei.com> References: <20240322093555.226789-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemd200004.china.huawei.com (7.185.36.141) X-Rspamd-Queue-Id: CB774A000A X-Rspam-User: X-Stat-Signature: fjukxjgpodmw9a36iwjwmxj6rjjbpshs X-Rspamd-Server: rspam03 X-HE-Tag: 1711100183-711047 X-HE-Meta: U2FsdGVkX1/qpdnP45rpvlHp+NLNpPUhu3hcYGBsZTUhgBbsLDsGPDlFriAds3PrBxvdXoYKyM2ahSNDhT6RXIbzwPwuzMZepgGjvNq8gz7e5Jau/l+FcEnUSYntvM8Pb2GxWmL75s0WIQGFNwcR6NJupMVyftFbOtoSC9UWmYmR7RdYNLquFgbhki1AEc2QFIZEmj//v6QJXS9iYX9eFsnMw9mfIsY2QWTyT9bH8PMOIzIWw6ZbJSwuDUv4M8TjYTpcpMocOztKxJ5MLPabl5M5crd5WfYvQY5QotNu+fvsTXDVRNaJCkcR1Z0bz6gwSurw0vrvrWbbO28ncpvfP7+Pus62ZX4PK5VtLRZrGs0mWWufd7rTeCUzT83mQkUweJt/KXE6oa0+vEAeOWeJ0GSh4ZzrKqi138n9HHeukgi+cZTY8jT3Im4joV/k2Z6VIBxwQ0A2rv5cPhJxfaKoCsOi2f7aJdHIsaidifIQp98JyAFi4XH9CRcxfMNNwxAjeHd9fPJS+qRACxE8aBg0HQtWW6wHKIbU+KkGeiLF7gIAtHPwLf5G1rHQPSAOFY2BQtg1o0n7czVcx1ALGgke7E2RqDysEjG42uljR068lKpmxvQ98pFgJPMXu1ToY3NVMAhGbd92fgrObSiU5ih8arDPhY1g9T3hmAVXf3NE6otAJpkUoPsNn5LXhb0GzmXJyCn13hKRe1PEpKqAl0BSsoFFhNs8r/NpIIVBgMpfVQ05zIs7ZtbVoCXm0YyF8ADgKwHb5IzTJ9PkP+Jap2Ox9f5K96B2iqAelDM1mmNdakphMcXzAdgHeDO7nIyo4Bm6+LqUM2Rpc7SLqlp98G0G33SO9jm6Zs8klpWKwXSHszLcyrTLVzk86m456c2QlZe0FLr+xFXLKI3l7nrVK3KNqPugqLq50yvJq8uM1AOQQkK7SU3bjX2KKKyp1kz8JMhE+wICQ4n0UaJ5NuzjQQg F0XJoONR 7sgYhf+YJEm9d3M5G6iEhS1F5RRsW8dVjK4iOjvYDoxrdWsGwBpCW86ixmKZiS6eerSKIZlsVJBmM5l/+8qDWF5Rm7ko9Kkh4K4HTHEneSs0lUsFL3Mm+cji23ATbFSxF3ohrSUGTSfs0VHxkgpOv0Gaq4it3wbjT60iys9a+w7VNqCQNZiVZH+xFU6AnI97JEG3Z 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: When filemap_add_folio() return -ENOMEM, break read-ahead loop like what filemap_alloc_folio() does. Signed-off-by: Liu Shixin Signed-off-by: Jinjiang Tu Reviewed-by: Jan Kara --- mm/readahead.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 2648ec4f0494..a8513ffbb17f 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -228,6 +228,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, */ for (i = 0; i < nr_to_read; i++) { struct folio *folio = xa_load(&mapping->i_pages, index + i); + int ret; if (folio && !xa_is_value(folio)) { /* @@ -247,9 +248,12 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, folio = filemap_alloc_folio(gfp_mask, 0); if (!folio) break; - if (filemap_add_folio(mapping, folio, index + i, - gfp_mask) < 0) { + + ret = filemap_add_folio(mapping, folio, index + i, gfp_mask); + if (ret < 0) { folio_put(folio); + if (ret == -ENOMEM) + break; read_pages(ractl); ractl->_index++; i = ractl->_index + ractl->_nr_pages - index - 1; From patchwork Fri Mar 22 09:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13599848 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 DCEBCC47DD9 for ; Fri, 22 Mar 2024 09:36:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 697136B008A; Fri, 22 Mar 2024 05:36:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 644AF6B008C; Fri, 22 Mar 2024 05:36:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50CED6B0093; Fri, 22 Mar 2024 05:36: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 42CD06B008A for ; Fri, 22 Mar 2024 05:36:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B8F8A161514 for ; Fri, 22 Mar 2024 09:36:27 +0000 (UTC) X-FDA: 81924169614.24.28B9171 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf30.hostedemail.com (Postfix) with ESMTP id 555B680014 for ; Fri, 22 Mar 2024 09:36:24 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711100185; a=rsa-sha256; cv=none; b=W1yKi4T3aM2u2cTbbrH4NZKs6MlTyqGu6VQbBTFW9nBDjN3ECrOGAy3UY40m7SaugkpPlU f0yrs0mma3eSBgQKLXcjxM3nhPWfS7z4nAg9TRk6aaXC9tEh3jLAjbxqeFTTFFe7DekXP1 kSvzzGYFeJ9+v36T0tGIa8VMaRCgFXQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711100185; 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=6fo+DJ/eKF+RnrUfgp9/auEJ+mhPlykcMF8nrNgnGNg=; b=iK8gOVKng9okt2fRiYcFcoxY+wZNySUOF0Rsnzw3jlSALGF4CRbvn5DPI+ZaiYFW8KO33E M4tIOqfiucBNXmg/+7gmZp6mxnrZ3yAZ2RJj30gxW7WEQrj/N3BykVO9/xcXuQDB/+qdGh xi9xhBZTYYA19x2JiDL+uWk9zji+jcI= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V1HFk6jJXz1h3SL; Fri, 22 Mar 2024 17:33:46 +0800 (CST) Received: from dggpemd200004.china.huawei.com (unknown [7.185.36.141]) by mail.maildlp.com (Postfix) with ESMTPS id DAF6F140384; Fri, 22 Mar 2024 17:36:21 +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; Fri, 22 Mar 2024 17:36:21 +0800 From: Liu Shixin To: Jan Kara , Matthew Wilcox , Andrew Morton , Alexander Viro , Christian Brauner CC: , , , Liu Shixin Subject: [PATCH v2 2/2] mm/readahead: don't decrease mmap_miss when folio has workingset flags Date: Fri, 22 Mar 2024 17:35:55 +0800 Message-ID: <20240322093555.226789-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240322093555.226789-1-liushixin2@huawei.com> References: <20240322093555.226789-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemd200004.china.huawei.com (7.185.36.141) X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 555B680014 X-Stat-Signature: mt59j3e5cfr383us8ry8i851sggtqiad X-HE-Tag: 1711100184-811170 X-HE-Meta: U2FsdGVkX1/2fGmWqXcrCT1ZGkw9LM/Oy37YilnPTCr7DWxsvWJOJCtIO87yql7HXgmshho7PybOs9qQv5+o4Djgk7nnzLs2oOheGHeDrbVWe0YeiJnKv/mQoiP6iXOQg5piiRLj6Jwrik7aMVe1gSAwjSJfm6WEnYNAjn+LTKGAUeJ1N0vewHhbNXCEqaL1sCXz9yzlJBVgyc2ldX6L3wL1yRiEe181GjPLuYYIn0u/+0mjYDn0A36xNJAfcjCqx6bUtiuCvdZr1aS6uRwKjBZ2svg6i7WWyM9Tqtp3x/r4PVFXMaqj+Cp1SI2a/vguNzVNA5VgtKLtdhPZXWyJ0Ooo0x/prIflFMIu07bTEM6j04fCrKM40kf1BbnxEiCypRF2oVkqycR1JWPIT6PTCYL5NEnxmbj6IayzNMtj9BPywPV6P+dU8wG+vG5LkELMjxaCnB/b3+6yZUC1wgLmXBtDvGil3MfMiIsBedjPuNuiKMTTUgPec0oFj57TGBA5jDLj1vfd08oWxby7DtSYZSnhPwjIv438UnDBEKxUR7WLOjHTwZhnbEqovt2sdkfnFssz7xjaV0hb0v38TapuGnjRthRXHEXgcle6KtcQKKJsizWnDSCvKX3atmmrUVgM3m2ECoMgMO+9AzaaFMUzE92o/YwDJpBGGVxbVvgSiVrtBuYCBlX+BeD1qsoTNZC6Z1TEmrdjH7/iASAXkZzgzFtWmovE5izWV/0NujAFB5B658Z+l2xa+1Y/yMxOYwXfnZGREDevQkGVXUNZt9xECh4KcV9aA6WJnoTNXQ45dN6wIb3ezAz3TMrXSGziKWvRIWZWlQBrLlDhjO0iDae4rrLgZUCGMXGmrMbqFsVHhn5dg94/5l7d3cPiM+ezRfWlMc3USLoy7843d7gyDt2/BDGzUr5yYHM9aR/xM8YNo9oTNJsoj8fD5jHnECZqoKHw1Zshy8chscoCCfxf7zn vAVIu4kD IxfotHQbMP5hENVVKSO4a4IgACnrXWLev6/LvN/2JeV9HgEvfklZzMWFrf0RdggKY5XHMFG3b0hB61vQZsULfXahO9VQ3ntdC54HCwlXGOt0foITXQHRMkypbxmoSoj1DPIrBSQIfuE5ak3MWg8Blzo1QtTnChfpvLvbCq51OapZbA6bPCljLRz/sQ53VHj1c6xZI 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 flags. 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 --- mm/filemap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 8df4797c5287..753771310127 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3439,7 +3439,8 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, if (PageHWPoison(page + count)) goto skip; - (*mmap_miss)++; + if (!folio_test_workingset(folio)) + (*mmap_miss)++; /* * NOTE: If there're PTE markers, we'll leave them to be @@ -3488,7 +3489,8 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf, if (PageHWPoison(page)) return ret; - (*mmap_miss)++; + if (!folio_test_workingset(folio)) + (*mmap_miss)++; /* * NOTE: If there're PTE markers, we'll leave them to be