Re: [PATCH 2/2] zram: idle memory tracking

From: Sergey Senozhatsky
Date: Mon Mar 26 2018 - 22:21:59 EST


On (03/26/18 15:49), Minchan Kim wrote:
[..]
> +static ssize_t read_access_time(struct file *file, char __user *buf,
> + size_t count, loff_t *ppos)
> +{
[..]
> +
> + for (index = *ppos; index < nr_pages; index++) {
> + zram_slot_lock(zram, index);
> + if (zram_test_flag(zram, index, ZRAM_WB))
> + goto next;

I think it'll be better to show ZRAM_WB pages as well. Those pages
are swapped out pages after all, consuming swap space - a physical
page. Freeing those should also be beneficial. So tracking "bad"
incompressible pages is quite handful.

> + if (zram_test_flag(zram, index, ZRAM_SAME))
> + goto next;
> + if (!zram_get_handle(zram, index))
> + goto next;
> +
> + ret = snprintf(kbuf + written, remained, "%lu %lu\n", index,
> + get_seconds() - zram->table[index].ac_time);

So here you can add a flag after index and age which will tell if the page
is in zsmalloc pool or on backing swap device.

> + if (remained < ret) {
> + zram_slot_unlock(zram, index);
> + break;
> + }
> + written += ret;
> + remained -= ret;
> +next:
> + zram_slot_unlock(zram, index);
> + *ppos += 1;
> + }
> +
> + up_read(&zram->init_lock);
> + copy_to_user(buf, kbuf, written);
> + kvfree(kbuf);
> +
> + return written;
> +}

-ss