From: Minchan Kim <minchan@kernel.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hugh Dickins <hughd@google.com>, Shaohua Li <shli@kernel.org>, Jerome Marchand <jmarchan@redhat.com>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Dan Streetman <ddstreet@ieee.org>, Nitin Gupta <ngupta@vflare.org>, Luigi Semenzato <semenzato@google.com>, Minchan Kim <minchan@kernel.org> Subject: [RFC 1/3] zram: generalize swap_slot_free_notify Date: Thu, 4 Sep 2014 10:39:44 +0900 [thread overview] Message-ID: <1409794786-10951-2-git-send-email-minchan@kernel.org> (raw) In-Reply-To: <1409794786-10951-1-git-send-email-minchan@kernel.org> Currently, swap_slot_free_notify is used for zram to free duplicated copy page for memory efficiency when it knows there is no reference to the swap slot. Let's extend it to be able to use it for other purpose so this patch generalizes it so that zram can get more hints from VM. Signed-off-by: Minchan Kim <minchan@kernel.org> --- Documentation/filesystems/Locking | 7 ++----- drivers/block/zram/zram_drv.c | 18 ++++++++++++++++-- include/linux/blkdev.h | 7 +++++-- mm/page_io.c | 7 ++++--- mm/swapfile.c | 7 ++++--- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index f1997e9da61f..e7133874fd75 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking @@ -405,7 +405,7 @@ prototypes: void (*unlock_native_capacity) (struct gendisk *); int (*revalidate_disk) (struct gendisk *); int (*getgeo)(struct block_device *, struct hd_geometry *); - void (*swap_slot_free_notify) (struct block_device *, unsigned long); + int (*swap_hint) (struct block_device *, unsigned int, void *); locking rules: bd_mutex @@ -418,14 +418,11 @@ media_changed: no unlock_native_capacity: no revalidate_disk: no getgeo: no -swap_slot_free_notify: no (see below) +swap_hint: no media_changed, unlock_native_capacity and revalidate_disk are called only from check_disk_change(). -swap_slot_free_notify is called with swap_lock and sometimes the page lock -held. - --------------------------- file_operations ------------------------------- prototypes: diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index be88d750b112..88661d62e46a 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -933,7 +933,8 @@ error: bio_io_error(bio); } -static void zram_slot_free_notify(struct block_device *bdev, +/* this callback is with swap_lock and sometimes page table lock held */ +static int zram_slot_free_notify(struct block_device *bdev, unsigned long index) { struct zram *zram; @@ -946,10 +947,23 @@ static void zram_slot_free_notify(struct block_device *bdev, zram_free_page(zram, index); bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value); atomic64_inc(&zram->stats.notify_free); + + return 0; +} + +static int zram_swap_hint(struct block_device *bdev, + unsigned int hint, void *arg) +{ + int ret = -EINVAL; + + if (hint == SWAP_SLOT_FREE) + ret = zram_slot_free_notify(bdev, (unsigned long)arg); + + return ret; } static const struct block_device_operations zram_devops = { - .swap_slot_free_notify = zram_slot_free_notify, + .swap_hint = zram_swap_hint, .owner = THIS_MODULE }; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 518b46555b80..17437b2c18e4 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1609,6 +1609,10 @@ static inline bool blk_integrity_is_initialized(struct gendisk *g) #endif /* CONFIG_BLK_DEV_INTEGRITY */ +enum swap_blk_hint { + SWAP_SLOT_FREE, +}; + struct block_device_operations { int (*open) (struct block_device *, fmode_t); void (*release) (struct gendisk *, fmode_t); @@ -1624,8 +1628,7 @@ struct block_device_operations { void (*unlock_native_capacity) (struct gendisk *); 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); + int (*swap_hint)(struct block_device *, unsigned int, void *); struct module *owner; }; diff --git a/mm/page_io.c b/mm/page_io.c index 955db8b0d497..88a13d74c621 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -114,7 +114,7 @@ void end_swap_bio_read(struct bio *bio, int err) * we again wish to reclaim it. */ struct gendisk *disk = sis->bdev->bd_disk; - if (disk->fops->swap_slot_free_notify) { + if (disk->fops->swap_hint) { swp_entry_t entry; unsigned long offset; @@ -122,8 +122,9 @@ void end_swap_bio_read(struct bio *bio, int err) offset = swp_offset(entry); SetPageDirty(page); - disk->fops->swap_slot_free_notify(sis->bdev, - offset); + disk->fops->swap_hint(sis->bdev, + SWAP_SLOT_FREE, + (void *)offset); } } } diff --git a/mm/swapfile.c b/mm/swapfile.c index 8798b2e0ac59..4bff521e649a 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -816,9 +816,10 @@ static unsigned char swap_entry_free(struct swap_info_struct *p, frontswap_invalidate_page(p->type, offset); if (p->flags & SWP_BLKDEV) { struct gendisk *disk = p->bdev->bd_disk; - if (disk->fops->swap_slot_free_notify) - disk->fops->swap_slot_free_notify(p->bdev, - offset); + if (disk->fops->swap_hint) + disk->fops->swap_hint(p->bdev, + SWAP_SLOT_FREE, + (void *)offset); } } -- 2.0.0
WARNING: multiple messages have this Message-ID (diff)
From: Minchan Kim <minchan@kernel.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hugh Dickins <hughd@google.com>, Shaohua Li <shli@kernel.org>, Jerome Marchand <jmarchan@redhat.com>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Dan Streetman <ddstreet@ieee.org>, Nitin Gupta <ngupta@vflare.org>, Luigi Semenzato <semenzato@google.com>, Minchan Kim <minchan@kernel.org> Subject: [RFC 1/3] zram: generalize swap_slot_free_notify Date: Thu, 4 Sep 2014 10:39:44 +0900 [thread overview] Message-ID: <1409794786-10951-2-git-send-email-minchan@kernel.org> (raw) In-Reply-To: <1409794786-10951-1-git-send-email-minchan@kernel.org> Currently, swap_slot_free_notify is used for zram to free duplicated copy page for memory efficiency when it knows there is no reference to the swap slot. Let's extend it to be able to use it for other purpose so this patch generalizes it so that zram can get more hints from VM. Signed-off-by: Minchan Kim <minchan@kernel.org> --- Documentation/filesystems/Locking | 7 ++----- drivers/block/zram/zram_drv.c | 18 ++++++++++++++++-- include/linux/blkdev.h | 7 +++++-- mm/page_io.c | 7 ++++--- mm/swapfile.c | 7 ++++--- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index f1997e9da61f..e7133874fd75 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking @@ -405,7 +405,7 @@ prototypes: void (*unlock_native_capacity) (struct gendisk *); int (*revalidate_disk) (struct gendisk *); int (*getgeo)(struct block_device *, struct hd_geometry *); - void (*swap_slot_free_notify) (struct block_device *, unsigned long); + int (*swap_hint) (struct block_device *, unsigned int, void *); locking rules: bd_mutex @@ -418,14 +418,11 @@ media_changed: no unlock_native_capacity: no revalidate_disk: no getgeo: no -swap_slot_free_notify: no (see below) +swap_hint: no media_changed, unlock_native_capacity and revalidate_disk are called only from check_disk_change(). -swap_slot_free_notify is called with swap_lock and sometimes the page lock -held. - --------------------------- file_operations ------------------------------- prototypes: diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index be88d750b112..88661d62e46a 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -933,7 +933,8 @@ error: bio_io_error(bio); } -static void zram_slot_free_notify(struct block_device *bdev, +/* this callback is with swap_lock and sometimes page table lock held */ +static int zram_slot_free_notify(struct block_device *bdev, unsigned long index) { struct zram *zram; @@ -946,10 +947,23 @@ static void zram_slot_free_notify(struct block_device *bdev, zram_free_page(zram, index); bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value); atomic64_inc(&zram->stats.notify_free); + + return 0; +} + +static int zram_swap_hint(struct block_device *bdev, + unsigned int hint, void *arg) +{ + int ret = -EINVAL; + + if (hint == SWAP_SLOT_FREE) + ret = zram_slot_free_notify(bdev, (unsigned long)arg); + + return ret; } static const struct block_device_operations zram_devops = { - .swap_slot_free_notify = zram_slot_free_notify, + .swap_hint = zram_swap_hint, .owner = THIS_MODULE }; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 518b46555b80..17437b2c18e4 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1609,6 +1609,10 @@ static inline bool blk_integrity_is_initialized(struct gendisk *g) #endif /* CONFIG_BLK_DEV_INTEGRITY */ +enum swap_blk_hint { + SWAP_SLOT_FREE, +}; + struct block_device_operations { int (*open) (struct block_device *, fmode_t); void (*release) (struct gendisk *, fmode_t); @@ -1624,8 +1628,7 @@ struct block_device_operations { void (*unlock_native_capacity) (struct gendisk *); 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); + int (*swap_hint)(struct block_device *, unsigned int, void *); struct module *owner; }; diff --git a/mm/page_io.c b/mm/page_io.c index 955db8b0d497..88a13d74c621 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -114,7 +114,7 @@ void end_swap_bio_read(struct bio *bio, int err) * we again wish to reclaim it. */ struct gendisk *disk = sis->bdev->bd_disk; - if (disk->fops->swap_slot_free_notify) { + if (disk->fops->swap_hint) { swp_entry_t entry; unsigned long offset; @@ -122,8 +122,9 @@ void end_swap_bio_read(struct bio *bio, int err) offset = swp_offset(entry); SetPageDirty(page); - disk->fops->swap_slot_free_notify(sis->bdev, - offset); + disk->fops->swap_hint(sis->bdev, + SWAP_SLOT_FREE, + (void *)offset); } } } diff --git a/mm/swapfile.c b/mm/swapfile.c index 8798b2e0ac59..4bff521e649a 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -816,9 +816,10 @@ static unsigned char swap_entry_free(struct swap_info_struct *p, frontswap_invalidate_page(p->type, offset); if (p->flags & SWP_BLKDEV) { struct gendisk *disk = p->bdev->bd_disk; - if (disk->fops->swap_slot_free_notify) - disk->fops->swap_slot_free_notify(p->bdev, - offset); + if (disk->fops->swap_hint) + disk->fops->swap_hint(p->bdev, + SWAP_SLOT_FREE, + (void *)offset); } } -- 2.0.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-09-04 1:39 UTC|newest] Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-09-04 1:39 [RFC 0/3] make vm aware of zram-swap Minchan Kim 2014-09-04 1:39 ` Minchan Kim 2014-09-04 1:39 ` Minchan Kim [this message] 2014-09-04 1:39 ` [RFC 1/3] zram: generalize swap_slot_free_notify Minchan Kim 2014-09-04 1:39 ` [RFC 2/3] mm: add swap_get_free hint for zram Minchan Kim 2014-09-04 1:39 ` Minchan Kim 2014-09-13 19:01 ` Dan Streetman 2014-09-13 19:01 ` Dan Streetman 2014-09-15 0:30 ` Minchan Kim 2014-09-15 0:30 ` Minchan Kim 2014-09-15 14:53 ` Dan Streetman 2014-09-15 14:53 ` Dan Streetman 2014-09-16 0:33 ` Minchan Kim 2014-09-16 0:33 ` Minchan Kim 2014-09-16 15:09 ` Dan Streetman 2014-09-16 15:09 ` Dan Streetman 2014-09-17 7:14 ` Minchan Kim 2014-09-17 7:14 ` Minchan Kim 2014-09-04 1:39 ` [RFC 3/3] zram: add swap_get_free hint Minchan Kim 2014-09-04 1:39 ` Minchan Kim 2014-09-04 6:26 ` Heesub Shin 2014-09-04 6:26 ` Heesub Shin 2014-09-04 23:59 ` Minchan Kim 2014-09-04 23:59 ` Minchan Kim 2014-09-13 19:39 ` Dan Streetman 2014-09-13 19:39 ` Dan Streetman 2014-09-15 0:57 ` Minchan Kim 2014-09-15 0:57 ` Minchan Kim 2014-09-15 16:00 ` Dan Streetman 2014-09-15 16:00 ` Dan Streetman 2014-09-16 1:21 ` Minchan Kim 2014-09-16 1:21 ` Minchan Kim 2014-09-16 15:58 ` Dan Streetman 2014-09-16 15:58 ` Dan Streetman 2014-09-17 7:44 ` Minchan Kim 2014-09-17 7:44 ` Minchan Kim 2014-09-17 16:28 ` Dan Streetman 2014-09-17 16:28 ` Dan Streetman 2014-09-19 6:14 ` Minchan Kim 2014-09-19 6:14 ` Minchan Kim
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1409794786-10951-2-git-send-email-minchan@kernel.org \ --to=minchan@kernel.org \ --cc=akpm@linux-foundation.org \ --cc=ddstreet@ieee.org \ --cc=hughd@google.com \ --cc=jmarchan@redhat.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=ngupta@vflare.org \ --cc=semenzato@google.com \ --cc=sergey.senozhatsky@gmail.com \ --cc=shli@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.