Re: [PATCHv4 4/9] zram: Introduce recompress sysfs knob

From: Minchan Kim
Date: Fri Nov 04 2022 - 13:53:31 EST


On Fri, Nov 04, 2022 at 04:12:13PM +0900, Sergey Senozhatsky wrote:
> On (22/11/04 12:48), Sergey Senozhatsky wrote:
> > > read_block_state
> > > zram_algo_idx(zram, index) > 0 ? 'r' : '.');
> > >
> > > zram_read_from_zpool
> > > if (zram_algo_idx(zram, idx) != 0)
> > > idx = 1;
> >
> > As an idea, maybe we can store everything re-compression related
> > in a dedicated meta field? SKIP flag, algorithm ID, etc.
>
> That's just an idea.
>
> Something like this
>
> ---
> diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
> index bdfc9bf0bdd5..c011d0f145f6 100644
> --- a/drivers/block/zram/zram_drv.h
> +++ b/drivers/block/zram/zram_drv.h
> @@ -49,8 +49,6 @@ enum zram_pageflags {
> ZRAM_UNDER_WB, /* page is under writeback */
> ZRAM_HUGE, /* Incompressible page */
> ZRAM_IDLE, /* not accessed page since last idle marking */
> - ZRAM_RECOMP, /* page was recompressed */
> - ZRAM_RECOMP_SKIP, /* secondary algorithm cannot compress this page */
>
> __NR_ZRAM_PAGEFLAGS,
> };
> @@ -64,6 +62,11 @@ struct zram_table_entry {
> unsigned long element;
> };
> unsigned long flags;
> +#ifdef CONFIG_ZRAM_MULTI_COMP
> + unsigned int incompressible:1;
> + unsigned int priority:2;
> +#endif
> +
> #ifdef CONFIG_ZRAM_MEMORY_TRACKING
> ktime_t ac_time;
> #endif
> ---
>
> The reason I'm thinking about it is that we have flags bits that are
> used only when particular .config options are enabled. Without those
> options we just waste bits.
>
> Recompression is one such thing. Another one is writeback.
>
> ---
> diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
> index c011d0f145f6..7076ec209e79 100644
> --- a/drivers/block/zram/zram_drv.h
> +++ b/drivers/block/zram/zram_drv.h
> @@ -45,8 +45,6 @@ enum zram_pageflags {
> /* zram slot is locked */
> ZRAM_LOCK = ZRAM_FLAG_SHIFT,
> ZRAM_SAME, /* Page consists the same element */
> - ZRAM_WB, /* page is stored on backing_device */
> - ZRAM_UNDER_WB, /* page is under writeback */
> ZRAM_HUGE, /* Incompressible page */
> ZRAM_IDLE, /* not accessed page since last idle marking */
>
> @@ -68,6 +66,8 @@ struct zram_table_entry {
> #endif
>
> #ifdef CONFIG_ZRAM_MEMORY_TRACKING
> + unsigned int under_writeback:1;
> + unsigned int written_back:1;
> ktime_t ac_time;
> #endif
> };
> ---
>
> So we can use ->flags only for things that are independent of .config

Couldn't we move them into a dedicated field to introduce one more field
overhead in the meta area when we run out the extra field in the flag?
So I'd like to squeeze the bits into flag.