From: Matthew Wilcox <willy@infradead.org>
To: Jinjiang Tu <tujinjiang@huawei.com>
Cc: fengwei.yin@intel.com, akpm@linux-foundation.org,
david@redhat.com, linux-mm@kvack.org, wangkefeng.wang@huawei.com
Subject: Re: [PATCH] filemap: optimize order0 folio in filemap_map_pages
Date: Tue, 19 Aug 2025 16:52:16 +0100 [thread overview]
Message-ID: <aKSdsH_yk69EvkMX@casper.infradead.org> (raw)
In-Reply-To: <20250819140653.3229136-1-tujinjiang@huawei.com>
On Tue, Aug 19, 2025 at 10:06:53PM +0800, Jinjiang Tu wrote:
> There are two meaningless folio refcount update for order0 folio in
> filemap_map_pages(). First, filemap_map_order0_folio() adds folio refcount
> after the folio is mapped to pte. And then, filemap_map_pages() drops a
> refcount grabbed by next_uptodate_folio(). We could remain the refcount
> unchanged in this case.
>
> With this patch, we can get 8% performance gain for lmbench testcase
> 'lat_pagefault -P 1 file', the size of file is 512M.
You don't explain why you move the folio_unlock() call
> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
> ---
> mm/filemap.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 751838ef05e5..5de52deab138 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -3693,6 +3693,8 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
> }
>
> vmf->pte = old_ptep;
> + folio_unlock(folio);
> + folio_put(folio);
>
> return ret;
> }
> @@ -3705,7 +3707,7 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf,
> struct page *page = &folio->page;
>
> if (PageHWPoison(page))
> - return ret;
> + goto out;
>
> /* See comment of filemap_map_folio_range() */
> if (!folio_test_workingset(folio))
> @@ -3717,15 +3719,19 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf,
> * the fault-around logic.
> */
> if (!pte_none(ptep_get(vmf->pte)))
> - return ret;
> + goto out;
>
> if (vmf->address == addr)
> ret = VM_FAULT_NOPAGE;
>
> set_pte_range(vmf, folio, page, 1, addr);
> (*rss)++;
> - folio_ref_inc(folio);
> + folio_unlock(folio);
> + return ret;
>
> +out:
> + folio_unlock(folio);
> + folio_put(folio);
> return ret;
> }
>
> @@ -3783,9 +3789,6 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf,
> ret |= filemap_map_folio_range(vmf, folio,
> xas.xa_index - folio->index, addr,
> nr_pages, &rss, &mmap_miss);
> -
> - folio_unlock(folio);
> - folio_put(folio);
> } while ((folio = next_uptodate_folio(&xas, mapping, end_pgoff)) != NULL);
> add_mm_counter(vma->vm_mm, folio_type, rss);
> pte_unmap_unlock(vmf->pte, vmf->ptl);
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2025-08-19 15:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-19 14:06 [PATCH] filemap: optimize order0 folio in filemap_map_pages Jinjiang Tu
2025-08-19 15:52 ` Matthew Wilcox [this message]
2025-08-20 1:10 ` Jinjiang Tu
2025-08-20 12:42 ` Matthew Wilcox
2025-08-21 1:22 ` Jinjiang Tu
2025-08-21 12:45 ` Matthew Wilcox
2025-08-21 12:57 ` David Hildenbrand
2025-08-21 13:20 ` Matthew Wilcox
2025-08-21 13:35 ` David Hildenbrand
2025-09-02 14:04 ` Kefeng Wang
2025-09-03 4:50 ` Matthew Wilcox
2025-09-03 6:22 ` Kefeng Wang
2025-08-22 2:01 ` Jinjiang Tu
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=aKSdsH_yk69EvkMX@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=fengwei.yin@intel.com \
--cc=linux-mm@kvack.org \
--cc=tujinjiang@huawei.com \
--cc=wangkefeng.wang@huawei.com \
/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).