From: David Hildenbrand <david@redhat.com>
To: Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm: shmem: extend shmem_unused_huge_shrink() to all sizes
Date: Mon, 26 Aug 2024 08:53:15 +0200 [thread overview]
Message-ID: <0b36595c-db50-4e8b-96db-2d4ceeaa1908@redhat.com> (raw)
In-Reply-To: <d8c40850-6774-7a93-1e2c-8d941683b260@google.com>
On 26.08.24 01:25, Hugh Dickins wrote:
> Although shmem_get_folio_gfp() is correctly putting inodes on the
> shrinklist according to the folio size, shmem_unused_huge_shrink()
> was still dealing with that shrinklist in terms of HPAGE_PMD_SIZE.
>
> Generalize that; and to handle the mixture of sizes more sensibly,
> shmem_alloc_and_add_folio() give it a number of pages to be freed
> (approximate: no need to minimize that with an exact calculation)
> instead of a number of inodes to split.
That might be worth a comment in the code.
>
> Signed-off-by: Hugh Dickins <hughd@google.com>
> ---
> This patch would most naturally go into mm-unstable as 10/9 over
> Baolin's "support large folio swap-out and swap-in for shmem" series.
>
> mm/shmem.c | 45 ++++++++++++++++++++-------------------------
> 1 file changed, 20 insertions(+), 25 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 4dd0570962fa..4c9921c234b7 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -636,15 +636,14 @@ static const char *shmem_format_huge(int huge)
> #endif
>
> static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo,
> - struct shrink_control *sc, unsigned long nr_to_split)
> + struct shrink_control *sc, unsigned long nr_to_free)
> {
> LIST_HEAD(list), *pos, *next;
> - LIST_HEAD(to_remove);
> struct inode *inode;
> struct shmem_inode_info *info;
> struct folio *folio;
> unsigned long batch = sc ? sc->nr_to_scan : 128;
> - int split = 0;
> + unsigned long split = 0, freed = 0;
>
> if (list_empty(&sbinfo->shrinklist))
> return SHRINK_STOP;
> @@ -662,13 +661,6 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo,
> goto next;
> }
>
> - /* Check if there's anything to gain */
> - if (round_up(inode->i_size, PAGE_SIZE) ==
> - round_up(inode->i_size, HPAGE_PMD_SIZE)) {
> - list_move(&info->shrinklist, &to_remove);
> - goto next;
> - }
> -
> list_move(&info->shrinklist, &list);
> next:
> sbinfo->shrinklist_len--;
> @@ -677,34 +669,36 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo,
> }
> spin_unlock(&sbinfo->shrinklist_lock);
>
> - list_for_each_safe(pos, next, &to_remove) {
> - info = list_entry(pos, struct shmem_inode_info, shrinklist);
> - inode = &info->vfs_inode;
> - list_del_init(&info->shrinklist);
> - iput(inode);
> - }
> -
> list_for_each_safe(pos, next, &list) {
> + pgoff_t next, end;
> + loff_t i_size;
> int ret;
> - pgoff_t index;
>
> info = list_entry(pos, struct shmem_inode_info, shrinklist);
> inode = &info->vfs_inode;
>
> - if (nr_to_split && split >= nr_to_split)
> + if (nr_to_free && freed >= nr_to_free)
> goto move_back;
>
> - index = (inode->i_size & HPAGE_PMD_MASK) >> PAGE_SHIFT;
> - folio = filemap_get_folio(inode->i_mapping, index);
> - if (IS_ERR(folio))
> + i_size = i_size_read(inode);
> + folio = filemap_get_entry(inode->i_mapping, i_size / PAGE_SIZE);
> + if (!folio || xa_is_value(folio))
> goto drop;
>
> - /* No huge page at the end of the file: nothing to split */
> + /* No large page at the end of the file: nothing to split */
s/large page/large folio/
Or simply "Nothing to split."
> if (!folio_test_large(folio)) {
> folio_put(folio);
> goto drop;
> }
>
> + /* Check if there is anything to gain from splitting */
> + next = folio_next_index(folio);
> + end = shmem_fallocend(inode, DIV_ROUND_UP(i_size, PAGE_SIZE));
> + if (end <= folio->index || end >= next) {
> + folio_put(folio);
> + goto drop;
> + }
> +
Looks sensible to me
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
prev parent reply other threads:[~2024-08-26 6:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-25 23:25 [PATCH] mm: shmem: extend shmem_unused_huge_shrink() to all sizes Hugh Dickins
2024-08-26 6:53 ` David Hildenbrand [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0b36595c-db50-4e8b-96db-2d4ceeaa1908@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=hughd@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).