Commit 808068da authored by Barry Song's avatar Barry Song Committed by Euler
Browse files

mm: extend 'usage' parameter so that cluster_swap_free_nr() can be reused

mainline inclusion
from mainline-v6.12-rc1
commit d2539ed7ee3b042e4503c304603d0eaa50c9c476
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAOMRL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d2539ed7ee3b042e4503c304603d0eaa50c9c476

--------------------------------

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.

Link: https://lkml.kernel.org/r/20240724020056.65838-1-21cnbao@gmail.com


Signed-off-by: default avatarBarry Song <v-songbaohua@oppo.com>
Reviewed-by: default avatarRyan Roberts <ryan.roberts@arm.com>
Acked-by: default avatarChris Li <chrisl@kernel.org>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Chuanhua Han <hanchuanhua@oppo.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarWang Lian <dev01404@linx-info.com>
---
parent 13706c95
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -1427,7 +1427,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 };
@@ -1437,7 +1438,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)) {
@@ -1471,7 +1472,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;
	}
@@ -3570,15 +3571,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)