Re: [PATCH v3 2/3] mm, swap: reduce indention for hibernate allocation helper

From: Kairui Song

Date: Mon Feb 16 2026 - 01:21:25 EST


On Mon, Feb 16, 2026 at 07:20:49AM +0800, Barry Song wrote:
> On Mon, Feb 16, 2026 at 3:00 AM Kairui Song via B4 Relay
> <devnull+kasong.tencent.com@xxxxxxxxxx> wrote:
> >
> > From: Kairui Song <kasong@xxxxxxxxxxx>
> >
> > It doesn't have to check the device flag, as the allocator will also
> > check the device flag and refuse to allocate if the device is not
> > writable. This might cause a trivial waste of CPU cycles of hibernate
> > allocation raced with swapoff, but that is very unlikely to happen.
> > Removing the check on the common path should be more helpful.
> >
> > Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> > ---
> > mm/swapfile.c | 38 ++++++++++++++++++--------------------
> > 1 file changed, 18 insertions(+), 20 deletions(-)
> >
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index 32e0e7545ab8..0d1b17c99221 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -1936,27 +1936,25 @@ swp_entry_t swap_alloc_hibernation_slot(int type)
> >
> > /* This is called for allocating swap entry, not cache */
> > if (get_swap_device_info(si)) {
>
>
> I guess we could further reduce indentation by doing:
> if (!get_swap_device_info(si))
> goto fail;
>

Agree, I think we can make it even simpler by having:

/* Return empty entry if device is not usable (swapoff or full) */
if (!si || !get_swap_device_info(si))
return entry;

Then the `fail` label is also gone.

I'll post a v4 later today combined with your another suggestion. Thanks!