mm: swap: drop last SWAP_MAP_SHMEM flag in batch in swap_entries_put_nr()

The SWAP_MAP_SHMEM indicates last map from shmem.  Therefore we can drop
SWAP_MAP_SHMEM in batch in similar way to drop last ref count in batch.

Link: https://lkml.kernel.org/r/20250325162528.68385-6-shikemeng@huaweicloud.com
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
Cc: Kairui Song <kasong@tencent.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
pull/1253/head
Kemeng Shi 2025-03-26 00:25:25 +08:00 committed by Andrew Morton
parent 46e0ab2c62
commit f2252acf44
1 changed files with 5 additions and 2 deletions

View File

@ -192,7 +192,7 @@ static bool swap_is_last_map(struct swap_info_struct *si,
unsigned char *map_end = map + nr_pages; unsigned char *map_end = map + nr_pages;
unsigned char count = *map; unsigned char count = *map;
if (swap_count(count) != 1) if (swap_count(count) != 1 && swap_count(count) != SWAP_MAP_SHMEM)
return false; return false;
while (++map < map_end) { while (++map < map_end) {
@ -1487,7 +1487,10 @@ static bool swap_entries_put_nr(struct swap_info_struct *si,
unsigned char count; unsigned char count;
int i; int i;
if (nr <= 1 || swap_count(data_race(si->swap_map[offset])) != 1) if (nr <= 1)
goto fallback;
count = swap_count(data_race(si->swap_map[offset]));
if (count != 1 && count != SWAP_MAP_SHMEM)
goto fallback; goto fallback;
/* cross into another cluster */ /* cross into another cluster */
if (nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER) if (nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER)