* [PATCH v3] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused
@ 2024-07-24 2:00 Barry Song
2024-07-24 7:46 ` Chris Li
0 siblings, 1 reply; 2+ messages in thread
From: Barry Song @ 2024-07-24 2:00 UTC (permalink / raw)
To: akpm, linux-mm
Cc: chrisl, david, hanchuanhua, kasong, linux-kernel, ryan.roberts,
v-songbaohua, ying.huang
From: Barry Song <v-songbaohua@oppo.com>
Extend a usage parameter so that cluster_swap_free_nr() can be reused by
both swapcache_clear() and swap_free().
__swap_entry_free() is quite similar but more tricky as it requires the
return value of __swap_entry_free_locked() which cluster_swap_free_nr()
doesn't support.
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Chuanhua Han <hanchuanhua@oppo.com>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
---
-v3: resend &collect Ryan's reviewed-by
mm/swapfile.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 38bdc439651a..5f73a8553371 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1344,7 +1344,8 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry)
}
static void cluster_swap_free_nr(struct swap_info_struct *sis,
- unsigned long offset, int nr_pages)
+ unsigned long offset, int nr_pages,
+ unsigned char usage)
{
struct swap_cluster_info *ci;
DECLARE_BITMAP(to_free, BITS_PER_LONG) = { 0 };
@@ -1354,7 +1355,7 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis,
while (nr_pages) {
nr = min(BITS_PER_LONG, nr_pages);
for (i = 0; i < nr; i++) {
- if (!__swap_entry_free_locked(sis, offset + i, 1))
+ if (!__swap_entry_free_locked(sis, offset + i, usage))
bitmap_set(to_free, i, 1);
}
if (!bitmap_empty(to_free, BITS_PER_LONG)) {
@@ -1388,7 +1389,7 @@ void swap_free_nr(swp_entry_t entry, int nr_pages)
while (nr_pages) {
nr = min_t(int, nr_pages, SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER);
- cluster_swap_free_nr(sis, offset, nr);
+ cluster_swap_free_nr(sis, offset, nr, 1);
offset += nr;
nr_pages -= nr;
}
@@ -3472,15 +3473,9 @@ int swapcache_prepare(swp_entry_t entry)
void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry)
{
- struct swap_cluster_info *ci;
unsigned long offset = swp_offset(entry);
- unsigned char usage;
- ci = lock_cluster_or_swap_info(si, offset);
- usage = __swap_entry_free_locked(si, offset, SWAP_HAS_CACHE);
- unlock_cluster_or_swap_info(si, ci);
- if (!usage)
- free_swap_slot(entry);
+ cluster_swap_free_nr(si, offset, 1, SWAP_HAS_CACHE);
}
struct swap_info_struct *swp_swap_info(swp_entry_t entry)
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v3] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused
2024-07-24 2:00 [PATCH v3] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused Barry Song
@ 2024-07-24 7:46 ` Chris Li
0 siblings, 0 replies; 2+ messages in thread
From: Chris Li @ 2024-07-24 7:46 UTC (permalink / raw)
To: Barry Song
Cc: akpm, linux-mm, david, hanchuanhua, kasong, linux-kernel,
ryan.roberts, v-songbaohua, ying.huang
Acked-by: Chris Li <chrisl@kernel.org>
Chris
On Tue, Jul 23, 2024 at 7:01 PM Barry Song <21cnbao@gmail.com> wrote:
>
> From: Barry Song <v-songbaohua@oppo.com>
>
> Extend a usage parameter so that cluster_swap_free_nr() can be reused by
> both swapcache_clear() and swap_free().
> __swap_entry_free() is quite similar but more tricky as it requires the
> return value of __swap_entry_free_locked() which cluster_swap_free_nr()
> doesn't support.
>
> Cc: "Huang, Ying" <ying.huang@intel.com>
> Cc: Chris Li <chrisl@kernel.org>
> Cc: Kairui Song <kasong@tencent.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Chuanhua Han <hanchuanhua@oppo.com>
> Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> ---
> -v3: resend &collect Ryan's reviewed-by
>
> mm/swapfile.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 38bdc439651a..5f73a8553371 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1344,7 +1344,8 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry)
> }
>
> static void cluster_swap_free_nr(struct swap_info_struct *sis,
> - unsigned long offset, int nr_pages)
> + unsigned long offset, int nr_pages,
> + unsigned char usage)
> {
> struct swap_cluster_info *ci;
> DECLARE_BITMAP(to_free, BITS_PER_LONG) = { 0 };
> @@ -1354,7 +1355,7 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis,
> while (nr_pages) {
> nr = min(BITS_PER_LONG, nr_pages);
> for (i = 0; i < nr; i++) {
> - if (!__swap_entry_free_locked(sis, offset + i, 1))
> + if (!__swap_entry_free_locked(sis, offset + i, usage))
> bitmap_set(to_free, i, 1);
> }
> if (!bitmap_empty(to_free, BITS_PER_LONG)) {
> @@ -1388,7 +1389,7 @@ void swap_free_nr(swp_entry_t entry, int nr_pages)
>
> while (nr_pages) {
> nr = min_t(int, nr_pages, SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER);
> - cluster_swap_free_nr(sis, offset, nr);
> + cluster_swap_free_nr(sis, offset, nr, 1);
> offset += nr;
> nr_pages -= nr;
> }
> @@ -3472,15 +3473,9 @@ int swapcache_prepare(swp_entry_t entry)
>
> void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry)
> {
> - struct swap_cluster_info *ci;
> unsigned long offset = swp_offset(entry);
> - unsigned char usage;
>
> - ci = lock_cluster_or_swap_info(si, offset);
> - usage = __swap_entry_free_locked(si, offset, SWAP_HAS_CACHE);
> - unlock_cluster_or_swap_info(si, ci);
> - if (!usage)
> - free_swap_slot(entry);
> + cluster_swap_free_nr(si, offset, 1, SWAP_HAS_CACHE);
> }
>
> struct swap_info_struct *swp_swap_info(swp_entry_t entry)
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-24 7:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-24 2:00 [PATCH v3] mm: Extend 'usage' parameter so that cluster_swap_free_nr() can be reused Barry Song
2024-07-24 7:46 ` Chris Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox