public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* Re: [PATCHv5 04/13] zram: Introduce recompress sysfs knob
       [not found] ` <20221109115047.2921851-5-senozhatsky@chromium.org>
@ 2022-11-10 13:09   ` Nathan Chancellor
  2022-11-10 14:31     ` Sergey Senozhatsky
  2022-11-10 14:34   ` [PATCH] zram: we should always zero out err variable in recompress loop Sergey Senozhatsky
  1 sibling, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2022-11-10 13:09 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Minchan Kim, Andrew Morton, Nitin Gupta, Suleiman Souhlal,
	linux-kernel, linux-mm, llvm

Hi Sergey,

On Wed, Nov 09, 2022 at 08:50:38PM +0900, Sergey Senozhatsky wrote:
> Allow zram to recompress (using secondary compression streams)
> pages.
> 
> Re-compression algorithms (we support up to 3 at this stage)
> are selected via recomp_algorithm:
> 
>   echo "algo=zstd priority=1" > /sys/block/zramX/recomp_algorithm
> 
> Please read documentation for more details.
> 
> We support several recompression modes:
> 
> 1) IDLE pages recompression is activated by `idle` mode
> 
>   echo "type=idle" > /sys/block/zram0/recompress
> 
> 2) Since there may be many idle pages user-space may pass a size
> threshold value (in bytes) and we will recompress pages only
> of equal or greater size:
> 
>   echo "threshold=888" > /sys/block/zram0/recompress
> 
> 3) HUGE pages recompression is activated by `huge` mode
> 
>   echo "type=huge" > /sys/block/zram0/recompress
> 
> 4) HUGE_IDLE pages recompression is activated by `huge_idle` mode
> 
>   echo "type=huge_idle" > /sys/block/zram0/recompress
> 
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
...
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index a6a5fd2474d7..749e4266dd72 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
...
> +	for (index = 0; index < nr_pages; index++) {
> +		int err;
> +
> +		zram_slot_lock(zram, index);
> +
> +		if (!zram_allocated(zram, index))
> +			goto next;
> +
> +		if (mode & RECOMPRESS_IDLE &&
> +		    !zram_test_flag(zram, index, ZRAM_IDLE))
> +			goto next;
> +
> +		if (mode & RECOMPRESS_HUGE &&
> +		    !zram_test_flag(zram, index, ZRAM_HUGE))
> +			goto next;
> +
> +		if (zram_test_flag(zram, index, ZRAM_WB) ||
> +		    zram_test_flag(zram, index, ZRAM_UNDER_WB) ||
> +		    zram_test_flag(zram, index, ZRAM_SAME) ||
> +		    zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE))
> +			goto next;
> +
> +		err = zram_recompress(zram, index, page, threshold,
> +				      prio, ZRAM_MAX_COMPS);
> +next:
> +		zram_slot_unlock(zram, index);
> +		if (err) {
> +			ret = err;
> +			break;
> +		}
> +
> +		cond_resched();
> +	}

This commit is now in -next as commit 03e6c729aa64 ("zram: introduce
recompress sysfs knob"), where it introduces the following clang
warnings:

drivers/block/zram/zram_drv.c:1909:7: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1919:7: note: uninitialized use occurs here
                if (err) {
                    ^~~
drivers/block/zram/zram_drv.c:1909:3: note: remove the 'if' if its condition is always false
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1909:7: error: variable 'err' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1919:7: note: uninitialized use occurs here
                if (err) {
                    ^~~
drivers/block/zram/zram_drv.c:1909:7: note: remove the '||' if its condition is always false
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1909:7: error: variable 'err' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1919:7: note: uninitialized use occurs here
                if (err) {
                    ^~~
drivers/block/zram/zram_drv.c:1909:7: note: remove the '||' if its condition is always false
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1909:7: error: variable 'err' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1919:7: note: uninitialized use occurs here
                if (err) {
                    ^~~
drivers/block/zram/zram_drv.c:1909:7: note: remove the '||' if its condition is always false
                if (zram_test_flag(zram, index, ZRAM_WB) ||
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1905:7: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (mode & RECOMPRESS_HUGE &&
                    ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1919:7: note: uninitialized use occurs here
                if (err) {
                    ^~~
drivers/block/zram/zram_drv.c:1905:3: note: remove the 'if' if its condition is always false
                if (mode & RECOMPRESS_HUGE &&
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1901:7: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (mode & RECOMPRESS_IDLE &&
                    ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1919:7: note: uninitialized use occurs here
                if (err) {
                    ^~~
drivers/block/zram/zram_drv.c:1901:3: note: remove the 'if' if its condition is always false
                if (mode & RECOMPRESS_IDLE &&
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1898:7: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                if (!zram_allocated(zram, index))
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1919:7: note: uninitialized use occurs here
                if (err) {
                    ^~~
drivers/block/zram/zram_drv.c:1898:3: note: remove the 'if' if its condition is always false
                if (!zram_allocated(zram, index))
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/zram/zram_drv.c:1894:10: note: initialize the variable 'err' to silence this warning
                int err;
                       ^
                        = 0
7 errors generated.

Is the fix just to initialize err to 0 as it suggests or should there be
a different fix?

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCHv5 04/13] zram: Introduce recompress sysfs knob
  2022-11-10 13:09   ` [PATCHv5 04/13] zram: Introduce recompress sysfs knob Nathan Chancellor
@ 2022-11-10 14:31     ` Sergey Senozhatsky
  2022-11-10 14:38       ` Sergey Senozhatsky
  0 siblings, 1 reply; 5+ messages in thread
From: Sergey Senozhatsky @ 2022-11-10 14:31 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Sergey Senozhatsky, Minchan Kim, Andrew Morton, Nitin Gupta,
	Suleiman Souhlal, linux-kernel, linux-mm, llvm

On (22/11/10 06:09), Nathan Chancellor wrote:
[..]
> drivers/block/zram/zram_drv.c:1894:10: note: initialize the variable 'err' to silence this warning
>                 int err;
>                        ^
>                         = 0
> 7 errors generated.
> 
> Is the fix just to initialize err to 0 as it suggests or should there be
> a different fix?

Yes, that's the correct fix. Thanks for catching this. We had "err = 0"
in v4 of this patch set, but it somehow didn't make it to v5.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] zram: we should always zero out err variable in recompress loop
       [not found] ` <20221109115047.2921851-5-senozhatsky@chromium.org>
  2022-11-10 13:09   ` [PATCHv5 04/13] zram: Introduce recompress sysfs knob Nathan Chancellor
@ 2022-11-10 14:34   ` Sergey Senozhatsky
  1 sibling, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2022-11-10 14:34 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Minchan Kim, Nitin Gupta, Suleiman Souhlal, linux-kernel,
	linux-mm, llvm, Sergey Senozhatsky, Nathan Chancellor

Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/block/zram/zram_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 171eccc2249d..9d33801e8ba8 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1891,7 +1891,7 @@ static ssize_t recompress_store(struct device *dev,
 
 	ret = len;
 	for (index = 0; index < nr_pages; index++) {
-		int err;
+		int err = 0;
 
 		zram_slot_lock(zram, index);
 
-- 
2.38.1.431.g37b22c650d-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCHv5 04/13] zram: Introduce recompress sysfs knob
  2022-11-10 14:31     ` Sergey Senozhatsky
@ 2022-11-10 14:38       ` Sergey Senozhatsky
  2022-11-10 15:18         ` Nathan Chancellor
  0 siblings, 1 reply; 5+ messages in thread
From: Sergey Senozhatsky @ 2022-11-10 14:38 UTC (permalink / raw)
  To: Nathan Chancellor, Andrew Morton
  Cc: Minchan Kim, Nitin Gupta, Suleiman Souhlal, linux-kernel,
	linux-mm, llvm, Sergey Senozhatsky

On (22/11/10 23:31), Sergey Senozhatsky wrote:
> On (22/11/10 06:09), Nathan Chancellor wrote:
> [..]
> > drivers/block/zram/zram_drv.c:1894:10: note: initialize the variable 'err' to silence this warning
> >                 int err;
> >                        ^
> >                         = 0
> > 7 errors generated.
> > 
> > Is the fix just to initialize err to 0 as it suggests or should there be
> > a different fix?
> 
> Yes, that's the correct fix. Thanks for catching this. We had "err = 0"
> in v4 of this patch set, but it somehow didn't make it to v5.

Nathan, I just sent a simple one-liner patch. If you don't mind,
may we ask Andrew to take it as a fixup (folded) patch?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCHv5 04/13] zram: Introduce recompress sysfs knob
  2022-11-10 14:38       ` Sergey Senozhatsky
@ 2022-11-10 15:18         ` Nathan Chancellor
  0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2022-11-10 15:18 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Andrew Morton, Minchan Kim, Nitin Gupta, Suleiman Souhlal,
	linux-kernel, linux-mm, llvm

On Thu, Nov 10, 2022 at 11:38:57PM +0900, Sergey Senozhatsky wrote:
> On (22/11/10 23:31), Sergey Senozhatsky wrote:
> > On (22/11/10 06:09), Nathan Chancellor wrote:
> > [..]
> > > drivers/block/zram/zram_drv.c:1894:10: note: initialize the variable 'err' to silence this warning
> > >                 int err;
> > >                        ^
> > >                         = 0
> > > 7 errors generated.
> > > 
> > > Is the fix just to initialize err to 0 as it suggests or should there be
> > > a different fix?
> > 
> > Yes, that's the correct fix. Thanks for catching this. We had "err = 0"
> > in v4 of this patch set, but it somehow didn't make it to v5.
> 
> Nathan, I just sent a simple one-liner patch. If you don't mind,
> may we ask Andrew to take it as a fixup (folded) patch?

Yup, sounds like a plan to me, thanks for the quick response and fix!

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-10 15:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20221109115047.2921851-1-senozhatsky@chromium.org>
     [not found] ` <20221109115047.2921851-5-senozhatsky@chromium.org>
2022-11-10 13:09   ` [PATCHv5 04/13] zram: Introduce recompress sysfs knob Nathan Chancellor
2022-11-10 14:31     ` Sergey Senozhatsky
2022-11-10 14:38       ` Sergey Senozhatsky
2022-11-10 15:18         ` Nathan Chancellor
2022-11-10 14:34   ` [PATCH] zram: we should always zero out err variable in recompress loop Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox