linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Minchan Kim <minchan@kernel.org>,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCHv3 00/19] zram: convert to custom compression API and allow algorithms tuning
Date: Fri, 10 May 2024 14:15:09 +0900	[thread overview]
Message-ID: <20240510051509.GI8623@google.com> (raw)
In-Reply-To: <ZjzFB2CzCh1NKlfw@infradead.org>

On (24/05/09 05:43), Christoph Hellwig wrote:
> On Wed, May 08, 2024 at 04:41:53PM +0900, Sergey Senozhatsky wrote:
> > 	This patch set moves zram from crypto API to a custom compression
> > API which allows us to tune and configure compression algorithms,
> > something that crypto API, unfortunately, doesn't support.
> 
> [...]
> 
> >  21 files changed, 1203 insertions(+), 111 deletions(-)
> 
> Why can't it?

Well, I asked crypto folks if that's doable and the only reply was
"did you try using compression libs directly".  And that's not a
bad response, I take it.

The handling of parameters becomes quite intrusive very quickly.
It's not as simple as just passing a new "struct crypto_tfm" to all
sort of API abstractions that crypto has, it's a little more than that.

Just as an example.  For zstd we can work in two modes
1) load the dictionary by_copy
2) load the dictionary by_ref

In (2) we need to guarantee that the dictionary memory outlives any
comp contexts, so cyrpto_tfm-s now begin to have "external" dependency.
But if we load the dictionary by_ref then what we can do is a
pre-processing of the dictionary buffer - we get CDict and DDict
pointers (specific only to zstd backend) which all contexts now can
share (contexts access C/D Dict in read-only mode).  For this we need
to have a pre-processing stage somewhere in the API and keep the
"compression's backend private data" somewhere, then somehow pass it to
context cra_init and release that memory when all context were destroyed.
In zram I just went with "we do only by_ref" and handle all the
dependencies/guarantees, it's very simple because all of this stays
in zram.

But in general case, a typical crypto API usage

	tfm = crypto_alloc_comp(comp->name, 0, 0);

should become much more complex.  I'd say that, probably, developing
an entirely new sub-set of API would be simpler.

So I implemented a simple zram comp API.  I can't tell how much effort
it'll be to handle all of this in crypto, I'm not really familiar with
crypto, and I'm not sure if crypto API folks are even interested.

> This is an awful lot of crazy code duplication just
> to pass a few parameters.

I see what you mean, but the majority of the code is unique, there
isn't too much code duplication in fact.  Params handling is unique,
dictionary handling is unique, zstd implementation is entirely
different and pretty much specific to zram (we don't handle all sort
of cases that zstd API support, we focus on things that we need),
lz4/lz4hc implementations are also different, etc. etc.  Things like
lzo/lzorle may count as code duplication, but those are like 20 lines
of code or maybe even less (which isn't that crazy).

  reply	other threads:[~2024-05-10  5:15 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08  7:41 [PATCHv3 00/19] zram: convert to custom compression API and allow algorithms tuning Sergey Senozhatsky
2024-05-08  7:41 ` [PATCHv3 01/19] zram: move from crypto API to custom comp backends API Sergey Senozhatsky
2024-05-08  7:41 ` [PATCHv3 02/19] zram: add lzo and lzorle compression backends support Sergey Senozhatsky
2024-05-09 11:23   ` kernel test robot
2024-05-10  5:33     ` Sergey Senozhatsky
2024-05-08  7:41 ` [PATCHv3 03/19] zram: add lz4 compression backend support Sergey Senozhatsky
2024-05-10  7:00   ` Sergey Senozhatsky
2024-05-08  7:41 ` [PATCHv3 04/19] zram: add lz4hc " Sergey Senozhatsky
2024-05-08  7:41 ` [PATCHv3 05/19] zram: add zstd " Sergey Senozhatsky
2024-05-08  7:41 ` [PATCHv3 06/19] zram: pass estimated src size hint to zstd Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 07/19] zram: add zlib compression backend support Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 08/19] zram: add 842 " Sergey Senozhatsky
2024-05-09 12:42   ` Christoph Hellwig
2024-05-10  4:43     ` Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 09/19] zram: check that backends array has at least one backend Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 10/19] zram: introduce zcomp_config structure Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 11/19] zram: extend comp_algorithm attr write handling Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 12/19] zram: support compression level comp config Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 13/19] zram: add support for dict " Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 14/19] zram: add dictionary support to zstd backend Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 15/19] zram: add config init/release backend callbacks Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 16/19] zram: share dictionaries between per-CPU contexts Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 17/19] zram: add dictionary support to lz4 Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 18/19] zram: add dictionary support to lz4hc Sergey Senozhatsky
2024-05-08  7:42 ` [PATCHv3 19/19] Documentation/zram: add documentation for algorithm parameters Sergey Senozhatsky
2024-05-09 12:43 ` [PATCHv3 00/19] zram: convert to custom compression API and allow algorithms tuning Christoph Hellwig
2024-05-10  5:15   ` Sergey Senozhatsky [this message]
2024-05-10  7:40     ` Herbert Xu
2024-05-10  8:08       ` Sergey Senozhatsky
2024-05-10  8:12         ` Herbert Xu
2024-05-10  8:28           ` Sergey Senozhatsky
2024-05-10  8:30             ` Herbert Xu
2024-05-10  8:40               ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240510051509.GI8623@google.com \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=hch@infradead.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).