Re: [PATCH v3 1/3] mm, swap: speed up hibernation allocation and writeout

From: Kairui Song

Date: Mon Feb 16 2026 - 01:06:32 EST


On Mon, Feb 16, 2026 at 04:43:40AM +0800, Barry Song wrote:
> > @@ -1937,11 +1938,21 @@ swp_entry_t swap_alloc_hibernation_slot(int type)
> > if (get_swap_device_info(si)) {
> > if (si->flags & SWP_WRITEOK) {
> > /*
> > - * Grab the local lock to be compliant
> > - * with swap table allocation.
> > + * Try the local cluster first if it matches the device. If
> > + * not, try grab a new cluster and override local cluster.
> > */
> > local_lock(&percpu_swap_cluster.lock);
> > - offset = cluster_alloc_swap_entry(si, NULL);
> > + pcp_si = this_cpu_read(percpu_swap_cluster.si[0]);
> > + pcp_offset = this_cpu_read(percpu_swap_cluster.offset[0]);
> > + if (pcp_si == si && pcp_offset) {
> > + ci = swap_cluster_lock(si, pcp_offset);
> > + if (cluster_is_usable(ci, 0))
> > + offset = alloc_swap_scan_cluster(si, ci, NULL, pcp_offset);
> > + else
> > + swap_cluster_unlock(ci);
> > + }
> > + if (!offset)
>
> I assume you mean SWAP_ENTRY_INVALID? Would that be more readable?

Yes, it's very common in swapfile.c to check !offset since
SWAP_ENTRY_INVALID is zero. But I agree checking SWAP_ENTRY_INVALID
is more readable and maintainable, I'll change to SWAP_ENTRY_INVALID,
also use this macro more in further codes.

Thanks!