Skip to contentSkip to conversation

zram: use notify_free to account all free notifications

PATCH New Sergey Senozhatsky 2 participants 4 messages Sep 5, 2014 – Sep 13, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zram: use notify_free to account all free notifications

Hello,

This patch change the way zram uses notify_free' stat attr. Currently, this attr accounts only swap free notifications, iow used only when zram device is a swap device. The patch preserves the existing behaviour and additionally makes notify_free' universal, so it's also used by zram to account REQ_DISCARDs when zram is not used as a swap device.

Please refer to:
https://lkml.org/lkml/2014/9/3/1115

Please revert 2cbf6f7bea1048ab5 (zram: add num_{discard_req, discarded} for discard stat) and apply this patch.

Sergey Senozhatsky (1):
zram: use notify_free to account all free notifications

 Documentation/ABI/testing/sysfs-block-zram | 13 ++++++++-----
 drivers/block/zram/zram_drv.c              |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.1.0.134.gb1ae451
#1 lore raw

PATCH 1/1 zram: use notify_free to account all free notifications

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 in zram_free_page(), instead of accounting only swap_slot_free_notify() calls (each zram_slot_free_notify() call frees one page).

This means that 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

---
 Documentation/ABI/testing/sysfs-block-zram | 13 ++++++++-----
 drivers/block/zram/zram_drv.c              |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-block-zram +8 -5
index b13dc99..a6148ea 100644
@@ -77,11 +77,14 @@ What:		/sys/block/zram<id>/notify_free
 Date:		August 2010
 Contact:	Nitin Gupta <[email protected]>
 Description:
-		The notify_free file is read-only and specifies the number of
-		swap slot free notifications received by this device. These
-		notifications are sent 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>/zero_pages
 Date:		August 2010
drivers/block/zram/zram_drv.c +1 -1
index d78b245..bc20fe1 100644
@@ -410,6 +410,7 @@ static void zram_free_page(struct zram *zram, size_t index)
 	atomic64_sub(zram_get_obj_size(meta, index),
 			&zram->stats.compr_data_size);
 	atomic64_dec(&zram->stats.pages_stored);
+	atomic64_inc(&zram->stats.notify_free);
 
 	meta->table[index].handle = 0;
 	zram_set_obj_size(meta, index, 0);
@@ -938,7 +939,6 @@ static void zram_slot_free_notify(struct block_device *bdev,
 	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);
 }
 
 static const struct block_device_operations zram_devops = {
Signature · 1 line
2.1.0.134.gb1ae451
maintainer
#2 lore raw

Hey Sergey,

Sorry for late review.

Quoted 55 lines · Sergey Senozhatsky

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 in zram_free_page(), instead of accounting only swap_slot_free_notify() calls (each zram_slot_free_notify() call frees one page).

This means that 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

---
 Documentation/ABI/testing/sysfs-block-zram | 13 ++++++++-----
 drivers/block/zram/zram_drv.c              |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-block-zram +8 -5
index b13dc99..a6148ea 100644
@@ -77,11 +77,14 @@ What:		/sys/block/zram<id>/notify_free
 Date:		August 2010
 Contact:	Nitin Gupta <[email protected]>
 Description:
-		The notify_free file is read-only and specifies the number of
-		swap slot free notifications received by this device. These
-		notifications are sent 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>/zero_pages
 Date:		August 2010
drivers/block/zram/zram_drv.c +0 -0
index d78b245..bc20fe1 100644

drivers/block/zram/zram_drv.c static void zram_free_page(struct zram *zram, size_t index) · line 413

Quoted 4 lines
drivers/block/zram/zram_drv.c +1 -0
@@ -410,6 +410,7 @@ static void zram_free_page(struct zram *zram, size_t index)
 	atomic64_sub(zram_get_obj_size(meta, index),
 			&zram->stats.compr_data_size);
 	atomic64_dec(&zram->stats.pages_stored);
+	atomic64_inc(&zram->stats.notify_free);

It is wrong. The zram_free_page is called at several places and they are all not notify free.
Pz, account it in zram_slot_free_notify and zram_bio_discard.

Quoted 19 lines
drivers/block/zram/zram_drv.c +0 -1
 	meta->table[index].handle = 0;
 	zram_set_obj_size(meta, index, 0);
@@ -938,7 +939,6 @@ static void zram_slot_free_notify(struct block_device *bdev,
 	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);
 }
 
 static const struct block_device_operations zram_devops = {
Signature · 7 lines
2.1.0.134.gb1ae451

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 2 lines
Kind regards,
Minchan Kim
#3 lore raw

Hello Minchan,

Quoted 53 lines · Minchan Kim

Hey Sergey,

Sorry for late review.

Quoted 48 lines · Sergey Senozhatsky

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 in zram_free_page(), instead of accounting only swap_slot_free_notify() calls (each zram_slot_free_notify() call frees one page).

This means that 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

---
 Documentation/ABI/testing/sysfs-block-zram | 13 ++++++++-----
 drivers/block/zram/zram_drv.c              |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-block-zram +8 -5
index b13dc99..a6148ea 100644
@@ -77,11 +77,14 @@ What:		/sys/block/zram<id>/notify_free
 Date:		August 2010
 Contact:	Nitin Gupta <[email protected]>
 Description:
-		The notify_free file is read-only and specifies the number of
-		swap slot free notifications received by this device. These
-		notifications are sent 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.
 
Quoted 15 lines

drivers/block/zram/zram_drv.c static void zram_free_page(struct zram *zram, size_t index) · line 413

Quoted 11 lines
Documentation/ABI/testing/sysfs-block-zram +0 -0
 What:		/sys/block/zram<id>/zero_pages
 Date:		August 2010
drivers/block/zram/zram_drv.c +1 -0
index d78b245..bc20fe1 100644
@@ -410,6 +410,7 @@ static void zram_free_page(struct zram *zram, size_t index)
 	atomic64_sub(zram_get_obj_size(meta, index),
 			&zram->stats.compr_data_size);
 	atomic64_dec(&zram->stats.pages_stored);
+	atomic64_inc(&zram->stats.notify_free);

It is wrong. The zram_free_page is called at several places and they are all not notify free.
Pz, account it in zram_slot_free_notify and zram_bio_discard.

wow, why did I do that... good catch!
will resend shortly.
sorry.

	-ss
Quoted 24 lines
Quoted 19 lines
drivers/block/zram/zram_drv.c +0 -1
 	meta->table[index].handle = 0;
 	zram_set_obj_size(meta, index, 0);
@@ -938,7 +939,6 @@ static void zram_slot_free_notify(struct block_device *bdev,
 	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);
 }
 
 static const struct block_device_operations zram_devops = {
Signature · 7 lines
2.1.0.134.gb1ae451

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 2 lines
Kind regards,
Minchan Kim