Skip to contentSkip to conversation

zram: extra zram_get_element call in zram_read_from_zspool()

PATCH In review Vasily Averin 2 participants 7 messages Nov 6, 2023 – Nov 8, 2023

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

PATCH 1/1 zram: extra zram_get_element call in zram_read_from_zspool()

'element' and 'handle' are union in struct zram_table_entry.

Fixes 8e19d540d107 ("zram: extend zero pages to same element pages")
---
 drivers/block/zram/zram_drv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/zram/zram_drv.c +1 -3
index 9ac3d4e51d26..f4d342d11b81 100644
@@ -1318,12 +1318,10 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page,
 
 	handle = zram_get_handle(zram, index);
 	if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) {
-		unsigned long value;
 		void *mem;
 
-		value = handle ? zram_get_element(zram, index) : 0;
 		mem = kmap_atomic(page);
-		zram_fill_page(mem, PAGE_SIZE, value);
+		zram_fill_page(mem, PAGE_SIZE, handle);
 		kunmap_atomic(mem);
 		return 0;
 	}
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line · Vasily Averin

'element' and 'handle' are union in struct zram_table_entry.

struct zram_table_entry {
        union {
                unsigned long handle;
                unsigned long element;
        };

I do not understand the sense of this union.
From my POV it just makes it harder to check the code because an reviewer doesn't expect that the zram element can't be used together.
Can I remove this union at all and replace zram_get/set_element calls by zram_get/set_handle instead?

Thank you,
Vasily Averin

#2 lore raw
Quoted 9 lines · Vasily Averin
Quoted 1 line · Vasily Averin

'element' and 'handle' are union in struct zram_table_entry.

struct zram_table_entry {
        union {
                unsigned long handle;
                unsigned long element;
        };
Quoted 4 lines

I do not understand the sense of this union.
From my POV it just makes it harder to check the code because an reviewer doesn't expect that the zram element can't be used together.
Can I remove this union at all and replace zram_get/set_element calls by zram_get/set_handle instead?

I guess it sort of helps API-wise to distinguish zram_handle (allocated zsmalloc object handle) and zram_element (same-filled entry).

I'll leave it to Minchan to decide.

#3 lore raw
In reply to Vasily Averin
Quoted 4 lines · Vasily Averin

'element' and 'handle' are union in struct zram_table_entry.

Fixes 8e19d540d107 ("zram: extend zero pages to same element pages")

Sorry, what exactly does it fix?

[..]

Quoted 14 lines
drivers/block/zram/zram_drv.c +1 -3
@@ -1318,12 +1318,10 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page,
 
 	handle = zram_get_handle(zram, index);
 	if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) {
-		unsigned long value;
 		void *mem;
 
-		value = handle ? zram_get_element(zram, index) : 0;
 		mem = kmap_atomic(page);
-		zram_fill_page(mem, PAGE_SIZE, value);
+		zram_fill_page(mem, PAGE_SIZE, handle);
 		kunmap_atomic(mem);
 		return 0;
 	}
#4 lore raw
Quoted 7 lines · Sergey Senozhatsky
Quoted 4 lines · Vasily Averin

'element' and 'handle' are union in struct zram_table_entry.

Fixes 8e19d540d107 ("zram: extend zero pages to same element pages")

Sorry, what exactly does it fix?

It removes unneeded call of zram_get_element() and unneeded variable 'value'. zram_get_element() == zram_get_handle(), they both access the same field of the same struct zram_table_entry, no need to read it 2nd time.
'value' variable is not required, 'handle' can be used instead.

I hope this explain why element/handle union should be removed: it confuses reviewers.

Quoted 15 lines

[..]

Quoted 14 lines
drivers/block/zram/zram_drv.c +1 -3
@@ -1318,12 +1318,10 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page,
 
 	handle = zram_get_handle(zram, index);
 	if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) {
-		unsigned long value;
 		void *mem;
 
-		value = handle ? zram_get_element(zram, index) : 0;
 		mem = kmap_atomic(page);
-		zram_fill_page(mem, PAGE_SIZE, value);
+		zram_fill_page(mem, PAGE_SIZE, handle);
 		kunmap_atomic(mem);
 		return 0;
 	}
#5 lore raw
Quoted 10 lines · Vasily Averin
Quoted 7 lines · Sergey Senozhatsky
Quoted 4 lines · Vasily Averin

'element' and 'handle' are union in struct zram_table_entry.

Fixes 8e19d540d107 ("zram: extend zero pages to same element pages")

Sorry, what exactly does it fix?

It removes unneeded call of zram_get_element() and unneeded variable 'value'.

Yes, what the patch does is pretty clear. It doesn't *fix* anything per se.

Quoted 5 lines

zram_get_element() == zram_get_handle(), they both access the same field of the same struct zram_table_entry, no need to read it 2nd time.
'value' variable is not required, 'handle' can be used instead.

I hope this explain why element/handle union should be removed: it confuses reviewers.

I do not agree with "union should be removed" part.

In this particular case - using handle as the page pattern (element) is in fact quite confusing. The visual separation of handle and element is helpful.

#6 lore raw
Quoted 6 lines · Sergey Senozhatsky
Quoted 5 lines · Vasily Averin
Quoted 4 lines · Sergey Senozhatsky
Quoted 3 lines · Vasily Averin

'element' and 'handle' are union in struct zram_table_entry.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Fixes 8e19d540d107 ("zram: extend zero pages to same element pages")

Sorry, what exactly does it fix?

It removes unneeded call of zram_get_element() and unneeded variable 'value'.

Yes, what the patch does is pretty clear. It doesn't *fix* anything per se.

Ok, I'm sorry for miscommunication.
I'm agree, it is just minor cleanup.
"Fixes:" tag just here was pointed to the patch added this problem. Perhaps it was better to specify something like "Introduced-by:" tag instead.

Quoted 11 lines
Quoted 5 lines

zram_get_element() == zram_get_handle(), they both access the same field of the same struct zram_table_entry, no need to read it 2nd time.
'value' variable is not required, 'handle' can be used instead.

I hope this explain why element/handle union should be removed: it confuses reviewers.

I do not agree with "union should be removed" part.

In this particular case - using handle as the page pattern (element) is in fact quite confusing. The visual separation of handle and element is helpful.

It's at your discretion, you know better.

Thank you,
Vasily Averin