Skip to content

ramzswap: Eliminate stale data in compressed memory

Nitin Gupta lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3Send callback when a swap slot is freedinclude/linux/swap.h mm/swapfile.c+20 -00 replies
2/3Add notifiers for swapon and swapoff eventsinclude/linux/swap.h mm/swapfile.c+13 -20 replies
3/3Add handlers for swap eventsdrivers/staging/ramzswap/ramzswap_drv.c drivers/staging/ramzswap/ramzswap_drv.h drivers/staging/ramzswap/ramzswap_ioctl.h+3 -00 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 0/3] ramzswap: Eliminate stale data in compressed memory

ramzswap driver creates RAM based block devices which can be used (only) as swap disks. Pages swapped to these disks are compressed and stored in memory itself.

However, these devices do not get any notification when a swap slot is freed (swap_map[i] reaches 0). So, we cannot free memory allocated corresponding to this swap slot. Such stale data can quickly accumulate in (compressed) memory defeating the whole purpose of such devices.

To overcome this problem, we now add a callback in 'struct swap_info_struct' which is called as soon as a swap slot is freed.

Adding handler for this callback:

	swapon notifier --> set_swap_free_notify(swap_type, fn)

Removing handler:

	swapoff notifier --> set_swap_free_notify(swap_type, NULL)

Alternative approaches:
1) Add callback directly in 'struct block_device_operations' but that is considered too hacky.
2) Use swap discard mechanism: It involves unncessary overhead of allocating 'discard bio' requests and its too slow to serve ramzswap needs.

 drivers/staging/ramzswap/ramzswap_drv.c   |   91 +++++++++++++++++++++++++++++
 drivers/staging/ramzswap/ramzswap_drv.h   |    1 +
 drivers/staging/ramzswap/ramzswap_ioctl.h |    1 +
 include/linux/swap.h                      |   16 +++++-
 mm/swapfile.c                             |   78 ++++++++++++++++++++++++
 5 files changed, 185 insertions(+), 2 deletions(-)