Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Suseendran Bhaskaran" <suseendranb@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Yosry Ahmed" <yosry@kernel.org>, "Nhat Pham" <nphamcs@gmail.com>
Cc: "Chengming Zhou" <chengming.zhou@linux.dev>,
	"Nick Terrell" <terrelln@fb.com>,
	"David Sterba" <dsterba@suse.com>, "SJ Park" <sj@kernel.org>,
	"Chris Li" <chrisl@kernel.org>,
	"Giovanni Cabiddu" <giovanni.cabiddu@intel.com>,
	"Suman Kumar Chakraborty" <suman.kumar.chakraborty@intel.com>,
	linux-crypto@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 2/2] mm/zswap: classify compression dst overflow as poor compression
Date: Thu, 22 Oct 2026 20:57:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-182032@kernel.org> (raw)
In-Reply-To: <20261021205626.3286270-3-suseendranb@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/zswap: zswap_compress() mishandles -E2BIG overflow from hw compressors
--

commit 6e958455f7e6f806b4bd7b7afc39fe7c9fb8cd1f
Author: Suseendran Bhaskaran <suseendranb@google.com>

mm/zswap: classify compression dst overflow as poor compression

This commit updates zswap_compress() to treat only -ENOSPC or an output
length of at least PAGE_SIZE as an incompressible page, while routing other
non-zero return values from crypto_acomp_compress() to the compressor failure
path.

> diff --git a/mm/zswap.c b/mm/zswap.c
> index 37f34e406c8e3..5f2a941fcaf1e 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -881,12 +881,12 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,
>  	 * only adds metadata overhead.  swap_writeout() will put the page back
>  	 * to the active LRU list in the case.
>  	 */
> -	if (comp_ret || !dlen || dlen >= PAGE_SIZE) {
> +	if (comp_ret == -ENOSPC || (!comp_ret && dlen >= PAGE_SIZE)) {
>  		rcu_read_lock();
>  		if (!mem_cgroup_zswap_writeback_enabled(
>  					folio_memcg(page_folio(page)))) {
>  			rcu_read_unlock();
> -			comp_ret = comp_ret ? comp_ret : -EINVAL;
> +			comp_ret = -ENOSPC;
>  			goto unlock;
>  		}
>  		rcu_read_unlock();
> @@ -894,6 +894,9 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,
>  		dlen = PAGE_SIZE;
>  		dst = kmap_local_page(page);
>  		mapped = true;
> +	} else if (comp_ret || !dlen) {
> +		comp_ret = comp_ret ? comp_ret : -EINVAL;
> +		goto unlock;
>  	}
>  
>  	gfp = GFP_NOWAIT | __GFP_NORETRY | __GFP_HIGHMEM | __GFP_MOVABLE;

[Severity: Medium]
Does restricting the incompressible page check to comp_ret == -ENOSPC cause a
regression when using hardware acomp drivers that return -E2BIG or -EOVERFLOW
on destination buffer overflow?

When zswap_store() -> zswap_store_page() -> zswap_compress() compresses an
incompressible page into a PAGE_SIZE destination buffer, hardware acomp
drivers in drivers/crypto/ do not return -ENOSPC when the compressed output
exceeds the destination buffer:

drivers/crypto/intel/iaa/iaa_crypto_main.c:check_completion() {
	if (comp->status == IAA_ANALYTICS_ERROR &&
	    comp->error_code == IAA_ERROR_COMP_BUF_OVERFLOW && compress) {
		ret = -E2BIG;
		dev_dbg(dev, "compressed > uncompressed size,"
			" not compressing, size=0x%x\n",
			comp->output_size);
		update_completion_comp_buf_overflow_errs();
		goto out;
	}
}

Similarly, the QAT acomp driver (which registers deflate and zstd with
priority 4001) completes destination buffer overflows with -E2BIG in
qat_comp_generic_callback() (and -E2BIG or -EOVERFLOW in
qat_comp_lz4s_zstd_callback()):

drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:qat_comp_generic_callback() {
	if (unlikely(produced > qat_req->actual_dlen)) {
		memset(inst->dc_data->ovf_buff, 0,
		       inst->dc_data->ovf_buff_sz);
		dev_dbg(&GET_DEV(accel_dev),
			"Actual buffer overflow: produced=%d, dlen=%d\n",
			produced, qat_req->actual_dlen);

		res = -E2BIG;
		areq->dlen = 0;
		goto end;
	}
}

With this change, -E2BIG and -EOVERFLOW fall into the else if (comp_ret ||
!dlen) branch and jump to unlock. When zswap writeback is enabled,
incompressible pages will be rejected instead of being stored uncompressed in
zsmalloc, and zswap_reject_compress_fail will be incremented instead of
zswap_reject_compress_poor.

Should those hardware acomp drivers be updated to return -ENOSPC on
destination overflow, or should zswap_compress() also handle -E2BIG and
-EOVERFLOW as poor compression?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261021205626.3286270-1-suseendranb@google.com?part=2


      parent reply	other threads:[~2026-10-22 20:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 20:56 [PATCH 0/2] mm/zswap: distinguish incompressible pages from compressor failures Suseendran Bhaskaran
2026-10-21 20:56 ` [PATCH 1/2] crypto: return -ENOSPC on compression destination overflow Suseendran Bhaskaran
2026-10-22  8:14   ` Herbert Xu
2026-10-22 15:34     ` Yosry Ahmed
2026-10-22 22:19       ` Yosry Ahmed
2026-10-21 20:56 ` [PATCH 2/2] mm/zswap: classify compression dst overflow as poor compression Suseendran Bhaskaran
2026-10-21 21:47   ` Yosry Ahmed
2026-10-22 15:51     ` Suseendran Bhaskaran
2026-10-22 16:01       ` Yosry Ahmed
2026-10-22 18:33         ` Suseendran Bhaskaran
2026-10-22 19:15           ` Yosry Ahmed
2026-10-22 22:05             ` Suseendran Bhaskaran
2026-10-22 20:57   ` sashiko-bot [this message]

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=sashiko-outbox-182032@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsterba@suse.com \
    --cc=giovanni.cabiddu@intel.com \
    --cc=hannes@cmpxchg.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sj@kernel.org \
    --cc=suman.kumar.chakraborty@intel.com \
    --cc=suseendranb@google.com \
    --cc=terrelln@fb.com \
    --cc=yosry@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