Skip to contentSkip to conversation

zram: clear disk io accounting when reset zram device

PATCH In review Weijie Yang 3 participants 4 messages May 29, 2015 – May 30, 2015

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

PATCH 1/1 zram: clear disk io accounting when reset zram device

This patch clears zram disk io accounting when reset the zram device, if don't do this, the residual io accounting stat will affect the diskstat in the next zram active cycle.

---
 drivers/block/zram/zram_drv.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/block/zram/zram_drv.c +2 -0
index 8dcbced..6e134f4 100644
@@ -805,7 +805,9 @@ static void zram_reset_device(struct zram *zram)
 	memset(&zram->stats, 0, sizeof(zram->stats));
 	zram->disksize = 0;
 	zram->max_comp_streams = 1;
+
 	set_capacity(zram->disk, 0);
+	part_stat_set_all(&zram->disk->part0, 0);
 
 	up_write(&zram->init_lock);
 	/* I/O operation under all of CPU are done so let's free */
Signature · 8 lines
1.7.10.4


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Weijie Yang

This patch clears zram disk io accounting when reset the zram device, if don't do this, the residual io accounting stat will affect the diskstat in the next zram active cycle.

thanks. my bad.

	-ss
Quoted 23 lines
---
 drivers/block/zram/zram_drv.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/block/zram/zram_drv.c +2 -0
index 8dcbced..6e134f4 100644
@@ -805,7 +805,9 @@ static void zram_reset_device(struct zram *zram)
 	memset(&zram->stats, 0, sizeof(zram->stats));
 	zram->disksize = 0;
 	zram->max_comp_streams = 1;
+
 	set_capacity(zram->disk, 0);
+	part_stat_set_all(&zram->disk->part0, 0);
 
 	up_write(&zram->init_lock);
 	/* I/O operation under all of CPU are done so let's free */
Signature · 1 line
1.7.10.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer Acked-by
#2 lore raw

Hello guys,

Quoted 4 lines · Sergey Senozhatsky
Quoted 3 lines · Weijie Yang

This patch clears zram disk io accounting when reset the zram device, if don't do this, the residual io accounting stat will affect the diskstat in the next zram active cycle.

Thanks for the fix.

Quoted 5 lines
Quoted 1 line

thanks. my bad.

I give my acked-by because it's surely fix so there is no reason to hesitate.

In future, I hope to change it like below.

I think the problem is caused from weired feature "reset" of zram. Until a while ago, we didn't have hot_add/del feature so we should use custom reset function but now we have hot/add feature. So reset is logically same feature(ie, reset = hot_remove+hot_add but remains same device id).

If we reuse zram_remove/add for reset, finally it calls del_gendisk which will do part_stat_set_all for us so we didn't have this kinds of problems.

It needs more churns and some tweaks of zram_[remove|add] but it's more clean and consistent between reset and hot_remove.

Just my two cents.

Quoted 26 lines
	-ss
Quoted 23 lines
---
 drivers/block/zram/zram_drv.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/block/zram/zram_drv.c +2 -0
index 8dcbced..6e134f4 100644
@@ -805,7 +805,9 @@ static void zram_reset_device(struct zram *zram)
 	memset(&zram->stats, 0, sizeof(zram->stats));
 	zram->disksize = 0;
 	zram->max_comp_streams = 1;
+
 	set_capacity(zram->disk, 0);
+	part_stat_set_all(&zram->disk->part0, 0);
 
 	up_write(&zram->init_lock);
 	/* I/O operation under all of CPU are done so let's free */
Signature · 1 line
1.7.10.4
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
Quoted 1 line · Minchan Kim

I think the problem is caused from weired feature "reset" of zram.

agree.

Quoted 5 lines

Until a while ago, we didn't have hot_add/del feature so we should use custom reset function but now we have hot/add feature. So reset is logically same feature(ie, reset = hot_remove+hot_add but remains same device id).

hm, sounds interesting, but I think it will end up being tricky.

zram_remove() will be called from device's sysfs node (now we call it from zram_control sysfs class node, makes a huge difference). sysfs locks the node until node's read/write handler returns back, so zram_remove() will be called with lock(s_active#XXX) being locked (we had a lockdep splat with these locks recently), while zram_remove()->sysfs_remove_group() will once again attempt to lock this node (the very same lock(s_active#XXX)). in other words, we cannot fully remove zram device from its sysfs attr. and I don't want to add any bool flags to zram_remove() and zram_add() indicating that this is a "partial" device
remove: don't delete device's sysfs group in remove() and don't create it in add().

doing reset from zram_control is easy, for sure:
lock idr mutex,
do zram_remove() and zram_add()
unlock idr lock.

echo ID > /sys/.../zram_control/reset

no need to modify remove()/add() -- idr will pick up just released idx, so device_id will be preserved. but it'll be hard to drop the per-device reset attr and to make it a zram_control attr. things would have been much simpler if all of zram users were also zramctl users. zramctl, from this point of view, lets us change zram interfaces easily -- we merely need to teach/modify zramctl, the rest is transparent.

	-ss

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>