From: Barry Song <21cnbao@gmail.com>
To: akpm@linux-foundation.org, linux-mm@kvack.org
Cc: david@redhat.com, willy@infradead.org, ryan.roberts@arm.com,
yosryahmed@google.com, hughd@google.com, hannes@cmpxchg.org,
surenb@google.com, xiang@kernel.org, yuzhao@google.com,
ying.huang@intel.com, chrisl@kernel.org, kasong@tencent.com,
ziy@nvidia.com, baolin.wang@linux.alibaba.com,
hanchuanhua@oppo.com, Barry Song <v-songbaohua@oppo.com>
Subject: [PATCH 3/4] mm: swap_pte_batch: add an output argument to reture if all swap entries are exclusive
Date: Tue, 2 Apr 2024 20:32:36 +1300 [thread overview]
Message-ID: <20240402073237.240995-4-21cnbao@gmail.com> (raw)
In-Reply-To: <20240402073237.240995-1-21cnbao@gmail.com>
From: Barry Song <v-songbaohua@oppo.com>
Add a boolean argument named any_shared. If any of the swap entries are
non-exclusive, set any_shared to true. The function do_swap_page() can
then utilize this information to determine whether the entire large
folio can be reused.
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
---
mm/internal.h | 5 ++++-
mm/madvise.c | 2 +-
mm/memory.c | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/mm/internal.h b/mm/internal.h
index 9512de7398d5..ffdd1b049c77 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -216,7 +216,7 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr,
* Return: the number of table entries in the batch.
*/
static inline int swap_pte_batch(pte_t *start_ptep, int max_nr,
- swp_entry_t entry)
+ swp_entry_t entry, bool *any_shared)
{
const pte_t *end_ptep = start_ptep + max_nr;
unsigned long expected_offset = swp_offset(entry) + 1;
@@ -239,6 +239,9 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr,
swp_offset(entry) != expected_offset)
break;
+ if (any_shared)
+ *any_shared |= !pte_swp_exclusive(pte);
+
expected_offset++;
ptep++;
}
diff --git a/mm/madvise.c b/mm/madvise.c
index bd00b83e7c50..d4624fb92665 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -672,7 +672,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
entry = pte_to_swp_entry(ptent);
if (!non_swap_entry(entry)) {
max_nr = (end - addr) / PAGE_SIZE;
- nr = swap_pte_batch(pte, max_nr, entry);
+ nr = swap_pte_batch(pte, max_nr, entry, NULL);
nr_swap -= nr;
free_swap_and_cache_nr(entry, nr);
clear_not_present_full_ptes(mm, addr, pte, nr, tlb->fullmm);
diff --git a/mm/memory.c b/mm/memory.c
index f6377cc4c1ca..0a80e75af22c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1632,7 +1632,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
folio_put(folio);
} else if (!non_swap_entry(entry)) {
max_nr = (end - addr) / PAGE_SIZE;
- nr = swap_pte_batch(pte, max_nr, entry);
+ nr = swap_pte_batch(pte, max_nr, entry, NULL);
/* Genuine swap entries, hence a private anon pages */
if (!should_zap_cows(details))
continue;
--
2.34.1
next prev parent reply other threads:[~2024-04-02 7:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 7:32 [PATCH 0/4] large folios swap-in: handle refault cases first Barry Song
2024-04-02 7:32 ` [PATCH 1/4] mm: swap: introduce swap_free_nr() for batched swap_free() Barry Song
2024-04-02 7:32 ` [PATCH 2/4] mm: swap: make should_try_to_free_swap() support large-folio Barry Song
2024-04-02 7:32 ` Barry Song [this message]
2024-04-02 7:32 ` [PATCH 4/4] mm: swap: entirely map large folios found in swapcache Barry Song
2024-04-07 2:24 ` Barry Song
2024-04-08 7:18 ` Huang, Ying
2024-04-08 7:27 ` Barry Song
2024-04-08 7:49 ` Huang, Ying
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=20240402073237.240995-4-21cnbao@gmail.com \
--to=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=hanchuanhua@oppo.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=v-songbaohua@oppo.com \
--cc=willy@infradead.org \
--cc=xiang@kernel.org \
--cc=ying.huang@intel.com \
--cc=yosryahmed@google.com \
--cc=yuzhao@google.com \
--cc=ziy@nvidia.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