Skip to content

RFC kernel/power: fix swap device reference handling in hibernation swap path

Youngjun Park linux-mm linux-pm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2mm/swap: release swap reference on each hibernation slot allocationinclude/linux/swap.h mm/swapfile.c+28 -280 replies
2/2kernel/power: hold swap device reference across hibernation swap operationkernel/power/swap.c kernel/power/user.c+17 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/2] kernel/power: fix swap device reference handling in hibernation swap path

This series addresses two issues in the hibernation swap path.

First, grabbing and releasing the swap device reference on every slot allocation is inefficient across the entire hibernation swap path.

Second, in the uswsusp path, only the swap type value is retrieved at lookup time without holding a reference. If swapoff races after the type is acquired, subsequent slot allocations operate on a stale swap device.

The fix is to hold the swap device reference from the point the swap device is looked up, and release it once at each exit path.

Patch 1: Release the reference immediately after each slot allocation
as a preparatory step.
Patch 2: Lift the reference acquisition to the lookup site and place
put_swap_device_by_type() at all relevant cleanup paths in swap.c and user.c.

This series is based on mm-new.

I'm sending this as RFC because my familiarity with the kernel/power and snapshot paths is limited. I believe the approach is reasonable, but I'd appreciate any feedback before moving forward with proper testing and a formal submission.

Thanks,
Youngjun Park

Youngjun Park (2):
mm/swap: release swap reference on each hibernation slot allocation kernel/power: hold swap device reference across hibernation swap
operation

 include/linux/swap.h |  1 +
 kernel/power/swap.c  | 12 +++++++---
 kernel/power/user.c  |  9 +++++++-
 mm/swapfile.c        | 55 ++++++++++++++++++++++----------------------
 4 files changed, 45 insertions(+), 32 deletions(-)
Signature · 1 line
2.34.1