Re: [RFC] mm/crypto: add tunable compression algorithm for zswap

From: Matthew Wilcox
Date: Sun Apr 02 2017 - 09:57:18 EST


On Sat, Apr 01, 2017 at 11:18:13PM +0200, Vlastimil Babka wrote:
> In this prototype patch, it offers three predefined ratios, but nothing
> prevents more fine-grained settings, except the current crypto API (or my
> limited knowledge of it, but I'm guessing nobody really expected the
> compression ratio to be tunable). So by doing
>
> echo tco50 > /sys/module/zswap/parameters/compressor
>
> you get 50% compression ratio, guaranteed! This setting and zbud are just the
> perfect buddies, if you prefer the nice and simple allocator. Zero internal
> fragmentation!

[...]

> +struct tco_ctx {
> + char ratio;
> +};

You say this is a ratio, but it's a plain char. Clearly it should be
a floating point number; what if I want to achieve 2/3 compression?
Or if I'm a disgruntled sysadmin wanting to show how much more Linux
suxks than BSD, I might want to expand memory when it goes to swap,
perhaps taking up an extra 25%.

Maybe we could get away with char numerator; char denominator to allow
for the most common rationals, but a floating point ratio would be easier
to program with and allow for maximum flexibility. I don't think we
need to have as much precision as a double; a plain float should suffice.