Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp459950lqp; Mon, 10 Jun 2024 09:08:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXP58/xpniAkg3odKEMoNDIIfTGkErHKbhcR9IweDdYqUoOfCGQ9kXBexIwbwlEfR5/XYoP6mV1LM/pNBOPYSHfjyRNwUn94ghEusi3iw== X-Google-Smtp-Source: AGHT+IFMOi+4X48FSNAQkmBadQqdswvx3/mqvu18yFwR4gagw1TPBZL0sjnaAZrkMVNrfs+CpdJ4 X-Received: by 2002:a17:90a:7181:b0:2c2:f8f5:a057 with SMTP id 98e67ed59e1d1-2c2f8f5a19fmr3388233a91.33.1718035680757; Mon, 10 Jun 2024 09:08:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718035680; cv=pass; d=google.com; s=arc-20160816; b=iIMcuvp/3/GQhVz54ivYx2JvMPX/Kf992zvz1MANRaQz8BXv0UuTlHdX1OSqek9cMm mw84vJOmgxbS0DuAg2y2A4HyYNC6Qwm0r5uCxTpl+A+WQWxB9LiJDNfHUQkfXxpaEt55 gx3L4jtWh5n9vkpvXvEtzYNk37RiltX9KH/NU95+vaB5qq/+M+RfEViyqsz3b+5szdnG 27M2gIuuRwLGcDRNGlg9pgUQZpkO91hSntqOol+3i/BkJ1eynKot4ylbakYWUX84tGgF 2AUqJUcTMnBmcejE17WivssJkmcXuI4BQNic/VwQ2n6RgiUs/fd6Yn+cFcAPpXnPO2wD hULQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:content-transfer-encoding:content-id :content-language:accept-language:in-reply-to:message-id:date :thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-filter; bh=xsQRh9XT0ssETz1BZhE8jFAxkkrZ+caHg8QHRypEaZQ=; fh=0TespLm8LwwnBoB3YiF26LZ40WVDYei6KrY0dT7V8cw=; b=Z6MTr1Mqa6Bl3sVWIWH5tSinjCaJ4eUwirJJ21740NUsi7X4EUWBLdNB4RZqd2qLC0 bcBFbFlGnQfhmU75es9Z5OMMdjOk5y8RrnNvdiRVJZ5lN9/aIy1XJp1fWYb1aJ7Pfv11 oIhBozvKiwke2t2u6yilboLFo1o3+9Xt9dTQnxVkOIYSZPHTz5y8PRjFIhilEHeV17A9 1OGYBEd1tj/+qhl19HaAWKpM+qZXBwtBkN64FX8Dtvo6LAwAo1rJAWFfxNYSE3YsGjHM y1xGK6XZCdV4sM+OxHTz1f+rrUINr096DtWK8J+jmwGgMh6PfTjjDbtFUuxz4WRhw/yR ku3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=LeGw68Ls; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-208477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2eb2527cdsi3591382a91.36.2024.06.10.09.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 09:08:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=LeGw68Ls; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-208477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0A97CB288EB for ; Mon, 10 Jun 2024 15:27:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0356713D8A7; Mon, 10 Jun 2024 15:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="LeGw68Ls" Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (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 8FCBF150991 for ; Mon, 10 Jun 2024 15:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032994; cv=none; b=pegG0EYOEhoodBf5JnY7O4edgp1UVin/wJeOQ42BfLrF7fYh1f/zVQjMSxBrq6LJCSbdNwyWemKpOLFAG2e7cM9WEXWnUlYSyLIMccG+gNor4U0w2OFHgShjt3sfL1lfZQNBO0iBiPMlDM4zjU0Dx1LTlElMLAlbnk4jePkvh0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032994; c=relaxed/simple; bh=MeURfKp4npVnwlWE8hV6JLcA+wNUiMHoeT8QM74Um5E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=AJfVZKMeA4kWaXevLy9jUgUiPDbWHpm+VHpnz3nuXEh2+Qzyq02ZkJpPJBDuONOAai8b356ppsQv8kW8K1cex9S8s457dnBI1A65nxVOMrRd1a62xAwPrffMlC0jB0YdVbhqlC0tsvCytqgCDIU05snJyQKzXREtq7hMoWuf8Ec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=LeGw68Ls; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240610152309euoutp019da7397ffb5cc01b761d793ed8bf34e8~Xrea5BrQp1000410004euoutp01j for ; Mon, 10 Jun 2024 15:23:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240610152309euoutp019da7397ffb5cc01b761d793ed8bf34e8~Xrea5BrQp1000410004euoutp01j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1718032989; bh=xsQRh9XT0ssETz1BZhE8jFAxkkrZ+caHg8QHRypEaZQ=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=LeGw68Ls+3L0S5kx8X7KkJoqbMbJUquiIj57f47YwBnTfC+O2tX/YJg3EBm60a7pt srtcibqQJwjnijZjmx/rq5tGiVsXp1rfkEW1FUdixWVPOz06tBYt7B9w7kFrT5H5AK uLW6JRWg5nV9sQwfKGhP0/zUbLtI6zthpzAgUmgA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240610152308eucas1p254c0bd8c8ab1b3d99e3abce355e2a8c7~XreajaHdv0828808288eucas1p28; Mon, 10 Jun 2024 15:23:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id F7.09.09620.C5A17666; Mon, 10 Jun 2024 16:23:08 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240610152307eucas1p10417f113fcc5e1729bdf638f370d54e4~XreZhT2xA2197921979eucas1p1U; Mon, 10 Jun 2024 15:23:07 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240610152307eusmtrp135eb1e0ff64ac806e8eaf41de73053fe~XreZfPx8Q1787017870eusmtrp1G; Mon, 10 Jun 2024 15:23:07 +0000 (GMT) X-AuditID: cbfec7f5-d31ff70000002594-a2-66671a5caf40 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id A5.63.08810.B5A17666; Mon, 10 Jun 2024 16:23:07 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240610152307eusmtip1db04ad59f2b5fa6cf768636ea5fcf278~XreZN62xP0569405694eusmtip1j; Mon, 10 Jun 2024 15:23:07 +0000 (GMT) Received: from CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 10 Jun 2024 16:23:06 +0100 Received: from CAMSVWEXC01.scsc.local ([::1]) by CAMSVWEXC01.scsc.local ([fe80::7d73:5123:34e0:4f73%13]) with mapi id 15.00.1497.012; Mon, 10 Jun 2024 16:23:06 +0100 From: Daniel Gomez To: Baolin Wang CC: "akpm@linux-foundation.org" , "hughd@google.com" , "willy@infradead.org" , "david@redhat.com" , "wangkefeng.wang@huawei.com" , "chrisl@kernel.org" , "ying.huang@intel.com" , "21cnbao@gmail.com" <21cnbao@gmail.com>, "ryan.roberts@arm.com" , "shy828301@gmail.com" , "ziy@nvidia.com" , "ioworker0@gmail.com" , Pankaj Raghav , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 5/7] mm: add new 'orders' parameter for find_get_entries() and find_lock_entries() Thread-Topic: [PATCH 5/7] mm: add new 'orders' parameter for find_get_entries() and find_lock_entries() Thread-Index: AQHauAk68+kKkF9tKUiB4eqFXoRvB7HBE1kA Date: Mon, 10 Jun 2024 15:23:06 +0000 Message-ID: In-Reply-To: <5304c4c54868336985b396d2c46132c2e0cdf803.1717673614.git.baolin.wang@linux.alibaba.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted Content-Type: text/plain; charset="us-ascii" Content-ID: <9399C4818E7B364CA97436B94E4A03A5@scsc.local> Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJKsWRmVeSWpSXmKPExsWy7djP87oxUulpBqf+m1p8vitkMWf9GjaL /3uPMVo0PXjEZPF1/S9mi6ef+lgsFv02tri8aw6bxb01/1ktenZPZbRYcGIxo0Xj5/uMFr9/ ACVOzprMYjH76D12B36PNfPWMHrsnHWX3WPBplKPliNvWT02r9DyWLznJZPHplWdbB6bPk1i 9zgx4zeLx86Hlh69ze/YPN7vu8rm8XmTXABvFJdNSmpOZllqkb5dAlfG9ZbbLAW/PCu6Lt5l aWA8adXFyMkhIWAise7UF8YuRi4OIYEVjBJvrl5jgXC+MEocaJ/ADuF8ZpTYefIL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Yi4qTgQADOPzoBMEAAA= X-CMS-MailID: 20240610152307eucas1p10417f113fcc5e1729bdf638f370d54e4 X-Msg-Generator: CA X-RootMTR: 20240610152307eucas1p10417f113fcc5e1729bdf638f370d54e4 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240610152307eucas1p10417f113fcc5e1729bdf638f370d54e4 References: <5304c4c54868336985b396d2c46132c2e0cdf803.1717673614.git.baolin.wang@linux.alibaba.com> Hi Baolin, On Thu, Jun 06, 2024 at 07:58:55PM +0800, Baolin Wang wrote: > In the following patches, shmem will support the swap out of large folios= , > which means the shmem mappings may contain large order swap entries, so a= n > 'orders' array is added for find_get_entries() and find_lock_entries() to > obtain the order size of shmem swap entries, which will help in the relea= se > of shmem large folio swap entries. >=20 > Signed-off-by: Baolin Wang > --- > mm/filemap.c | 27 +++++++++++++++++++++++++-- > mm/internal.h | 4 ++-- > mm/shmem.c | 17 +++++++++-------- > mm/truncate.c | 8 ++++---- > 4 files changed, 40 insertions(+), 16 deletions(-) >=20 > diff --git a/mm/filemap.c b/mm/filemap.c > index 37061aafd191..47fcd9ee6012 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2036,14 +2036,24 @@ static inline struct folio *find_get_entry(struct= xa_state *xas, pgoff_t max, > * Return: The number of entries which were found. > */ > unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, > - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices) > + pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices, > + int *orders) > { > XA_STATE(xas, &mapping->i_pages, *start); > struct folio *folio; > + int order; > =20 > rcu_read_lock(); > while ((folio =3D find_get_entry(&xas, end, XA_PRESENT)) !=3D NULL) { > indices[fbatch->nr] =3D xas.xa_index; > + if (orders) { > + if (!xa_is_value(folio)) > + order =3D folio_order(folio); > + else > + order =3D xa_get_order(xas.xa, xas.xa_index); > + > + orders[fbatch->nr] =3D order; > + } > if (!folio_batch_add(fbatch, folio)) > break; > } > @@ -2056,6 +2066,8 @@ unsigned find_get_entries(struct address_space *map= ping, pgoff_t *start, > folio =3D fbatch->folios[idx]; > if (!xa_is_value(folio)) > nr =3D folio_nr_pages(folio); > + else if (orders) > + nr =3D 1 << orders[idx]; > *start =3D indices[idx] + nr; > } > return folio_batch_count(fbatch); > @@ -2082,10 +2094,12 @@ unsigned find_get_entries(struct address_space *m= apping, pgoff_t *start, > * Return: The number of entries which were found. > */ > unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start= , > - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices) > + pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices, > + int *orders) > { > XA_STATE(xas, &mapping->i_pages, *start); > struct folio *folio; > + int order; > =20 > rcu_read_lock(); > while ((folio =3D find_get_entry(&xas, end, XA_PRESENT))) { > @@ -2099,9 +2113,16 @@ unsigned find_lock_entries(struct address_space *m= apping, pgoff_t *start, > if (folio->mapping !=3D mapping || > folio_test_writeback(folio)) > goto unlock; > + if (orders) > + order =3D folio_order(folio); > VM_BUG_ON_FOLIO(!folio_contains(folio, xas.xa_index), > folio); > + } else if (orders) { > + order =3D xa_get_order(xas.xa, xas.xa_index); > } > + > + if (orders) > + orders[fbatch->nr] =3D order; > indices[fbatch->nr] =3D xas.xa_index; > if (!folio_batch_add(fbatch, folio)) > break; > @@ -2120,6 +2141,8 @@ unsigned find_lock_entries(struct address_space *ma= pping, pgoff_t *start, > folio =3D fbatch->folios[idx]; > if (!xa_is_value(folio)) > nr =3D folio_nr_pages(folio); > + else if (orders) > + nr =3D 1 << orders[idx]; > *start =3D indices[idx] + nr; > } > return folio_batch_count(fbatch); > diff --git a/mm/internal.h b/mm/internal.h > index 3419c329b3bc..0b5adb6c33cc 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -339,9 +339,9 @@ static inline void force_page_cache_readahead(struct = address_space *mapping, > } > =20 > unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start= , > - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); > + pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices, int *orders= ); > unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, > - pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); > + pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices, int *orders= ); > void filemap_free_folio(struct address_space *mapping, struct folio *fol= io); > int truncate_inode_folio(struct address_space *mapping, struct folio *fo= lio); > bool truncate_inode_partial_folio(struct folio *folio, loff_t start, > diff --git a/mm/shmem.c b/mm/shmem.c > index 0ac71580decb..28ba603d87b8 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -840,14 +840,14 @@ static void shmem_delete_from_page_cache(struct fol= io *folio, void *radswap) > * Remove swap entry from page cache, free the swap and its page cache. > */ > static int shmem_free_swap(struct address_space *mapping, > - pgoff_t index, void *radswap) > + pgoff_t index, void *radswap, int order) > { > void *old; Matthew Wilcox suggested [1] returning the number of pages freed in shmem_f= ree_swap(). [1] https://lore.kernel.org/all/ZQRf2pGWurrE0uO+@casper.infradead.org/ Which I submitted here: https://lore.kernel.org/all/20231028211518.3424020-5-da.gomez@samsung.com/ Do you agree with the suggestion? If so, could we update my patch to use free_swap_and_cache_nr() or include that here? > =20 > old =3D xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0); > if (old !=3D radswap) > return -ENOENT; > - free_swap_and_cache(radix_to_swp_entry(radswap)); > + free_swap_and_cache_nr(radix_to_swp_entry(radswap), 1 << order); > return 0; > } > =20 > @@ -981,6 +981,7 @@ static void shmem_undo_range(struct inode *inode, lof= f_t lstart, loff_t lend, > pgoff_t end =3D (lend + 1) >> PAGE_SHIFT; > struct folio_batch fbatch; > pgoff_t indices[PAGEVEC_SIZE]; > + int orders[PAGEVEC_SIZE]; > struct folio *folio; > bool same_folio; > long nr_swaps_freed =3D 0; > @@ -996,15 +997,15 @@ static void shmem_undo_range(struct inode *inode, l= off_t lstart, loff_t lend, > folio_batch_init(&fbatch); > index =3D start; > while (index < end && find_lock_entries(mapping, &index, end - 1, > - &fbatch, indices)) { > + &fbatch, indices, orders)) { > for (i =3D 0; i < folio_batch_count(&fbatch); i++) { > folio =3D fbatch.folios[i]; > =20 > if (xa_is_value(folio)) { > if (unfalloc) > continue; > - nr_swaps_freed +=3D !shmem_free_swap(mapping, > - indices[i], folio); > + if (!shmem_free_swap(mapping, indices[i], folio, orders[i])) > + nr_swaps_freed +=3D 1 << orders[i]; > continue; > } > =20 > @@ -1058,7 +1059,7 @@ static void shmem_undo_range(struct inode *inode, l= off_t lstart, loff_t lend, > cond_resched(); > =20 > if (!find_get_entries(mapping, &index, end - 1, &fbatch, > - indices)) { > + indices, orders)) { > /* If all gone or hole-punch or unfalloc, we're done */ > if (index =3D=3D start || end !=3D -1) > break; > @@ -1072,12 +1073,12 @@ static void shmem_undo_range(struct inode *inode,= loff_t lstart, loff_t lend, > if (xa_is_value(folio)) { > if (unfalloc) > continue; > - if (shmem_free_swap(mapping, indices[i], folio)) { > + if (shmem_free_swap(mapping, indices[i], folio, orders[i])) { > /* Swap was replaced by page: retry */ > index =3D indices[i]; > break; > } > - nr_swaps_freed++; > + nr_swaps_freed +=3D 1 << orders[i]; > continue; > } > =20 > diff --git a/mm/truncate.c b/mm/truncate.c > index 5ce62a939e55..3a4bc9dba451 100644 > --- a/mm/truncate.c > +++ b/mm/truncate.c > @@ -352,7 +352,7 @@ void truncate_inode_pages_range(struct address_space = *mapping, > folio_batch_init(&fbatch); > index =3D start; > while (index < end && find_lock_entries(mapping, &index, end - 1, > - &fbatch, indices)) { > + &fbatch, indices, NULL)) { > truncate_folio_batch_exceptionals(mapping, &fbatch, indices); > for (i =3D 0; i < folio_batch_count(&fbatch); i++) > truncate_cleanup_folio(fbatch.folios[i]); > @@ -392,7 +392,7 @@ void truncate_inode_pages_range(struct address_space = *mapping, > while (index < end) { > cond_resched(); > if (!find_get_entries(mapping, &index, end - 1, &fbatch, > - indices)) { > + indices, NULL)) { > /* If all gone from start onwards, we're done */ > if (index =3D=3D start) > break; > @@ -496,7 +496,7 @@ unsigned long mapping_try_invalidate(struct address_s= pace *mapping, > int i; > =20 > folio_batch_init(&fbatch); > - while (find_lock_entries(mapping, &index, end, &fbatch, indices)) { > + while (find_lock_entries(mapping, &index, end, &fbatch, indices, NULL))= { > for (i =3D 0; i < folio_batch_count(&fbatch); i++) { > struct folio *folio =3D fbatch.folios[i]; > =20 > @@ -622,7 +622,7 @@ int invalidate_inode_pages2_range(struct address_spac= e *mapping, > =20 > folio_batch_init(&fbatch); > index =3D start; > - while (find_get_entries(mapping, &index, end, &fbatch, indices)) { > + while (find_get_entries(mapping, &index, end, &fbatch, indices, NULL)) = { > for (i =3D 0; i < folio_batch_count(&fbatch); i++) { > struct folio *folio =3D fbatch.folios[i]; > =20 > --=20 > 2.39.3 >=20 Daniel=