zram: use notify_free to account all free notifications
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Thu, 9 Oct 2014 22:29:57 +0000 (15:29 -0700)
committerAlex Shi <alex.shi@linaro.org>
Mon, 11 May 2015 13:24:48 +0000 (21:24 +0800)
`notify_free' device attribute accounts the number of slot free
notifications and internally represents the number of zram_free_page()
calls.  Slot free notifications are sent only when device is used as a
swap device, hence `notify_free' is used only for swap devices.  Since
f4659d8e620d08 (zram: support REQ_DISCARD) ZRAM handles yet another one
free notification (also via zram_free_page() call) -- REQ_DISCARD
requests, which are sent by a filesystem, whenever some data blocks are
discarded.  However, there is no way to know the number of notifications
in the latter case.

Use `notify_free' to account the number of pages freed by
zram_bio_discard() and zram_slot_free_notify().  Depending on usage
scenario `notify_free' represents:

 a) the number of pages freed because of slot free notifications, which is
   equal to the number of swap_slot_free_notify() calls, so there is no
   behaviour change

 b) the number of pages freed because of REQ_DISCARD notifications

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Acked-by: Jerome Marchand <jmarchan@redhat.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 015254daf1753003c19c46b90ee85a963260d270)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
 Conflicts:
Documentation/ABI/testing/sysfs-block-zram

Documentation/ABI/testing/sysfs-block-zram
drivers/block/zram/zram_drv.c

index 31db44f01936fbb1a5ac5a56a087cbc60929aed8..0c7f4f91c6b527923b0728cb7f19bd4ef67a1eac 100644 (file)
@@ -76,11 +76,14 @@ What:               /sys/block/zram<id>/notify_free
 Date:          August 2010
 Contact:       Nitin Gupta <ngupta@vflare.org>
 Description:
-               The notify_free file is read-only and specifies the number of
-               swap slot free notifications received by this device. These
-               notifications are send to a swap block device when a swap slot
-               is freed. This statistic is applicable only when this disk is
-               being used as a swap disk.
+               The notify_free file is read-only. Depending on device usage
+               scenario it may account a) the number of pages freed because
+               of swap slot free notifications or b) the number of pages freed
+               because of REQ_DISCARD requests sent by bio. The former ones
+               are sent to a swap block device when a swap slot is freed, which
+               implies that this disk is being used as a swap disk. The latter
+               ones are sent by filesystem mounted with discard option,
+               whenever some data blocks are getting discarded.
 
 What:          /sys/block/zram<id>/discard
 Date:          August 2010
index 204b7fa9d78eb35f155a7a7a7c2e1cd7b4f667e6..3503019a96722350e84d8d10592dd25d70bddf4b 100644 (file)
@@ -697,6 +697,7 @@ static void zram_bio_discard(struct zram *zram, u32 index,
                bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
                zram_free_page(zram, index);
                bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
+               atomic64_inc(&zram->stats.notify_free);
                index++;
                n -= PAGE_SIZE;
        }