public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org,
	Wang Yugui <wangyugui@e16-tech.com>,
	Christoph Hellwig <hch@infradead.org>,
	"Darrick J . Wong" <djwong@kernel.org>
Subject: Re: [PATCH 1/3] filemap: Allow __filemap_get_folio to allocate large folios
Date: Sun, 21 May 2023 04:38:36 +0100	[thread overview]
Message-ID: <ZGmSPNHU44dAzPvE@casper.infradead.org> (raw)
In-Reply-To: <ZGl+ZeaCB+7D23xj@dread.disaster.area>

On Sun, May 21, 2023 at 12:13:57PM +1000, Dave Chinner wrote:
> > +static inline unsigned fgp_order(size_t size)
> > +{
> > +	unsigned int shift = ilog2(size);
> > +
> > +	if (shift <= PAGE_SHIFT)
> > +		return 0;
> > +	return (shift - PAGE_SHIFT) << 26;
> > +}
> 
> Doesn't check for being larger than MAX_PAGECACHE_ORDER.

It doesn't need to.  I check it on extraction.  We've got six bits,
so we can't overflow it.

> Also: naming. FGP_ORDER(fgp) to get the order stored in the fgp,
> fgp_order(size) to get the order from the IO length.
> 
> Both are integers, the compiler is not going to tell us when we get
> them the wrong way around, and it's impossible to determine which
> one is right just from looking at the code.
> 
> Perhaps fgp_order_from_flags(fgp) and fgp_order_from_length(size)?

Yeah, I don't like that either.  I could be talked into
fgp_set_order(size) and fgp_get_order(fgp).  Also we should type the
FGP flags like we type the GFP flags.

> Also, why put the order in the high bits? Shifting integers up into
> unaligned high bits is prone to sign extension issues and overflows.
> e.g.  fgp_flags is passed around the filemap functions as a signed
> integer, so using the high bit in a shifted value that is unsigned
> seems like a recipe for unexpected sign extension bugs on
> extraction.

As long as it's an unsigned int in the function which does the extraction,
there's no problem.  It's also kind of hard to set the top bit -- you'd
have to somehow get a 2^44 byte write into iomap.

> Hence I'd much prefer low bits are used for this sort of integer
> encoding (i.e. uses masks instead of shifts for extraction), and
> that flags fields -always- use unsigned variables so high bit
> usage doesn't unexpected do the wrong thing....

There are some encoding advantages to using low bits for flags.  Does
depend on the architecture; x86 is particularly prone to this kind of
thing, but ARM has various constraints on what constants it can
represent as immediates.  I've rarely had cause to care about other
architecture details, but generally low bits are better supported
as flags than high bits.

  reply	other threads:[~2023-05-21  3:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-20 16:36 [PATCH 0/3] Create large folios in iomap buffered write path Matthew Wilcox (Oracle)
2023-05-20 16:36 ` [PATCH 1/3] filemap: Allow __filemap_get_folio to allocate large folios Matthew Wilcox (Oracle)
2023-05-21  1:02   ` Wang Yugui
2023-05-21  1:56     ` Matthew Wilcox
2023-05-21  2:04       ` Wang Yugui
2023-05-21  3:39         ` Matthew Wilcox
2023-05-21  2:13   ` Dave Chinner
2023-05-21  3:38     ` Matthew Wilcox [this message]
2023-05-23  5:59   ` Christoph Hellwig
2023-05-23 12:17     ` Matthew Wilcox
2023-05-20 16:36 ` [PATCH 2/3] iomap: Create large folios in the buffered write path Matthew Wilcox (Oracle)
2023-05-20 16:36 ` [PATCH 3/3] iomap: Copy larger chunks from userspace Matthew Wilcox (Oracle)
2023-05-20 19:11   ` kernel test robot
2023-05-20 19:25   ` kernel test robot
2023-05-21  0:49 ` [PATCH 0/3] Create large folios in iomap buffered write path Wang Yugui
2023-05-21  0:59   ` Matthew Wilcox
2023-05-21  1:38     ` Wang Yugui
2023-05-21  2:49 ` Dave Chinner
2023-05-21 11:40 ` Wang Yugui
2023-05-31  4:34   ` Wang Yugui

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=ZGmSPNHU44dAzPvE@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=wangyugui@e16-tech.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox