linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org,
	Matthew Wilcox <willy@infradead.org>,
	Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] fs: don't allocate blocks beyond EOF from __mpage_writepage
Date: Wed, 4 Jan 2023 09:41:47 +0100	[thread overview]
Message-ID: <20230104084147.4z3b33j6ow3g5yas@quack3> (raw)
In-Reply-To: <Y7TCFz++qFNbGKwU@ZenIV>

On Wed 04-01-23 00:02:31, Al Viro wrote:
> On Tue, Jan 03, 2023 at 11:44:30AM +0100, Jan Kara wrote:
> > When __mpage_writepage() is called for a page beyond EOF, it will go and
> > allocate all blocks underlying the page. This is not only unnecessary
> > but this way blocks can get leaked (e.g. if a page beyond EOF is marked
> > dirty but in the end write fails and i_size is not extended).
> > 
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> >  fs/mpage.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/fs/mpage.c b/fs/mpage.c
> > index 0f8ae954a579..9f040c1d5912 100644
> > --- a/fs/mpage.c
> > +++ b/fs/mpage.c
> > @@ -524,6 +524,12 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
> >  	 */
> >  	BUG_ON(!PageUptodate(page));
> >  	block_in_file = (sector_t)page->index << (PAGE_SHIFT - blkbits);
> > +	/*
> > +	 * Whole page beyond EOF? Skip allocating blocks to avoid leaking
> > +	 * space.
> > +	 */
> > +	if (block_in_file >= (i_size + (1 << blkbits) - 1) >> blkbits)
> > +		goto page_is_mapped;
> >  	last_block = (i_size - 1) >> blkbits;
> 
> Why not simply
> 
> 	if (block_in_file > last_block)
> 		goto page_is_mapped;
> 
> after last_block has been calculated?

Because if i_size == 0, last_block is (~0 >> blkbits) (which was actually
the case the test hit).

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2023-01-04  8:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-03 10:44 [PATCH] fs: don't allocate blocks beyond EOF from __mpage_writepage Jan Kara
2023-01-04  0:02 ` Al Viro
2023-01-04  8:41   ` Jan Kara [this message]
2023-01-08 17:25 ` Christoph Hellwig
2023-01-25 14:23   ` Jan Kara
2023-01-25 15:45     ` Matthew Wilcox
2023-01-26  0:52     ` Andrew Morton
2023-01-26  8:42       ` Jan Kara

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=20230104084147.4z3b33j6ow3g5yas@quack3 \
    --to=jack@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.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).