Re: [PATCH 3/6] zram: introduce ZRAM_IDLE flag
From: Sergey Senozhatsky
Date: Mon Nov 19 2018 - 21:47:07 EST
Hello,
On (11/16/18 16:20), Minchan Kim wrote:
[..]
> +static ssize_t idle_store(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t len)
> +{
> + struct zram *zram = dev_to_zram(dev);
> + unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
> + int index;
> +
> + down_read(&zram->init_lock);
> + if (!init_done(zram)) {
> + up_read(&zram->init_lock);
> + return -EINVAL;
> + }
> +
> + for (index = 0; index < nr_pages; index++) {
> + zram_slot_lock(zram, index);
> + if (!zram_allocated(zram, index))
> + goto next;
> +
> + zram_set_flag(zram, index, ZRAM_IDLE);
> +next:
> + zram_slot_unlock(zram, index);
> + }
> +
> + up_read(&zram->init_lock);
> +
> + return len;
> +}
This is one way of doing it.
The other one could, probabaly, be a bit more friendly to the cache
lines and CPU cycles. Basically, have a static timestamp variable,
which would keep the timestamp of last idle_store().
static idle_snapshot_ts;
static ssize_t idle_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
idle_snapshot_ts = ktime();
}
And then in read_block_state() compare handle access time and
idle_snapshot_ts (if it's not 0). If the page was not modified/access
since the last idle_snapshot_ts (handle access time <= idle_snapshot_ts),
then it's idle, otherwise (handle access time > idle_snapshot_ts) it's
not idle.
Would this do the trick?
-ss