aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinchan Kim <minchan@kernel.org>2018-06-07 17:05:45 -0700
committerAmit Pundir <amit.pundir@linaro.org>2018-10-04 14:16:25 +0530
commit95986f401e7a3f98753e4eed97f4db870728831f (patch)
treeebf09998f218cf447ec5f6fc25a2705985ed7277
parent5df312f29da828488f8e307774d642a4cee5bef6 (diff)
BACKPORT: zram: record accessed second
zRam as swap is useful for small memory device. However, swap means those pages on zram are mostly cold pages due to VM's LRU algorithm. Especially, once init data for application are touched for launching, they tend to be not accessed any more and finally swapped out. zRAM can store such cold pages as compressed form but it's pointless to keep in memory. Better idea is app developers free them directly rather than remaining them on heap. This patch records last access time of each block of zram so that With upcoming zram memory tracking, it could help userspace developers to reduce memory footprint. Link: http://lkml.kernel.org/r/20180416090946.63057-4-minchan@kernel.org Signed-off-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry picked from commit d7eac6b6e1838ef1a1400df4ec55daa34bbc855e) Signed-off-by: Peter Kalauskas <peskal@google.com> Bug: 112488418 Change-Id: I5b217d3cd4da57e548196658e0824d65a0cad631 Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
-rw-r--r--drivers/block/zram/zram_drv.c16
-rw-r--r--drivers/block/zram/zram_drv.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 8e74cafe9008..de4fdb599a58 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -101,6 +101,16 @@ static inline void zram_set_element(struct zram *zram, u32 index,
zram->table[index].element = element;
}
+static void zram_accessed(struct zram *zram, u32 index)
+{
+ zram->table[index].ac_time = sched_clock();
+}
+
+static void zram_reset_access(struct zram *zram, u32 index)
+{
+ zram->table[index].ac_time = 0;
+}
+
static unsigned long zram_get_element(struct zram *zram, u32 index)
{
return zram->table[index].element;
@@ -814,6 +824,8 @@ static void zram_free_page(struct zram *zram, size_t index)
{
unsigned long handle;
+ zram_reset_access(zram, index);
+
if (zram_test_flag(zram, index, ZRAM_HUGE)) {
zram_clear_flag(zram, index, ZRAM_HUGE);
atomic64_dec(&zram->stats.huge_pages);
@@ -1183,6 +1195,10 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
generic_end_io_acct(rw, &zram->disk->part0, start_time);
+ zram_slot_lock(zram, index);
+ zram_accessed(zram, index);
+ zram_slot_unlock(zram, index);
+
if (unlikely(ret < 0)) {
if (rw == READ)
atomic64_inc(&zram->stats.failed_reads);
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 4c4bc6042c89..79c73f50a2a2 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -78,6 +78,7 @@ struct zram_table_entry {
unsigned long element;
};
unsigned long value;
+ u64 ac_time;
};
struct zram_stats {