linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Nhat Pham <nphamcs@gmail.com>,
	akpm@linux-foundation.org, chengming.zhou@linux.dev,
	linux-mm@kvack.org, kernel-team@meta.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] page_io: zswap: do not crash the kernel on decompression failure
Date: Mon, 3 Mar 2025 16:55:24 -0500	[thread overview]
Message-ID: <20250303215524.GD120597@cmpxchg.org> (raw)
In-Reply-To: <Z8YdV4Vqju2w7hqI@google.com>

On Mon, Mar 03, 2025 at 09:21:27PM +0000, Yosry Ahmed wrote:
> On Mon, Mar 03, 2025 at 12:06:27PM -0800, Nhat Pham wrote:
> > @@ -635,13 +652,11 @@ void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
> >  	}
> >  	delayacct_swapin_start();
> >  
> > -	if (swap_read_folio_zeromap(folio)) {
> > -		folio_unlock(folio);
> > +	if (swap_read_folio_zeromap(folio) != -ENOENT)
> >  		goto finish;
> 
> I would split the zeromap change into a separate patch, but it's
> probably fine either way.

+1

> > @@ -1025,12 +1028,31 @@ static void zswap_decompress(struct zswap_entry *entry, struct folio *folio)
> >  	sg_init_table(&output, 1);
> >  	sg_set_folio(&output, folio, PAGE_SIZE, 0);
> >  	acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, PAGE_SIZE);
> > -	BUG_ON(crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait));
> > -	BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE);
> > +	decomp_ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait);
> > +	dlen = acomp_ctx->req->dlen;
> >  
> >  	if (src != acomp_ctx->buffer)
> >  		zpool_unmap_handle(zpool, entry->handle);
> >  	acomp_ctx_put_unlock(acomp_ctx);
> > +
> > +	if (decomp_ret || dlen != PAGE_SIZE) {
> > +		zswap_decompress_fail++;
> > +		pr_alert_ratelimited(
> > +			"decompression failed with returned value %d on zswap entry with "
> 
> nit: Decompression*
> 
> I am also wondering how this looks like in dmesg? Is the line too long
> to be read? Should we add some line breaks (e.g. like
> warn_sysctl_write()), we could probably also put this in a helper to
> keep this function visually easy to follow.

If it were more interwoven, I would agree. But it's only followed by
the return true, false. Moving it out of line would need another name
in the zswap namespace and also take an awkward amount of parameters,
so IMO more taxing on the reader.

But maybe do if (!decomp_ret && dlen == PAGE_SIZE) return true, and
then save an indentation for the error part?

> > +			"swap entry value %08lx, swap type %d, and swap offset %lu. "
> > +			"compression algorithm is %s. compressed size is %u bytes, and "
> > +			"decompressed size is %u bytes.\n",

Any objections to shortening it and avoiding the line length issue?
Even with \n's, this is still a lot of characters to dump 10x/5s. And
it's not like the debug info is super useful to anyone but kernel
developers, who in turn wouldn't have an issue interpreting this:

pr_alert_ratelimited("Decompression error from zswap (%d:%lu %s %u->%d)\n",
		     swptype, swpoffset, name, clen, dlen);

> > +			decomp_ret,
> > +			entry->swpentry.val,
> > +			swp_type(entry->swpentry),
> > +			swp_offset(entry->swpentry),
> > +			entry->pool->tfm_name,
> > +			entry->length,
> > +			acomp_ctx->req->dlen);


  reply	other threads:[~2025-03-03 21:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 20:06 Nhat Pham
2025-03-03 21:21 ` Yosry Ahmed
2025-03-03 21:55   ` Johannes Weiner [this message]
2025-03-03 22:34     ` Yosry Ahmed
2025-03-03 23:16       ` Johannes Weiner
2025-03-03 23:28         ` Nhat Pham
2025-03-04  0:05         ` Yosry Ahmed
2025-03-03 23:22       ` Nhat Pham

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=20250303215524.GD120597@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=yosry.ahmed@linux.dev \
    /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