From nobody Fri Dec 19 20:16:44 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F987224FA; Fri, 22 Mar 2024 09:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711100186; cv=none; b=Zn1wrNqbPB/UYYREAQFvHrqMXv5slP6jIaBun+yvG/tkbXJWaSmRU9qWxSmzgkHr4SeTi3Ba4hXg7Eshafsl5FRPqrYy7FC7eCEAkVkErJZHOPQXq97Ksiws4mF4ybV1WjxcU9vx1KwUd9STgqdGkAeJ7bOrDNbU08MYfZttmyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711100186; c=relaxed/simple; bh=Un5FAxnjdEo99yKEgJewvVt9ACNBktRqYLuELAqgtSM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MDQL5J8qtin6fQzThqm2RrJiE6OOKdcNI237C/bIIM2HQP4aXpj9j4JUGx4/2kl+ykZUjhwqnt4XRDNgE65/HLf4/06t8B5gVDBzQ8iGXPEvtMeV6a/cePuk1i3XkFA8WcOqqdkG2ip9Vg2Od3L2zQPWLOl8FZR24C7GMQCyR5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemd200004.china.huawei.com (7.185.36.141) Content-Type: text/plain; charset="utf-8" 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 =3D 0; i < nr_to_read; i++) { struct folio *folio =3D xa_load(&mapping->i_pages, index + i); + int ret; =20 if (folio && !xa_is_value(folio)) { /* @@ -247,9 +248,12 @@ void page_cache_ra_unbounded(struct readahead_control = *ractl, folio =3D filemap_alloc_folio(gfp_mask, 0); if (!folio) break; - if (filemap_add_folio(mapping, folio, index + i, - gfp_mask) < 0) { + + ret =3D filemap_add_folio(mapping, folio, index + i, gfp_mask); + if (ret < 0) { folio_put(folio); + if (ret =3D=3D -ENOMEM) + break; read_pages(ractl); ractl->_index++; i =3D ractl->_index + ractl->_nr_pages - index - 1; --=20 2.25.1 From nobody Fri Dec 19 20:16:44 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C80D224ED; Fri, 22 Mar 2024 09:36:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711100186; cv=none; b=ofw93lK2Xy6pxhMgYXr0H3n2S0t7UwD9NZy7mJ5C1kI5xUYNYdDNbT/oAvGbNZuHUnelQg410wYXwlhx40iSSayiV2JxT8TUbzVRDpJMNRSw+rDUf6nE+LWKWPLi7Doq+6mlzuJd6UIrF/yUfMgMKb5vq6yzPfBiXWzX7PATJTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711100186; c=relaxed/simple; bh=ecB2yv4xVDWojcVvrnD4p1dguHQ3ccRU+epK/KdXcN4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QvQKfprkEzV4VwRqIIZw6y8F549E/rLNTSzigFuyYl8YEa1I9qrUkzHoYcGRvMaJVcN2ru84HKZ0wsQGEKqgCpTFGInv0qpPXv7RORBxiEjGBXNozCn1ggGDJrqW3pJgxBN7dkXdAUvOysIbRKvhl2j/DMApmfO+JYAo2UdgNx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemd200004.china.huawei.com (7.185.36.141) Content-Type: text/plain; charset="utf-8" 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_f= ault *vmf, if (PageHWPoison(page + count)) goto skip; =20 - (*mmap_miss)++; + if (!folio_test_workingset(folio)) + (*mmap_miss)++; =20 /* * 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; =20 - (*mmap_miss)++; + if (!folio_test_workingset(folio)) + (*mmap_miss)++; =20 /* * NOTE: If there're PTE markers, we'll leave them to be --=20 2.25.1