linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Rik van Riel <riel@surriel.com>
Cc: Hugh Dickins <hughd@google.com>,
	kernel-team@meta.com, Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Dave Chinner <dchinner@redhat.com>,
	Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [PATCH] mm,tmpfs: consider end of file write in shmem_is_huge
Date: Fri, 30 Aug 2024 16:21:32 -0700	[thread overview]
Message-ID: <20240830232132.GG6257@frogsfrogsfrogs> (raw)
In-Reply-To: <97ba80061354fef89349a70e1cb8eb34dd7730f3.camel@surriel.com>

On Fri, Aug 30, 2024 at 09:11:32AM -0400, Rik van Riel wrote:
> On Thu, 2024-08-29 at 22:52 -0700, Darrick J. Wong wrote:
> > On Thu, Aug 29, 2024 at 11:54:15PM -0400, Rik van Riel wrote:
> > > 
> > > @@ -196,7 +196,7 @@ xfile_store(
> > >  		unsigned int	len;
> > >  		unsigned int	offset;
> > >  
> > > -		if (shmem_get_folio(inode, pos >> PAGE_SHIFT,
> > > &folio,
> > > +		if (shmem_get_folio(inode, pos >> PAGE_SHIFT, 0,
> > > &folio,
> > 
> > Technically speaking, the "0" here could be (pos + count), though for
> > the current xfile users this isn't likely to make much difference
> > because online fsck's index building only appends small amounts of
> > data
> > (i.e. not larger than a PAGE_SIZE) at a time.
> > 
> > >  				SGP_CACHE) < 0)
> 
> With SGP_CACHE, won't shmem_get_folio simply refuse to allocate
> any pages beyond the end of the inode?

Yes, though we're careful to i_size_write appropriate beforehand such
that @index is always within EOF.

--D

>         if (sgp <= SGP_CACHE &&
>             ((loff_t)index << PAGE_SHIFT) >= i_size_read(inode))
>                 return -EINVAL;
> 
> > >  			break;
> > >  		if (filemap_check_wb_err(inode->i_mapping, 0)) {
> > > @@ -267,7 +267,7 @@ xfile_get_folio(
> > >  		i_size_write(inode, pos + len);
> > >  
> > >  	pflags = memalloc_nofs_save();
> > > -	error = shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio,
> > > +	error = shmem_get_folio(inode, pos >> PAGE_SHIFT, 0,
> > > &folio,
> > 
> > This 0 could be pos + len, since the only caller is xfarray_sort,
> > which
> > runs much faster when it can heapsort a large folio's worth of data
> > at a
> > time.
> > 
> > >  			(flags & XFILE_ALLOC) ? SGP_CACHE :
> > > SGP_READ);
> 
> The same applies here.
> 
> > >  	memalloc_nofs_restore(pflags);
> > >  	if (error)
> > > diff --git a/fs/xfs/xfs_buf_mem.c b/fs/xfs/xfs_buf_mem.c
> > > index 9bb2d24de709..07bebbfb16ee 100644
> > > --- a/fs/xfs/xfs_buf_mem.c
> > > +++ b/fs/xfs/xfs_buf_mem.c
> > > @@ -149,7 +149,7 @@ xmbuf_map_page(
> > >  		return -ENOMEM;
> > >  	}
> > >  
> > > -	error = shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio,
> > > SGP_CACHE);
> > > +	error = shmem_get_folio(inode, pos >> PAGE_SHIFT, 0,
> > > &folio, SGP_CACHE);
> > 
> > The "0" here could be (pos + BBTOB(bp->length)) since we're likely
> > going
> > to write there soon.  Granted, no current user of xmbufs actually
> > uses a
> > blocksize larger than PAGE_SIZE, but in theory we could someday turn
> > that on.
> > 
> > Everything below here looks sane enough to me, but I'm not that much
> > of
> > an expert on mm/ things outside of the pagecache and shmem.c.
> 
> ... and here.
> 
> XFS is no using an SGP flag that allows shmem_get_folio to allocate
> a page beyond the end of the i_size.
> 
> -- 
> All Rights Reversed.


  reply	other threads:[~2024-08-30 23:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-30  3:54 Rik van Riel
2024-08-30  5:52 ` Darrick J. Wong
2024-08-30 13:11   ` Rik van Riel
2024-08-30 23:21     ` Darrick J. Wong [this message]
2024-09-02  8:36 ` Baolin Wang

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=20240830232132.GG6257@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=dchinner@redhat.com \
    --cc=hughd@google.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.com \
    --cc=vbabka@suse.cz \
    /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