public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] ramzswap: Eliminate stale data in compressed memory
@ 2010-05-05 13:45 Nitin Gupta
  2010-05-05 13:45 ` [PATCH 1/3] Add notifiers for swapon and swapoff events Nitin Gupta
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Nitin Gupta @ 2010-05-05 13:45 UTC (permalink / raw)
  To: Greg KH
  Cc: Minchan Kim, Pekka Enberg, Hugh Dickins, Cyp, Linus Torvalds,
	driverdev, linux-kernel

(tested on mainline but should apply to linux-next cleanly)

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 (nacked by Linus).
2) Use swap discard mechanism: It involves unncessary overhead of
allocating 'discard bio' requests and its too slow to serve ramzswap
needs.

I also tried an approach similar to what Linus suggested:
Create an address_space like swaper_space, so we can catch
read/writes with a_ops->readpage() etc. However, this approach
turned out to be quite difficult and I could not get it to work.

Nitin Gupta (3):
  Add notifiers for swapon and swapoff events
  Send callback when a swap slot is freed
  ramzswap: Register for swap event notifiers and callback

 drivers/staging/ramzswap/TODO           |    5 --
 drivers/staging/ramzswap/ramzswap_drv.c |   79 ++++++++++++++++++++++++++++++-
 include/linux/swap.h                    |   15 ++++++
 mm/swapfile.c                           |   70 +++++++++++++++++++++++++++
 4 files changed, 163 insertions(+), 6 deletions(-)
 delete mode 100644 drivers/staging/ramzswap/TODO


^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH 0/3] ramzswap: Eliminate stale data in compressed memory
@ 2010-03-05 10:22 Nitin Gupta
  2010-03-09 19:07 ` Nitin Gupta
  2010-03-11  7:22 ` Hugh Dickins
  0 siblings, 2 replies; 13+ messages in thread
From: Nitin Gupta @ 2010-03-05 10:22 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Linus Torvalds, Andrew Morton, Greg KH, Pekka Enberg, andi,
	linux-kernel

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(-)

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-05-05 17:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-05 13:45 [PATCH 0/3] ramzswap: Eliminate stale data in compressed memory Nitin Gupta
2010-05-05 13:45 ` [PATCH 1/3] Add notifiers for swapon and swapoff events Nitin Gupta
2010-05-05 13:45 ` [PATCH 2/3] Send callback when a swap slot is freed Nitin Gupta
2010-05-05 13:45 ` [PATCH 3/3] ramzswap: Register for swap event notifiers and callback Nitin Gupta
2010-05-05 15:14 ` [PATCH 0/3] ramzswap: Eliminate stale data in compressed memory Linus Torvalds
2010-05-05 16:05   ` Nitin Gupta
2010-05-05 16:22     ` Linus Torvalds
2010-05-05 16:55       ` Nitin Gupta
2010-05-05 17:50         ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2010-03-05 10:22 Nitin Gupta
2010-03-09 19:07 ` Nitin Gupta
2010-03-11  7:22 ` Hugh Dickins
2010-03-11 11:36   ` Nitin Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox