* [PATCH 1/3] Add flag to identify block swap devices
2010-05-17 5:32 [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend) Nitin Gupta
@ 2010-05-17 5:32 ` Nitin Gupta
2010-05-17 11:50 ` Minchan Kim
2010-05-17 5:32 ` [PATCH 2/3] Add swap slot free callback to block_device_operations Nitin Gupta
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Nitin Gupta @ 2010-05-17 5:32 UTC (permalink / raw)
To: Greg KH
Cc: Pekka Enberg, Linus Torvalds, Nigel Cunningham, Andrew Morton,
Minchan Kim, Hugh Dickins, Cyp, driverdev, linux-kernel
Added SWP_BLKDEV flag to distinguish block and regular file backed
swap devices. We could also check if a swap is entire block device,
rather than a file, by:
S_ISBLK(swap_info_struct->swap_file->f_mapping->host->i_mode)
but, I think, simply checking this flag is more convenient.
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
---
include/linux/swap.h | 1 +
mm/swapfile.c | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 1f59d93..ec2b7a4 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -146,6 +146,7 @@ enum {
SWP_DISCARDING = (1 << 3), /* now discarding a free cluster */
SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */
SWP_CONTINUED = (1 << 5), /* swap_map has count continuation */
+ SWP_BLKDEV = (1 << 6), /* its a block device */
/* add others here before... */
SWP_SCANNING = (1 << 8), /* refcount in scan_swap_map */
};
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 6cd0a8f..ecb069e 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1884,6 +1884,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
if (error < 0)
goto bad_swap;
p->bdev = bdev;
+ p->flags |= SWP_BLKDEV;
} else if (S_ISREG(inode->i_mode)) {
p->bdev = inode->i_sb->s_bdev;
mutex_lock(&inode->i_mutex);
--
1.6.6.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 1/3] Add flag to identify block swap devices
2010-05-17 5:32 ` [PATCH 1/3] Add flag to identify block swap devices Nitin Gupta
@ 2010-05-17 11:50 ` Minchan Kim
2010-05-17 19:35 ` Hugh Dickins
0 siblings, 1 reply; 13+ messages in thread
From: Minchan Kim @ 2010-05-17 11:50 UTC (permalink / raw)
To: Nitin Gupta
Cc: Greg KH, Pekka Enberg, Linus Torvalds, Nigel Cunningham,
Andrew Morton, Hugh Dickins, Cyp, driverdev, linux-kernel
On Mon, May 17, 2010 at 2:32 PM, Nitin Gupta <ngupta@vflare.org> wrote:
> Added SWP_BLKDEV flag to distinguish block and regular file backed
> swap devices. We could also check if a swap is entire block device,
> rather than a file, by:
> S_ISBLK(swap_info_struct->swap_file->f_mapping->host->i_mode)
> but, I think, simply checking this flag is more convenient.
>
> Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
We can enhance swap_show by the flag as further patch.
--
Kind regards,
Minchan Kim
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/3] Add flag to identify block swap devices
2010-05-17 11:50 ` Minchan Kim
@ 2010-05-17 19:35 ` Hugh Dickins
0 siblings, 0 replies; 13+ messages in thread
From: Hugh Dickins @ 2010-05-17 19:35 UTC (permalink / raw)
To: Minchan Kim
Cc: Nitin Gupta, Greg KH, Pekka Enberg, Linus Torvalds,
Nigel Cunningham, Andrew Morton, Cyp, driverdev, linux-kernel
On Mon, May 17, 2010 at 4:50 AM, Minchan Kim <minchan.kim@gmail.com> wrote:
> On Mon, May 17, 2010 at 2:32 PM, Nitin Gupta <ngupta@vflare.org> wrote:
>> Added SWP_BLKDEV flag to distinguish block and regular file backed
>> swap devices. We could also check if a swap is entire block device,
>> rather than a file, by:
>> S_ISBLK(swap_info_struct->swap_file->f_mapping->host->i_mode)
>> but, I think, simply checking this flag is more convenient.
>>
>> Signed-off-by: Nitin Gupta <ngupta@vflare.org>
> Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
>
> We can enhance swap_show by the flag as further patch.
You mean, make swap_show() decide partition or file by SWP_BLKDEV
instead of its own test?
Actually, I'd prefer we don't embed SWP_BLKDEV further, because it's
a bit of a hack and not really necessary. What ought to happen (though
perhaps it's silly to be expending code over an imaginary case) is a
map_swap_entry() call to convert the swap offset to physical page
within partition - no-op in the partition case, but correcting the file case.
But I wouldn't want to write that patch without testing it,
which I won't be doing for a while.
Hugh
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/3] Add swap slot free callback to block_device_operations
2010-05-17 5:32 [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend) Nitin Gupta
2010-05-17 5:32 ` [PATCH 1/3] Add flag to identify block swap devices Nitin Gupta
@ 2010-05-17 5:32 ` Nitin Gupta
2010-05-17 12:01 ` Minchan Kim
2010-05-17 5:32 ` [PATCH 3/3] ramzswap: Handler for swap slot free callback Nitin Gupta
2010-05-17 6:10 ` [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend) Pekka Enberg
3 siblings, 1 reply; 13+ messages in thread
From: Nitin Gupta @ 2010-05-17 5:32 UTC (permalink / raw)
To: Greg KH
Cc: Pekka Enberg, Linus Torvalds, Nigel Cunningham, Andrew Morton,
Minchan Kim, Hugh Dickins, Cyp, driverdev, linux-kernel
This callback is required when RAM based devices are used as swap disks.
One such device is ramzswap which is used as compressed in-memory swap
disk. For such devices, we need a callback as soon as a swap slot is no
longer used to allow freeing memory allocated for this slot. Without this
callback, stale data can quickly accumulate in memory defeating the whole
purpose of such devices.
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
---
include/linux/blkdev.h | 2 ++
mm/swapfile.c | 4 ++++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 6690e8b..413284a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1287,6 +1287,8 @@ struct block_device_operations {
unsigned long long);
int (*revalidate_disk) (struct gendisk *);
int (*getgeo)(struct block_device *, struct hd_geometry *);
+ /* this callback is with swap_lock and sometimes page table lock held */
+ void (*swap_slot_free_notify) (struct block_device *, unsigned long);
struct module *owner;
};
diff --git a/mm/swapfile.c b/mm/swapfile.c
index ecb069e..f5ccc47 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -574,6 +574,7 @@ static unsigned char swap_entry_free(struct swap_info_struct *p,
/* free if no reference */
if (!usage) {
+ struct gendisk *disk = p->bdev->bd_disk;
if (offset < p->lowest_bit)
p->lowest_bit = offset;
if (offset > p->highest_bit)
@@ -583,6 +584,9 @@ static unsigned char swap_entry_free(struct swap_info_struct *p,
swap_list.next = p->type;
nr_swap_pages++;
p->inuse_pages--;
+ if ((p->flags & SWP_BLKDEV) &&
+ disk->fops->swap_slot_free_notify)
+ disk->fops->swap_slot_free_notify(p->bdev, offset);
}
return usage;
--
1.6.6.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 2/3] Add swap slot free callback to block_device_operations
2010-05-17 5:32 ` [PATCH 2/3] Add swap slot free callback to block_device_operations Nitin Gupta
@ 2010-05-17 12:01 ` Minchan Kim
2010-05-18 3:31 ` Nitin Gupta
0 siblings, 1 reply; 13+ messages in thread
From: Minchan Kim @ 2010-05-17 12:01 UTC (permalink / raw)
To: Nitin Gupta
Cc: Greg KH, Pekka Enberg, Linus Torvalds, Nigel Cunningham,
Andrew Morton, Hugh Dickins, Cyp, driverdev, linux-kernel
On Mon, May 17, 2010 at 2:32 PM, Nitin Gupta <ngupta@vflare.org> wrote:
> This callback is required when RAM based devices are used as swap disks.
> One such device is ramzswap which is used as compressed in-memory swap
> disk. For such devices, we need a callback as soon as a swap slot is no
> longer used to allow freeing memory allocated for this slot. Without this
> callback, stale data can quickly accumulate in memory defeating the whole
> purpose of such devices.
>
> Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
Looks good to me about code. so I added my review sign.
But I have some comments.
last time I said, I don't like there is a swap specific function in
block_device_operations.
It doesn't need many memory but it's not good about design sine
block_device_operations have common functions about block device.
But I don't have any good idea now where I put swap specific function.
And Linus already acked this idea. Hmm.
If there isn't any objection, I don't insist on my thought.
Nitpick :
AFAIR, Nitin introduced SWP_BLKDEV since he think access of long
pointers isn't good. ex)
S_ISBLK(swap_info_struct->swap_file->f_mapping->host->i_mode)
But now, we have to access p->bdev->bd_disk->fops->swap_slot_free_notify.
Isn't it all right?
--
Kind regards,
Minchan Kim
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/3] Add swap slot free callback to block_device_operations
2010-05-17 12:01 ` Minchan Kim
@ 2010-05-18 3:31 ` Nitin Gupta
0 siblings, 0 replies; 13+ messages in thread
From: Nitin Gupta @ 2010-05-18 3:31 UTC (permalink / raw)
To: Minchan Kim
Cc: Greg KH, Pekka Enberg, Linus Torvalds, Nigel Cunningham,
Andrew Morton, Hugh Dickins, Cyp, driverdev, linux-kernel
On 05/17/2010 05:31 PM, Minchan Kim wrote:
> On Mon, May 17, 2010 at 2:32 PM, Nitin Gupta <ngupta@vflare.org> wrote:
>> This callback is required when RAM based devices are used as swap disks.
>> One such device is ramzswap which is used as compressed in-memory swap
>> disk. For such devices, we need a callback as soon as a swap slot is no
>> longer used to allow freeing memory allocated for this slot. Without this
>> callback, stale data can quickly accumulate in memory defeating the whole
>> purpose of such devices.
>>
>> Signed-off-by: Nitin Gupta <ngupta@vflare.org>
> Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
>
> Looks good to me about code. so I added my review sign.
> But I have some comments.
>
> last time I said, I don't like there is a swap specific function in
> block_device_operations.
> It doesn't need many memory but it's not good about design sine
> block_device_operations have common functions about block device.
>
> But I don't have any good idea now where I put swap specific function.
> And Linus already acked this idea. Hmm.
>
> If there isn't any objection, I don't insist on my thought.
>
> Nitpick :
> AFAIR, Nitin introduced SWP_BLKDEV since he think access of long
> pointers isn't good. ex)
> S_ISBLK(swap_info_struct->swap_file->f_mapping->host->i_mode)
>
> But now, we have to access p->bdev->bd_disk->fops->swap_slot_free_notify.
> Isn't it all right?
>
I'm also not sure about this point but accessing yet another very long
pointer chain just to check if its a block device seems weird.
Anyways, its trivial to remove this swap flag if its later decided that
its not really needed.
Thanks,
Nitin
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 3/3] ramzswap: Handler for swap slot free callback
2010-05-17 5:32 [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend) Nitin Gupta
2010-05-17 5:32 ` [PATCH 1/3] Add flag to identify block swap devices Nitin Gupta
2010-05-17 5:32 ` [PATCH 2/3] Add swap slot free callback to block_device_operations Nitin Gupta
@ 2010-05-17 5:32 ` Nitin Gupta
2010-05-17 12:03 ` Minchan Kim
2010-05-17 6:10 ` [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend) Pekka Enberg
3 siblings, 1 reply; 13+ messages in thread
From: Nitin Gupta @ 2010-05-17 5:32 UTC (permalink / raw)
To: Greg KH
Cc: Pekka Enberg, Linus Torvalds, Nigel Cunningham, Andrew Morton,
Minchan Kim, Hugh Dickins, Cyp, driverdev, linux-kernel
Install handler for swap_slot_free_notify callback which is called
when a swap slot is no longer used. This handler immediately frees
memory allocated corresponding to the given swap slot.
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
---
drivers/staging/ramzswap/TODO | 5 -----
drivers/staging/ramzswap/ramzswap_drv.c | 22 +++++++++++++---------
2 files changed, 13 insertions(+), 14 deletions(-)
delete mode 100644 drivers/staging/ramzswap/TODO
diff --git a/drivers/staging/ramzswap/TODO b/drivers/staging/ramzswap/TODO
deleted file mode 100644
index 8d64e28..0000000
--- a/drivers/staging/ramzswap/TODO
+++ /dev/null
@@ -1,5 +0,0 @@
-TODO:
- - Add support for swap notifiers
-
-Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
-Nitin Gupta <ngupta@vflare.org>
diff --git a/drivers/staging/ramzswap/ramzswap_drv.c b/drivers/staging/ramzswap/ramzswap_drv.c
index ee5eb12..ab15276 100644
--- a/drivers/staging/ramzswap/ramzswap_drv.c
+++ b/drivers/staging/ramzswap/ramzswap_drv.c
@@ -795,14 +795,6 @@ static int ramzswap_write(struct ramzswap *rzs, struct bio *bio)
src = rzs->compress_buffer;
- /*
- * System swaps to same sector again when the stored page
- * is no longer referenced by any process. So, its now safe
- * to free the memory that was allocated for this page.
- */
- if (rzs->table[index].page || rzs_test_flag(rzs, index, RZS_ZERO))
- ramzswap_free_page(rzs, index);
-
mutex_lock(&rzs->lock);
user_mem = kmap_atomic(page, KM_USER0);
@@ -1295,9 +1287,21 @@ out:
return ret;
}
+void ramzswap_slot_free_notify(struct block_device *bdev, unsigned long index)
+{
+ struct ramzswap *rzs;
+
+ rzs = bdev->bd_disk->private_data;
+ ramzswap_free_page(rzs, index);
+ rzs_stat64_inc(rzs, &rzs->stats.notify_free);
+
+ return;
+}
+
static struct block_device_operations ramzswap_devops = {
.ioctl = ramzswap_ioctl,
- .owner = THIS_MODULE,
+ .swap_slot_free_notify = ramzswap_slot_free_notify,
+ .owner = THIS_MODULE
};
static int create_device(struct ramzswap *rzs, int device_id)
--
1.6.6.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 3/3] ramzswap: Handler for swap slot free callback
2010-05-17 5:32 ` [PATCH 3/3] ramzswap: Handler for swap slot free callback Nitin Gupta
@ 2010-05-17 12:03 ` Minchan Kim
2010-05-18 3:24 ` Nitin Gupta
0 siblings, 1 reply; 13+ messages in thread
From: Minchan Kim @ 2010-05-17 12:03 UTC (permalink / raw)
To: Nitin Gupta
Cc: Greg KH, Pekka Enberg, Linus Torvalds, Nigel Cunningham,
Andrew Morton, Hugh Dickins, Cyp, driverdev, linux-kernel
On Mon, May 17, 2010 at 2:32 PM, Nitin Gupta <ngupta@vflare.org> wrote:
> Install handler for swap_slot_free_notify callback which is called
> when a swap slot is no longer used. This handler immediately frees
> memory allocated corresponding to the given swap slot.
>
> Signed-off-by: Nitin Gupta <ngupta@vflare.org>
> ---
> drivers/staging/ramzswap/TODO | 5 -----
> drivers/staging/ramzswap/ramzswap_drv.c | 22 +++++++++++++---------
> 2 files changed, 13 insertions(+), 14 deletions(-)
> delete mode 100644 drivers/staging/ramzswap/TODO
>
> diff --git a/drivers/staging/ramzswap/TODO b/drivers/staging/ramzswap/TODO
> deleted file mode 100644
> index 8d64e28..0000000
> --- a/drivers/staging/ramzswap/TODO
> +++ /dev/null
> @@ -1,5 +0,0 @@
> -TODO:
> - - Add support for swap notifiers
> -
> -Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
> -Nitin Gupta <ngupta@vflare.org>
> diff --git a/drivers/staging/ramzswap/ramzswap_drv.c b/drivers/staging/ramzswap/ramzswap_drv.c
> index ee5eb12..ab15276 100644
> --- a/drivers/staging/ramzswap/ramzswap_drv.c
> +++ b/drivers/staging/ramzswap/ramzswap_drv.c
> @@ -795,14 +795,6 @@ static int ramzswap_write(struct ramzswap *rzs, struct bio *bio)
>
> src = rzs->compress_buffer;
>
> - /*
> - * System swaps to same sector again when the stored page
> - * is no longer referenced by any process. So, its now safe
> - * to free the memory that was allocated for this page.
> - */
> - if (rzs->table[index].page || rzs_test_flag(rzs, index, RZS_ZERO))
> - ramzswap_free_page(rzs, index);
> -
> mutex_lock(&rzs->lock);
>
> user_mem = kmap_atomic(page, KM_USER0);
> @@ -1295,9 +1287,21 @@ out:
> return ret;
> }
>
> +void ramzswap_slot_free_notify(struct block_device *bdev, unsigned long index)
> +{
> + struct ramzswap *rzs;
> +
> + rzs = bdev->bd_disk->private_data;
> + ramzswap_free_page(rzs, index);
> + rzs_stat64_inc(rzs, &rzs->stats.notify_free);
> +
> + return;
> +}
Mistake. Let's remove _return_ in void function.
Otherwise, looks good to me.
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
--
Kind regards,
Minchan Kim
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 3/3] ramzswap: Handler for swap slot free callback
2010-05-17 12:03 ` Minchan Kim
@ 2010-05-18 3:24 ` Nitin Gupta
0 siblings, 0 replies; 13+ messages in thread
From: Nitin Gupta @ 2010-05-18 3:24 UTC (permalink / raw)
To: Minchan Kim
Cc: Greg KH, Pekka Enberg, Linus Torvalds, Nigel Cunningham,
Andrew Morton, Hugh Dickins, Cyp, driverdev, linux-kernel
On 05/17/2010 05:33 PM, Minchan Kim wrote:
> On Mon, May 17, 2010 at 2:32 PM, Nitin Gupta <ngupta@vflare.org> wrote:
>> Install handler for swap_slot_free_notify callback which is called
>> when a swap slot is no longer used. This handler immediately frees
>> memory allocated corresponding to the given swap slot.
>>
>> Signed-off-by: Nitin Gupta <ngupta@vflare.org>
>> ---
>> drivers/staging/ramzswap/TODO | 5 -----
>> drivers/staging/ramzswap/ramzswap_drv.c | 22 +++++++++++++---------
>> 2 files changed, 13 insertions(+), 14 deletions(-)
>> delete mode 100644 drivers/staging/ramzswap/TODO
>>
>> diff --git a/drivers/staging/ramzswap/TODO b/drivers/staging/ramzswap/TODO
>> deleted file mode 100644
>> index 8d64e28..0000000
>> --- a/drivers/staging/ramzswap/TODO
>> +++ /dev/null
>> @@ -1,5 +0,0 @@
>> -TODO:
>> - - Add support for swap notifiers
>> -
>> -Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
>> -Nitin Gupta <ngupta@vflare.org>
>> diff --git a/drivers/staging/ramzswap/ramzswap_drv.c b/drivers/staging/ramzswap/ramzswap_drv.c
>> index ee5eb12..ab15276 100644
>> --- a/drivers/staging/ramzswap/ramzswap_drv.c
>> +++ b/drivers/staging/ramzswap/ramzswap_drv.c
>> @@ -795,14 +795,6 @@ static int ramzswap_write(struct ramzswap *rzs, struct bio *bio)
>>
>> src = rzs->compress_buffer;
>>
>> - /*
>> - * System swaps to same sector again when the stored page
>> - * is no longer referenced by any process. So, its now safe
>> - * to free the memory that was allocated for this page.
>> - */
>> - if (rzs->table[index].page || rzs_test_flag(rzs, index, RZS_ZERO))
>> - ramzswap_free_page(rzs, index);
>> -
>> mutex_lock(&rzs->lock);
>>
>> user_mem = kmap_atomic(page, KM_USER0);
>> @@ -1295,9 +1287,21 @@ out:
>> return ret;
>> }
>>
>> +void ramzswap_slot_free_notify(struct block_device *bdev, unsigned long index)
>> +{
>> + struct ramzswap *rzs;
>> +
>> + rzs = bdev->bd_disk->private_data;
>> + ramzswap_free_page(rzs, index);
>> + rzs_stat64_inc(rzs, &rzs->stats.notify_free);
>> +
>> + return;
>> +}
>
> Mistake. Let's remove _return_ in void function.
> Otherwise, looks good to me.
>
I will do this in upcoming cleanup patches.
Thanks for the review.
Nitin
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend)
2010-05-17 5:32 [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend) Nitin Gupta
` (2 preceding siblings ...)
2010-05-17 5:32 ` [PATCH 3/3] ramzswap: Handler for swap slot free callback Nitin Gupta
@ 2010-05-17 6:10 ` Pekka Enberg
2010-05-17 8:45 ` Nitin Gupta
3 siblings, 1 reply; 13+ messages in thread
From: Pekka Enberg @ 2010-05-17 6:10 UTC (permalink / raw)
To: Nitin Gupta
Cc: Greg KH, Linus Torvalds, Nigel Cunningham, Andrew Morton,
Minchan Kim, Hugh Dickins, Cyp, driverdev, linux-kernel, hughd
On Mon, May 17, 2010 at 8:32 AM, Nitin Gupta <ngupta@vflare.org> wrote:
> Resending as Greg wanted.
>
> (tested on mainline but should apply to linux-next cleanly)
>
>
> * Changelog: v2 vs initial patches
> - directly add swap free callback to block_device_operations
> instead of using 'notifiers' for various swap events.
>
> 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
> block_device_operations which is called as soon as a swap
> slot is freed.
>
> Nitin Gupta (3):
> Add flag to identify block swap devices
> Add swap slot free callback to block_device_operations
> ramzswap: Handler for swap slot free callback
>
> drivers/staging/ramzswap/TODO | 5 -----
> drivers/staging/ramzswap/ramzswap_drv.c | 22 +++++++++++++---------
> include/linux/blkdev.h | 2 ++
> include/linux/swap.h | 1 +
> mm/swapfile.c | 5 +++++
> 5 files changed, 21 insertions(+), 14 deletions(-)
> delete mode 100644 drivers/staging/ramzswap/TODO
Nitin, please retain ACKs when resending patches.
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
for the whole series.
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend)
2010-05-17 6:10 ` [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2 resend) Pekka Enberg
@ 2010-05-17 8:45 ` Nitin Gupta
0 siblings, 0 replies; 13+ messages in thread
From: Nitin Gupta @ 2010-05-17 8:45 UTC (permalink / raw)
To: Pekka Enberg
Cc: Greg KH, Linus Torvalds, Nigel Cunningham, Andrew Morton,
Minchan Kim, Hugh Dickins, Cyp, driverdev, linux-kernel, hughd
On 05/17/2010 11:40 AM, Pekka Enberg wrote:
> On Mon, May 17, 2010 at 8:32 AM, Nitin Gupta <ngupta@vflare.org> wrote:
>> Resending as Greg wanted.
>>
>> (tested on mainline but should apply to linux-next cleanly)
>>
>>
>> * Changelog: v2 vs initial patches
>> - directly add swap free callback to block_device_operations
>> instead of using 'notifiers' for various swap events.
>>
>> 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
>> block_device_operations which is called as soon as a swap
>> slot is freed.
>>
>> Nitin Gupta (3):
>> Add flag to identify block swap devices
>> Add swap slot free callback to block_device_operations
>> ramzswap: Handler for swap slot free callback
>>
>> drivers/staging/ramzswap/TODO | 5 -----
>> drivers/staging/ramzswap/ramzswap_drv.c | 22 +++++++++++++---------
>> include/linux/blkdev.h | 2 ++
>> include/linux/swap.h | 1 +
>> mm/swapfile.c | 5 +++++
>> 5 files changed, 21 insertions(+), 14 deletions(-)
>> delete mode 100644 drivers/staging/ramzswap/TODO
>
> Nitin, please retain ACKs when resending patches.
>
> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
>
> for the whole series.
Sorry, I forgot to include Ack lines. Here are the remaining Acks:
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Nigel Cunningham <nigel@tuxonice.net>
Thanks you all for reviews.
Nitin
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 3/3] ramzswap: Handler for swap slot free callback
2010-05-07 7:25 [PATCH 0/3] ramzswap: Eliminate stale data from compressed memory (v2) Nitin Gupta
@ 2010-05-07 7:25 ` Nitin Gupta
0 siblings, 0 replies; 13+ messages in thread
From: Nitin Gupta @ 2010-05-07 7:25 UTC (permalink / raw)
To: Greg KH
Cc: Linus Torvalds, Pekka Enberg, Hugh Dickins, Cyp, Minchan Kim,
Al Viro, Christoph Hellwig, Jens Axboe, Andi Kleen, Andrew Morton,
driverdev, linux-kernel
Install handler for swap_slot_free_notify callback which is called
when a swap slot is no longer used. This handler immediately frees
memory allocated corresponding to the given swap slot.
Signed-off-by: Nitin Gupta
---
drivers/staging/ramzswap/TODO | 5 -----
drivers/staging/ramzswap/ramzswap_drv.c | 22 +++++++++++++---------
2 files changed, 13 insertions(+), 14 deletions(-)
delete mode 100644 drivers/staging/ramzswap/TODO
diff --git a/drivers/staging/ramzswap/TODO b/drivers/staging/ramzswap/TODO
deleted file mode 100644
index 8d64e28..0000000
--- a/drivers/staging/ramzswap/TODO
+++ /dev/null
@@ -1,5 +0,0 @@
-TODO:
- - Add support for swap notifiers
-
-Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
-Nitin Gupta <ngupta@vflare.org>
diff --git a/drivers/staging/ramzswap/ramzswap_drv.c b/drivers/staging/ramzswap/ramzswap_drv.c
index ee5eb12..ab15276 100644
--- a/drivers/staging/ramzswap/ramzswap_drv.c
+++ b/drivers/staging/ramzswap/ramzswap_drv.c
@@ -795,14 +795,6 @@ static int ramzswap_write(struct ramzswap *rzs, struct bio *bio)
src = rzs->compress_buffer;
- /*
- * System swaps to same sector again when the stored page
- * is no longer referenced by any process. So, its now safe
- * to free the memory that was allocated for this page.
- */
- if (rzs->table[index].page || rzs_test_flag(rzs, index, RZS_ZERO))
- ramzswap_free_page(rzs, index);
-
mutex_lock(&rzs->lock);
user_mem = kmap_atomic(page, KM_USER0);
@@ -1295,9 +1287,21 @@ out:
return ret;
}
+void ramzswap_slot_free_notify(struct block_device *bdev, unsigned long index)
+{
+ struct ramzswap *rzs;
+
+ rzs = bdev->bd_disk->private_data;
+ ramzswap_free_page(rzs, index);
+ rzs_stat64_inc(rzs, &rzs->stats.notify_free);
+
+ return;
+}
+
static struct block_device_operations ramzswap_devops = {
.ioctl = ramzswap_ioctl,
- .owner = THIS_MODULE,
+ .swap_slot_free_notify = ramzswap_slot_free_notify,
+ .owner = THIS_MODULE
};
static int create_device(struct ramzswap *rzs, int device_id)
--
1.6.6.1
^ permalink raw reply related [flat|nested] 13+ messages in thread