Re: [PATCHv4 2/9] zram: Add recompression algorithm sysfs knob

From: Minchan Kim
Date: Mon Nov 07 2022 - 14:08:47 EST


On Sat, Nov 05, 2022 at 09:00:33AM +0900, Sergey Senozhatsky wrote:
> On (22/11/05 08:41), Sergey Senozhatsky wrote:
> > One can be SW one can be HW. So I thought about having flexibility here.
> > Instead of doing
> >
> > for (idx = 1; idx < MAX_IDX; idx++) {
> > len = zcomp_compress(zram->comps[idx]);
> > if (len <= threshold)
> > break;
> > }
> >
> > We would just directly use the suggested algo.
> >
> > But we probably don't need that param at all and can use
> > the loop instead?
>
> My idea was that recompress does not loop through the algos (what
> on the fly recompression can do for instance), but instead
> recompress only does one thing.
>
> Because we can have, for instance, something like this
>
> algo=zstd priority=1
> algo=deflate priority=2
>
> And we recompress with algo=zstd only first. Without going
> into the slowest, most CPU and power consuming one. If the
> memory pressure keeps increasing then we might do algo=deflate
> recompress, as the last resort before we do writeback. But we
> may skip algo=deflate altogether and go straight to writeback,
> for instance because we have less than 30% of battery left.
>
> So the reason I suggested algo= in recompress was, basically,
> for that for having exact control of what recompression does.


I am thinking like this:

* Without recomp_algo setup, user can do whatever they want on the fly


echo "type=idle threshold=3000 algo=zstd" > recompress

Later they could do

echo "type=idle threshold=3000 algo=deflate" > recompress

or

writeback to backing device

* With recomp_algo setup like this,

echo "algo=zstd priority=1" > recomp_algo
echo "algo=deflate priority=2" > recomp_algo
..
..
echo "type=idle threshold=3000" > recompress

If zstd fails, it will continue to work with deflate transparently.

IOW, "algo=" in *recompress* interface will override the global policy
in the *recomp_algo* setup. Otherwise, the recomp_algo's set up will
work.