zram: extra zram_get_element call in zram_read_from_zspool()
Subsystems (2)
PATCH 1/1 zram: extra zram_get_element call in zram_read_from_zspool()
'element' and 'handle' are union in struct zram_table_entry.
--- drivers/block/zram/zram_drv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
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 ; }
Signature · 1 line
2.34.1
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
Sergey Senozhatsky
maintainerQuoted 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.
Sergey Senozhatsky
maintainerQuoted 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 ; }
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 ; }
Sergey Senozhatsky
maintainerQuoted 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 structzram_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.
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 structzram_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
handleandelementis helpful.
It's at your discretion, you know better.
Thank you,
Vasily Averin