Skip to contentSkip to conversation

zram: do not set ZRAM_IDLE bit for idlepage writeback in writeback_store()

PATCH In review Yue Hu 2 participants 4 messages Jan 21, 2020 – Jan 23, 2020

Subsystems (2)
lore
Share & tools
lore

Yue Hu

author
#0 lore raw

PATCH 1/1 zram: do not set ZRAM_IDLE bit for idlepage writeback in writeback_store()

From: Yue Hu <[email protected]>

Currently, we will call zram_set_flag() to set ZRAM_IDLE bit even for idlepage writeback. That is pointless. Let's set it only for hugepage mode.

---
 drivers/block/zram/zram_drv.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/block/zram/zram_drv.c +7 -5
index 4285e75..eef5767 100644
@@ -689,16 +689,18 @@ static ssize_t writeback_store(struct device *dev,
 		if (mode == IDLE_WRITEBACK &&
 			  !zram_test_flag(zram, index, ZRAM_IDLE))
 			goto next;
-		if (mode == HUGE_WRITEBACK &&
-			  !zram_test_flag(zram, index, ZRAM_HUGE))
-			goto next;
+		if (mode == HUGE_WRITEBACK) {
+			if (!zram_test_flag(zram, index, ZRAM_HUGE))
+				goto next;
+			/* Need for hugepage writeback racing */
+			zram_set_flag(zram, index, ZRAM_IDLE);
+		}
+
 		/*
 		 * Clearing ZRAM_UNDER_WB is duty of caller.
 		 * IOW, zram_free_page never clear it.
 		 */
 		zram_set_flag(zram, index, ZRAM_UNDER_WB);
-		/* Need for hugepage writeback racing */
-		zram_set_flag(zram, index, ZRAM_IDLE);
 		zram_slot_unlock(zram, index);
 		if (zram_bvec_read(zram, &bvec, index, 0, NULL)) {
 			zram_slot_lock(zram, index);
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 4 lines · Yue Hu

From: Yue Hu <[email protected]>

Currently, we will call zram_set_flag() to set ZRAM_IDLE bit even for idlepage writeback. That is pointless. Let's set it only for hugepage mode.

Could you be more specific? What do you see the problem with that?

Quoted 37 lines
---
 drivers/block/zram/zram_drv.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/block/zram/zram_drv.c +7 -5
index 4285e75..eef5767 100644
@@ -689,16 +689,18 @@ static ssize_t writeback_store(struct device *dev,
 		if (mode == IDLE_WRITEBACK &&
 			  !zram_test_flag(zram, index, ZRAM_IDLE))
 			goto next;
-		if (mode == HUGE_WRITEBACK &&
-			  !zram_test_flag(zram, index, ZRAM_HUGE))
-			goto next;
+		if (mode == HUGE_WRITEBACK) {
+			if (!zram_test_flag(zram, index, ZRAM_HUGE))
+				goto next;
+			/* Need for hugepage writeback racing */
+			zram_set_flag(zram, index, ZRAM_IDLE);
+		}
+
 		/*
 		 * Clearing ZRAM_UNDER_WB is duty of caller.
 		 * IOW, zram_free_page never clear it.
 		 */
 		zram_set_flag(zram, index, ZRAM_UNDER_WB);
-		/* Need for hugepage writeback racing */
-		zram_set_flag(zram, index, ZRAM_IDLE);
 		zram_slot_unlock(zram, index);
 		if (zram_bvec_read(zram, &bvec, index, 0, NULL)) {
 			zram_slot_lock(zram, index);
Signature · 1 line
1.9.1
author
#2 lore raw
Quoted 7 lines · On Wed, 22 Jan 2020 18:23:05 -0800 Minchan Kim <[email protected]> wrote:
Quoted 4 lines · Yue Hu

From: Yue Hu <[email protected]>

Currently, we will call zram_set_flag() to set ZRAM_IDLE bit even for idlepage writeback. That is pointless. Let's set it only for hugepage mode.

Could you be more specific? What do you see the problem with that?

If current writeback mode is idle, ZRAM_IDLE bit will be check firstly for this slot. Then go to call zram_set_flag(, , ZRAM_IDLE) if it's marked as ZRAM_IDLE. So, it's duplicated setting, am i right?

Thx.

Quoted 38 lines
Quoted 38 lines
---
 drivers/block/zram/zram_drv.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/block/zram/zram_drv.c +7 -5
index 4285e75..eef5767 100644
@@ -689,16 +689,18 @@ static ssize_t writeback_store(struct device *dev,
 		if (mode == IDLE_WRITEBACK &&
 			  !zram_test_flag(zram, index, ZRAM_IDLE))
 			goto next;
-		if (mode == HUGE_WRITEBACK &&
-			  !zram_test_flag(zram, index, ZRAM_HUGE))
-			goto next;
+		if (mode == HUGE_WRITEBACK) {
+			if (!zram_test_flag(zram, index, ZRAM_HUGE))
+				goto next;
+			/* Need for hugepage writeback racing */
+			zram_set_flag(zram, index, ZRAM_IDLE);
+		}
+
 		/*
 		 * Clearing ZRAM_UNDER_WB is duty of caller.
 		 * IOW, zram_free_page never clear it.
 		 */
 		zram_set_flag(zram, index, ZRAM_UNDER_WB);
-		/* Need for hugepage writeback racing */
-		zram_set_flag(zram, index, ZRAM_IDLE);
 		zram_slot_unlock(zram, index);
 		if (zram_bvec_read(zram, &bvec, index, 0, NULL)) {
 			zram_slot_lock(zram, index);
Signature · 1 line
1.9.1
maintainer
#3 lore raw
Quoted 6 lines · Yue Hu
Quoted 3 lines · On Wed, 22 Jan 2020 18:23:05 -0800 Minchan Kim <[email protected]> wrote:
Quoted 2 lines · Yue Hu

From: Yue Hu <[email protected]>

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Currently, we will call zram_set_flag() to set ZRAM_IDLE bit even for idlepage writeback. That is pointless. Let's set it only for hugepage mode.

Could you be more specific? What do you see the problem with that?

If current writeback mode is idle, ZRAM_IDLE bit will be check firstly for this slot. Then go to call zram_set_flag(, , ZRAM_IDLE) if it's marked as ZRAM_IDLE. So, it's duplicated setting, am i right?

As I wrote down in the description, it aims for the race with hugepage writeback. Without it, there is no way to detect the slot is reallocated and marked with huge again but it's new data so zram could free the page unintentionally.