aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorMinchan Kim <minchan@kernel.org>2015-04-15 19:15:36 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-15 19:35:21 -0400
commit4e3ba87845420e0bfa21e6c4f7f81897aed38f8c (patch)
treeb0eeb240f26c4edee1e298fe2ed384fb8ca0c6f4 /drivers/block
parentd3d07c92ff69f784bb8c3279fa87678bfa2f7f6f (diff)
zram: support compaction
Now that zsmalloc supports compaction, zram can use it. For the first step, this patch exports compact knob via sysfs so user can do compaction via "echo 1 > /sys/block/zram0/compact". Signed-off-by: Minchan Kim <minchan@kernel.org> Cc: Juneho Choi <juno.choi@lge.com> Cc: Gunho Lee <gunho.lee@lge.com> Cc: Luigi Semenzato <semenzato@google.com> Cc: Dan Streetman <ddstreet@ieee.org> Cc: Seth Jennings <sjennings@variantweb.net> Cc: Nitin Gupta <ngupta@vflare.org> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/zram/zram_drv.c25
-rw-r--r--drivers/block/zram/zram_drv.h1
2 files changed, 26 insertions, 0 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 871bd3550cb0..1626961fdb2f 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -63,6 +63,27 @@ static inline struct zram *dev_to_zram(struct device *dev)
63 return (struct zram *)dev_to_disk(dev)->private_data; 63 return (struct zram *)dev_to_disk(dev)->private_data;
64} 64}
65 65
66static ssize_t compact_store(struct device *dev,
67 struct device_attribute *attr, const char *buf, size_t len)
68{
69 unsigned long nr_migrated;
70 struct zram *zram = dev_to_zram(dev);
71 struct zram_meta *meta;
72
73 down_read(&zram->init_lock);
74 if (!init_done(zram)) {
75 up_read(&zram->init_lock);
76 return -EINVAL;
77 }
78
79 meta = zram->meta;
80 nr_migrated = zs_compact(meta->mem_pool);
81 atomic64_add(nr_migrated, &zram->stats.num_migrated);
82 up_read(&zram->init_lock);
83
84 return len;
85}
86
66static ssize_t disksize_show(struct device *dev, 87static ssize_t disksize_show(struct device *dev,
67 struct device_attribute *attr, char *buf) 88 struct device_attribute *attr, char *buf)
68{ 89{
@@ -1017,6 +1038,7 @@ static const struct block_device_operations zram_devops = {
1017 .owner = THIS_MODULE 1038 .owner = THIS_MODULE
1018}; 1039};
1019 1040
1041static DEVICE_ATTR_WO(compact);
1020static DEVICE_ATTR_RW(disksize); 1042static DEVICE_ATTR_RW(disksize);
1021static DEVICE_ATTR_RO(initstate); 1043static DEVICE_ATTR_RO(initstate);
1022static DEVICE_ATTR_WO(reset); 1044static DEVICE_ATTR_WO(reset);
@@ -1035,6 +1057,7 @@ ZRAM_ATTR_RO(invalid_io);
1035ZRAM_ATTR_RO(notify_free); 1057ZRAM_ATTR_RO(notify_free);
1036ZRAM_ATTR_RO(zero_pages); 1058ZRAM_ATTR_RO(zero_pages);
1037ZRAM_ATTR_RO(compr_data_size); 1059ZRAM_ATTR_RO(compr_data_size);
1060ZRAM_ATTR_RO(num_migrated);
1038 1061
1039static struct attribute *zram_disk_attrs[] = { 1062static struct attribute *zram_disk_attrs[] = {
1040 &dev_attr_disksize.attr, 1063 &dev_attr_disksize.attr,
@@ -1044,6 +1067,8 @@ static struct attribute *zram_disk_attrs[] = {
1044 &dev_attr_num_writes.attr, 1067 &dev_attr_num_writes.attr,
1045 &dev_attr_failed_reads.attr, 1068 &dev_attr_failed_reads.attr,
1046 &dev_attr_failed_writes.attr, 1069 &dev_attr_failed_writes.attr,
1070 &dev_attr_num_migrated.attr,
1071 &dev_attr_compact.attr,
1047 &dev_attr_invalid_io.attr, 1072 &dev_attr_invalid_io.attr,
1048 &dev_attr_notify_free.attr, 1073 &dev_attr_notify_free.attr,
1049 &dev_attr_zero_pages.attr, 1074 &dev_attr_zero_pages.attr,
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 17056e589146..570c598f4ce9 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -84,6 +84,7 @@ struct zram_stats {
84 atomic64_t compr_data_size; /* compressed size of pages stored */ 84 atomic64_t compr_data_size; /* compressed size of pages stored */
85 atomic64_t num_reads; /* failed + successful */ 85 atomic64_t num_reads; /* failed + successful */
86 atomic64_t num_writes; /* --do-- */ 86 atomic64_t num_writes; /* --do-- */
87 atomic64_t num_migrated; /* no. of migrated object */
87 atomic64_t failed_reads; /* can happen when memory is too low */ 88 atomic64_t failed_reads; /* can happen when memory is too low */
88 atomic64_t failed_writes; /* can happen when memory is too low */ 89 atomic64_t failed_writes; /* can happen when memory is too low */
89 atomic64_t invalid_io; /* non-page-aligned I/O requests */ 90 atomic64_t invalid_io; /* non-page-aligned I/O requests */