summaryrefslogtreecommitdiffstats
path: root/drivers/block/zram
diff options
context:
space:
mode:
authorMinchan Kim <minchan@kernel.org>2018-12-28 03:36:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-12-28 15:11:49 -0500
commite82592c4fd7eafe8dec12a70436e93e3afb28556 (patch)
tree89d470bbfcb0f97e7f3ed3f1516d038403992078 /drivers/block/zram
parent7e5292831b346bacb05558ca385cae366187314c (diff)
zram: introduce ZRAM_IDLE flag
To support idle page writeback with upcoming patches, this patch introduces a new ZRAM_IDLE flag. Userspace can mark zram slots as "idle" via "echo all > /sys/block/zramX/idle" which marks every allocated zram slot as ZRAM_IDLE. User could see it by /sys/kernel/debug/zram/zram0/block_state. 300 75.033841 ...i 301 63.806904 s..i 302 63.806919 ..hi Once there is IO for the slot, the mark will be disappeared. 300 75.033841 ... 301 63.806904 s..i 302 63.806919 ..hi Therefore, 300th block is idle zpage. With this feature, user can how many zram has idle pages which are waste of memory. Link: http://lkml.kernel.org/r/20181127055429.251614-5-minchan@kernel.org Signed-off-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Reviewed-by: Joey Pabalinas <joeypabalinas@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram')
-rw-r--r--drivers/block/zram/zram_drv.c57
-rw-r--r--drivers/block/zram/zram_drv.h1
2 files changed, 55 insertions, 3 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 4457d0395bfb..180613b478a6 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -281,6 +281,47 @@ static ssize_t mem_used_max_store(struct device *dev,
281 return len; 281 return len;
282} 282}
283 283
284static ssize_t idle_store(struct device *dev,
285 struct device_attribute *attr, const char *buf, size_t len)
286{
287 struct zram *zram = dev_to_zram(dev);
288 unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
289 int index;
290 char mode_buf[8];
291 ssize_t sz;
292
293 sz = strscpy(mode_buf, buf, sizeof(mode_buf));
294 if (sz <= 0)
295 return -EINVAL;
296
297 /* ignore trailing new line */
298 if (mode_buf[sz - 1] == '\n')
299 mode_buf[sz - 1] = 0x00;
300
301 if (strcmp(mode_buf, "all"))
302 return -EINVAL;
303
304 down_read(&zram->init_lock);
305 if (!init_done(zram)) {
306 up_read(&zram->init_lock);
307 return -EINVAL;
308 }
309
310 for (index = 0; index < nr_pages; index++) {
311 zram_slot_lock(zram, index);
312 if (!zram_allocated(zram, index))
313 goto next;
314
315 zram_set_flag(zram, index, ZRAM_IDLE);
316next:
317 zram_slot_unlock(zram, index);
318 }
319
320 up_read(&zram->init_lock);
321
322 return len;
323}
324
284#ifdef CONFIG_ZRAM_WRITEBACK 325#ifdef CONFIG_ZRAM_WRITEBACK
285static void reset_bdev(struct zram *zram) 326static void reset_bdev(struct zram *zram)
286{ 327{
@@ -638,6 +679,7 @@ static void zram_debugfs_destroy(void)
638 679
639static void zram_accessed(struct zram *zram, u32 index) 680static void zram_accessed(struct zram *zram, u32 index)
640{ 681{
682 zram_clear_flag(zram, index, ZRAM_IDLE);
641 zram->table[index].ac_time = ktime_get_boottime(); 683 zram->table[index].ac_time = ktime_get_boottime();
642} 684}
643 685
@@ -670,12 +712,13 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
670 712
671 ts = ktime_to_timespec64(zram->table[index].ac_time); 713 ts = ktime_to_timespec64(zram->table[index].ac_time);
672 copied = snprintf(kbuf + written, count, 714 copied = snprintf(kbuf + written, count,
673 "%12zd %12lld.%06lu %c%c%c\n", 715 "%12zd %12lld.%06lu %c%c%c%c\n",
674 index, (s64)ts.tv_sec, 716 index, (s64)ts.tv_sec,
675 ts.tv_nsec / NSEC_PER_USEC, 717 ts.tv_nsec / NSEC_PER_USEC,
676 zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.', 718 zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.',
677 zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.', 719 zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.',
678 zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.'); 720 zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.',
721 zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.');
679 722
680 if (count < copied) { 723 if (count < copied) {
681 zram_slot_unlock(zram, index); 724 zram_slot_unlock(zram, index);
@@ -720,7 +763,10 @@ static void zram_debugfs_unregister(struct zram *zram)
720#else 763#else
721static void zram_debugfs_create(void) {}; 764static void zram_debugfs_create(void) {};
722static void zram_debugfs_destroy(void) {}; 765static void zram_debugfs_destroy(void) {};
723static void zram_accessed(struct zram *zram, u32 index) {}; 766static void zram_accessed(struct zram *zram, u32 index)
767{
768 zram_clear_flag(zram, index, ZRAM_IDLE);
769};
724static void zram_debugfs_register(struct zram *zram) {}; 770static void zram_debugfs_register(struct zram *zram) {};
725static void zram_debugfs_unregister(struct zram *zram) {}; 771static void zram_debugfs_unregister(struct zram *zram) {};
726#endif 772#endif
@@ -924,6 +970,9 @@ static void zram_free_page(struct zram *zram, size_t index)
924#ifdef CONFIG_ZRAM_MEMORY_TRACKING 970#ifdef CONFIG_ZRAM_MEMORY_TRACKING
925 zram->table[index].ac_time = 0; 971 zram->table[index].ac_time = 0;
926#endif 972#endif
973 if (zram_test_flag(zram, index, ZRAM_IDLE))
974 zram_clear_flag(zram, index, ZRAM_IDLE);
975
927 if (zram_test_flag(zram, index, ZRAM_HUGE)) { 976 if (zram_test_flag(zram, index, ZRAM_HUGE)) {
928 zram_clear_flag(zram, index, ZRAM_HUGE); 977 zram_clear_flag(zram, index, ZRAM_HUGE);
929 atomic64_dec(&zram->stats.huge_pages); 978 atomic64_dec(&zram->stats.huge_pages);
@@ -1589,6 +1638,7 @@ static DEVICE_ATTR_RO(initstate);
1589static DEVICE_ATTR_WO(reset); 1638static DEVICE_ATTR_WO(reset);
1590static DEVICE_ATTR_WO(mem_limit); 1639static DEVICE_ATTR_WO(mem_limit);
1591static DEVICE_ATTR_WO(mem_used_max); 1640static DEVICE_ATTR_WO(mem_used_max);
1641static DEVICE_ATTR_WO(idle);
1592static DEVICE_ATTR_RW(max_comp_streams); 1642static DEVICE_ATTR_RW(max_comp_streams);
1593static DEVICE_ATTR_RW(comp_algorithm); 1643static DEVICE_ATTR_RW(comp_algorithm);
1594#ifdef CONFIG_ZRAM_WRITEBACK 1644#ifdef CONFIG_ZRAM_WRITEBACK
@@ -1602,6 +1652,7 @@ static struct attribute *zram_disk_attrs[] = {
1602 &dev_attr_compact.attr, 1652 &dev_attr_compact.attr,
1603 &dev_attr_mem_limit.attr, 1653 &dev_attr_mem_limit.attr,
1604 &dev_attr_mem_used_max.attr, 1654 &dev_attr_mem_used_max.attr,
1655 &dev_attr_idle.attr,
1605 &dev_attr_max_comp_streams.attr, 1656 &dev_attr_max_comp_streams.attr,
1606 &dev_attr_comp_algorithm.attr, 1657 &dev_attr_comp_algorithm.attr,
1607#ifdef CONFIG_ZRAM_WRITEBACK 1658#ifdef CONFIG_ZRAM_WRITEBACK
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 4f83f1f14b0a..a84611b97867 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -48,6 +48,7 @@ enum zram_pageflags {
48 ZRAM_SAME, /* Page consists the same element */ 48 ZRAM_SAME, /* Page consists the same element */
49 ZRAM_WB, /* page is stored on backing_device */ 49 ZRAM_WB, /* page is stored on backing_device */
50 ZRAM_HUGE, /* Incompressible page */ 50 ZRAM_HUGE, /* Incompressible page */
51 ZRAM_IDLE, /* not accessed page since last idle marking */
51 52
52 __NR_ZRAM_PAGEFLAGS, 53 __NR_ZRAM_PAGEFLAGS,
53}; 54};