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 68D8EC27C55 for ; Mon, 10 Jun 2024 15:23:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 056A86B009A; Mon, 10 Jun 2024 11:23:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 005F56B009B; Mon, 10 Jun 2024 11:23:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9B7F6B009C; Mon, 10 Jun 2024 11:23:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B3A4C6B009A for ; Mon, 10 Jun 2024 11:23:15 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 269F0160A8A for ; Mon, 10 Jun 2024 15:23:15 +0000 (UTC) X-FDA: 82215347550.14.891BC8C Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf15.hostedemail.com (Postfix) with ESMTP id B5EBAA0004 for ; Mon, 10 Jun 2024 15:23:11 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=LeGw68Ls; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf15.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718032992; 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:dkim-signature; bh=xsQRh9XT0ssETz1BZhE8jFAxkkrZ+caHg8QHRypEaZQ=; b=xBGyQkA1q8u2OOTUKGwUZRam1pDd+5UcuTqRyqPA5QU3j4UQmHoxNUA56+fUZCDkazs3dm 9haamLEmz9tsQWpYFlTNjV6OYtgy6Rk3bs1OVQPwcwMJ4RuVDPwZ+pC/iUbHrfwFH56IR6 Omun35nfsvwqJ+1PZYYu33pgrW7Djy4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=LeGw68Ls; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf15.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718032992; a=rsa-sha256; cv=none; b=K9+ebt2s1/9kF9zXMVaDH2l00PgSVfKdLEZOXoiMjicesR6wqVNkjr2gtODdwlE34aohS4 AKV8ZOmaY1hR2RSOrZ0dPImciFbPY9kqaZ3MGp1+Cd0kPY9McWgSl2V2VtzevHFlVrMMua eZhQAAF6+jcbxzIk4ARUu7b9lvSP0ek= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240610152309euoutp01f50e5f239c93d1370511327bd7572304~Xrea0Ztgt1025410254euoutp01b for ; Mon, 10 Jun 2024 15:23:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240610152309euoutp01f50e5f239c93d1370511327bd7572304~Xrea0Ztgt1025410254euoutp01b 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 x-originating-ip: [106.110.32.67] Content-Type: text/plain; charset="us-ascii" Content-ID: <9399C4818E7B364CA97436B94E4A03A5@scsc.local> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJKsWRmVeSWpSXmKPExsWy7djP87oxUulpBqf+m1p8vitkMWf9GjaL /3uPMVo0PXjEZPF1/S9mi6ef+lgsFv02tri8aw6bxb01/1ktenZPZbRYcGIxo0Xj5/uMFr9/ ACVOzprMYjH76D12B36PNfPWMHrsnHWX3WPB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Vy Ncm/H1QN12WyvK9ne+N/3aGg4PyPYNfM9h3VBwyd6zITpV8Y39X0aarwlftRcH1Py77TUy1n Prnew3sopUngXrp92J5tW1Z+NspnkTjJZhxcmf2uOu+FhWvA4upZH7ntu2TttL5ujTESbn1q seHbClP+/PomwzXfZJv3T/FQYinOSDTUYi4qTgQADOPzoBMEAAA= 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> X-Rspamd-Queue-Id: B5EBAA0004 X-Stat-Signature: eagqb9k7uaqn58xwxdq1b3ugbinqc1ix X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718032991-18938 X-HE-Meta: U2FsdGVkX19sN1dO5B+bKeUKdQ2V44EfECUgXa/rSGczV/Y9udwxQ5t0vHFFVgNdxj4dS6qLNpR/zrC19djnSkKk9nackx08wZARC/JBUmE8N0ntgR5wQx9THexRqIQ/tK/QRlMfHqj+Ftp8AzTPqHaVczXkDDWDgGwwU1G/6/42KHdwPzRlZPwED4dwG84OWZfPdJaeAzksdWKw+87kwUOAAYFZC4oDZRGvEvCmVmhW7Uc68/clt4Q7+BVxeo6xIUouOM3A4lsYJkObZ+X0yDR3GiBJdn/W3jw9taq64MthQkRbmVTznlh8lQk7ctMxYL+z286R8+foB+Gu7CyZlzIW2a1+iU0/hUnZNaiA70OGn7UzpVeWZTupgZTzvaFLhx3Z119BQ1WHuICsYa2racd6qUxKwU/XY7GZNMv5wFAUoooZfP8ifCwtsSMLGs0M6i9tvI/GR96npPZ3A4yj959j1V2j7u11E0dRl94wIbJ/OQ7buab5/f0ctHYaJt3lWArx5Vf50fqeVWV6Nir+S2kCdqn9RkQ78+IIzByytMsI9KuN6ofQRfY/uN+Tbv7brqAq29YJOD+iEjaWLfIoF9NqD3OpaJg0HQgn4TqL/dIwJ2hhZJ7e0ZNRBc3/RlRxq5f8SHXT25FeGdyG7WRO1HadGaxYP+jc4+nGZBonukOfNvcLZsIAhaQrvdCvS7vXTaF3cTVnqNgzIOSgpA/se0bFY62y2lnmPvoL7ZReSpsMD4zZ0F/+OB6SGBuiCJRXLGYn9gPw1pRhsET3huPQ/19SiG00Pn+E2HgZs8cqPm7eOAs1AkYrpcugTNJ3vraecHrG/e3n+A//ZYMJTJhmN7jDwo7tXYDj+y9K3auP+7W9RaZ0SiYDaO46R9BQ+oNB5MfUbKIeaAxxbHVuYgJkI56i91ItofY9+boj1CEui6BzWxCyfTHVYwogAHo1VmYm5u82dX5ml4YoGacGMDw xvVN7M7J V0CCj6LGAbAQY9uPxkG/GQvEn1fmQdtp2cx6jlpOwww6t6Ae2lGA714nn8bv2iliFxloKWn5qNI9ZOCZbxVCNydPsID+ZA4/KF0ZxafG0L3sZWO8DLOl77rPI+6ja1Wlm0uay35Y+mFtse5UTSNVjk9RZH4hlhgmT8yd+1cgkKoGs+uDz9hlXoIdSDVyQ9cKfChYgUDnbXKxKegXtmMta6igICw== 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: 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=