Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: swap: use swap_entries_free() to free swap entry in swap_entry_put_locked()

In swap_entry_put_locked(), we will set slot to SWAP_HAS_CACHE before
using swap_entries_free() to do actual swap entry freeing. This introduce
an unnecessary intermediate state. By using swap_entries_free() in
swap_entry_put_locked(), we can eliminate the need to set slot to
SWAP_HAS_CACHE. This change would make the behavior of
swap_entry_put_locked() more consistent with other put() operations which
will do actual free work after put last reference.

Link: https://lkml.kernel.org/r/20250325162528.68385-4-shikemeng@huaweicloud.com
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
Reviewed-by: Kairui Song <kasong@tencent.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kemeng Shi and committed by
Andrew Morton
835b8688 64944ef6

+9 -11
+9 -11
mm/swapfile.c
··· 1356 1356 } 1357 1357 1358 1358 static unsigned char swap_entry_put_locked(struct swap_info_struct *si, 1359 - unsigned long offset, 1359 + struct swap_cluster_info *ci, 1360 + swp_entry_t entry, 1360 1361 unsigned char usage) 1361 1362 { 1363 + unsigned long offset = swp_offset(entry); 1362 1364 unsigned char count; 1363 1365 unsigned char has_cache; 1364 1366 ··· 1392 1390 if (usage) 1393 1391 WRITE_ONCE(si->swap_map[offset], usage); 1394 1392 else 1395 - WRITE_ONCE(si->swap_map[offset], SWAP_HAS_CACHE); 1393 + swap_entries_free(si, ci, entry, 1); 1396 1394 1397 1395 return usage; 1398 1396 } ··· 1471 1469 unsigned char usage; 1472 1470 1473 1471 ci = lock_cluster(si, offset); 1474 - usage = swap_entry_put_locked(si, offset, 1); 1475 - if (!usage) 1476 - swap_entries_free(si, ci, swp_entry(si->type, offset), 1); 1472 + usage = swap_entry_put_locked(si, ci, entry, 1); 1477 1473 unlock_cluster(ci); 1478 1474 1479 1475 return usage; ··· 1570 1570 1571 1571 ci = lock_cluster(si, offset); 1572 1572 do { 1573 - if (!swap_entry_put_locked(si, offset, usage)) 1574 - swap_entries_free(si, ci, swp_entry(si->type, offset), 1); 1573 + swap_entry_put_locked(si, ci, swp_entry(si->type, offset), 1574 + usage); 1575 1575 } while (++offset < end); 1576 1576 unlock_cluster(ci); 1577 1577 } ··· 1616 1616 if (swap_only_has_cache(si, offset, size)) 1617 1617 swap_entries_free(si, ci, entry, size); 1618 1618 else { 1619 - for (int i = 0; i < size; i++, entry.val++) { 1620 - if (!swap_entry_put_locked(si, offset + i, SWAP_HAS_CACHE)) 1621 - swap_entries_free(si, ci, entry, 1); 1622 - } 1619 + for (int i = 0; i < size; i++, entry.val++) 1620 + swap_entry_put_locked(si, ci, entry, SWAP_HAS_CACHE); 1623 1621 } 1624 1622 unlock_cluster(ci); 1625 1623 }