All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosry.ahmed@linux.dev>
To: Johannes Weiner <hannes@cmpxchg.org>
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 v2] zswap: do not crash the kernel on decompression failure
Date: Thu, 27 Feb 2025 07:29:45 +0000	[thread overview]
Message-ID: <Z8AUaQamubA9lWae@google.com> (raw)
In-Reply-To: <Z8AQPyY7Qpux0mO0@google.com>

On Thu, Feb 27, 2025 at 07:11:59AM +0000, Yosry Ahmed wrote:
> On Thu, Feb 27, 2025 at 01:16:16AM -0500, Johannes Weiner wrote:
> > On Thu, Feb 27, 2025 at 05:44:29AM +0000, Yosry Ahmed wrote:
> > > On Wed, Feb 26, 2025 at 11:31:41PM -0500, Johannes Weiner wrote:
> > > > On Thu, Feb 27, 2025 at 01:19:31AM +0000, Yosry Ahmed wrote:
> > > > > On Wed, Feb 26, 2025 at 04:14:45PM -0800, Nhat Pham wrote:
> > > > > >  	if (WARN_ON_ONCE(folio_test_large(folio)))
> > > > > >  		return true;
> > > > > >  
> > > > > > +	entry = xa_load(tree, offset);
> > > > > > +	if (!entry)
> > > > > > +		return false;
> > > > > > +
> > > > > 
> > > > > A small comment here pointing out that we are deliberatly not setting
> > > > > uptodate because of the failure may make things more obvious, or do you
> > > > > think that's not needed?
> > > > >
> > > > > > +	if (!zswap_decompress(entry, folio))
> > > > > > +		return true;
> > > > 
> > > > How about an actual -ev and have this in swap_read_folio():
> > > 
> > > Good idea, I was going to suggest an enum but this is simpler.
> > > 
> > > > 
> > > >         ret = zswap_load(folio);
> > > >         if (ret != -ENOENT) {
> > > >                 folio_unlock(folio);
> > > >                 goto finish;
> > > >         }
> > > > 
> > > > 	read from swapfile...
> > > > 
> > > > Then in zswap_load(), move uptodate further up like this (I had
> > > > previously suggested this):
> > > > 
> > > > 	if (!zswap_decompress(entry, folio))
> > > > 		return -EIO;
> > > > 
> > > > 	folio_mark_uptodate(folio);
> > > > 
> > > > and I think it would be clear, even without or just minimal comments.
> > > 
> > > Another possibility is moving folio_mark_uptodate() back to
> > > swap_read_folio(), which should make things even clearer imo as the
> > > success/failure logic is all in one place:
> > 
> > That works. bdev, swapfile and zeromap set the flag in that file.
> > 
> > > 	ret = zswap_load(folio);
> > > 	if (ret != -ENOENT) {
> > > 		folio_unlock(folio);
> > > 		/* Comment about not marking uptodate */
> > > 		if (!ret)
> > > 			folio_mark_uptodate();
> > > 		goto finish;
> > > 	}
> > 
> > Personally, I like this one ^. The comment isn't needed IMO, as now
> > zswap really isn't doing anything special compared to the others.
> > 
> > > or we can make it crystal clear we have 3 distinct cases:
> > > 
> > > 	ret = zswap_load(folio);
> > > 	if (!ret) {
> > > 		folio_unlock(folio);
> > > 		folio_mark_uptodate();
> > > 		goto finish;
> > > 	} else if (ret != -ENOENT) {
> > > 		/* Comment about not marking uptodate */
> > > 		folio_unlock(folio);
> > > 		goto finish;
> > > 	}
> > 
> > This seems unnecessarily repetetive.
> 
> I know, but looking at the two, this one makes it clearer to me there
> are 3 distinct cases, and the redundancy is not terrible.
> 
> So I personally prefer the latter, but I am fine either way.

I just realized that swap_read_folio_zeromap() does the same trick, so
we should probably also move the folio_mark_uptodate() in there to
swap_read_folio().

Maybe we can do something like this:

/* Returns true if the folio was in the zeromap or zswap */
bool swap_read_folio_in_memory(struct folio *folio)
{
	int ret;

	ret = swap_read_folio_zeromap(folio);
	if (ret == -ENOENT)
		ret = zswap_load(folio);

	if (ret == 0) {
		folio_mark_uptodate(folio);
		folio_unlock(folio);
		return true;
	} else if (ret != -ENOENT) {
		folio_unlock(folio);
		return true;
	} else {
		return false;
	}
}

void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
{
	...
	if (swap_read_folio_in_memory(folio))
		goto finish;
	...
}

Admittedly, swap_read_folio_in_memory() is not a good name. Maybe
swap_read_folio_zeromap_or_zswap() :)


  reply	other threads:[~2025-02-27  7:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-27  0:14 [PATCH v2] zswap: do not crash the kernel on decompression failure Nhat Pham
2025-02-27  1:19 ` Yosry Ahmed
2025-02-27  4:31   ` Johannes Weiner
2025-02-27  5:44     ` Yosry Ahmed
2025-02-27  6:16       ` Johannes Weiner
2025-02-27  7:11         ` Yosry Ahmed
2025-02-27  7:29           ` Yosry Ahmed [this message]
2025-02-27 16:05             ` Johannes Weiner
2025-02-27 18:01               ` Yosry Ahmed
2025-02-27 22:35               ` Nhat Pham
2025-02-27 21:46   ` Nhat Pham
2025-02-27 21:55     ` Yosry Ahmed
2025-03-01  2:08       ` Nhat Pham
2025-03-01  2:20         ` Yosry Ahmed

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=Z8AUaQamubA9lWae@google.com \
    --to=yosry.ahmed@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.