From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
<linux-mm@kvack.org>, <linux-fsdevel@vger.kernel.org>,
Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH rfc 2/4] mm: filemap: add filemap_set_pte_range()
Date: Mon, 29 Apr 2024 15:24:15 +0800 [thread overview]
Message-ID: <20240429072417.2146732-3-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20240429072417.2146732-1-wangkefeng.wang@huawei.com>
Adding filemap_set_pte_range() independent of set_pte_range() to unify
the rss and folio reference update for small folio and large folio, which
also is prepare for the upcoming lruvec stat batch updating.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
mm/filemap.c | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index ec273b00ce5f..7019692daddd 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3499,6 +3499,25 @@ static struct folio *next_uptodate_folio(struct xa_state *xas,
return NULL;
}
+static void filemap_set_pte_range(struct vm_fault *vmf, struct folio *folio,
+ struct page *page, unsigned int nr, unsigned long addr,
+ unsigned long *rss)
+{
+ struct vm_area_struct *vma = vmf->vma;
+ pte_t entry;
+
+ entry = prepare_range_pte_entry(vmf, false, folio, page, nr, addr);
+
+ folio_add_file_rmap_ptes(folio, page, nr, vma);
+ set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr);
+
+ /* no need to invalidate: a not-present page won't be cached */
+ update_mmu_cache_range(vmf, vma, addr, vmf->pte, nr);
+
+ *rss += nr;
+ folio_ref_add(folio, nr);
+}
+
/*
* Map page range [start_page, start_page + nr_pages) of folio.
* start_page is gotten from start by folio_page(folio, start)
@@ -3539,9 +3558,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
continue;
skip:
if (count) {
- set_pte_range(vmf, folio, page, count, addr);
- *rss += count;
- folio_ref_add(folio, count);
+ filemap_set_pte_range(vmf, folio, page, count, addr, rss);
if (in_range(vmf->address, addr, count * PAGE_SIZE))
ret = VM_FAULT_NOPAGE;
}
@@ -3554,9 +3571,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf,
} while (--nr_pages > 0);
if (count) {
- set_pte_range(vmf, folio, page, count, addr);
- *rss += count;
- folio_ref_add(folio, count);
+ filemap_set_pte_range(vmf, folio, page, count, addr, rss);
if (in_range(vmf->address, addr, count * PAGE_SIZE))
ret = VM_FAULT_NOPAGE;
}
@@ -3591,9 +3606,7 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf,
if (vmf->address == addr)
ret = VM_FAULT_NOPAGE;
- set_pte_range(vmf, folio, page, 1, addr);
- (*rss)++;
- folio_ref_inc(folio);
+ filemap_set_pte_range(vmf, folio, page, 1, addr, rss);
return ret;
}
--
2.27.0
next prev parent reply other threads:[~2024-04-29 7:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 7:24 [PATCH rfc 0/4] mm: filemap: try to batch lruvec stat updating Kefeng Wang
2024-04-29 7:24 ` [PATCH rfc 1/4] mm: memory: add prepare_range_pte_entry() Kefeng Wang
2024-04-29 7:24 ` Kefeng Wang [this message]
2024-04-29 7:24 ` [PATCH rfc 3/4] mm: filemap: move __lruvec_stat_mod_folio() out of filemap_set_pte_range() Kefeng Wang
2024-05-07 11:11 ` David Hildenbrand
2024-05-07 13:12 ` Kefeng Wang
2024-05-08 9:33 ` David Hildenbrand
2024-05-08 11:15 ` Kefeng Wang
2024-05-08 11:27 ` David Hildenbrand
2024-05-08 13:56 ` Kefeng Wang
2024-04-29 7:24 ` [PATCH rfc 4/4] mm: filemap: try to batch lruvec stat updating Kefeng Wang
2024-05-07 9:06 ` Kefeng Wang
2024-05-09 14:01 ` Johannes Weiner
2024-05-10 1:55 ` Kefeng Wang
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=20240429072417.2146732-3-wangkefeng.wang@huawei.com \
--to=wangkefeng.wang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.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