From: Matthew Wilcox <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>,
Ira Weiny <ira.weiny@intel.com>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] mm: Add memcpy_from_file_folio()
Date: Fri, 27 Jan 2023 02:04:25 +0000 [thread overview]
Message-ID: <Y9MxKclIVqHMvpmL@casper.infradead.org> (raw)
In-Reply-To: <20230126154152.898a1bdfd7d729627e2a6bf4@linux-foundation.org>
On Thu, Jan 26, 2023 at 03:41:52PM -0800, Andrew Morton wrote:
> > + * Return: The number of bytes copied from the folio.
> > +static inline size_t memcpy_from_file_folio(char *to, struct folio *folio,
> > + loff_t pos, size_t len)
> > +{
> > + size_t offset = offset_in_folio(folio, pos);
> > + char *from = kmap_local_folio(folio, offset);
> > +
> > + if (folio_test_highmem(folio))
> > + len = min(len, PAGE_SIZE - offset);
> > + else
> > + len = min(len, folio_size(folio) - offset);
>
> min() blows up on arm allnoconfig.
>
> ./include/linux/highmem.h: In function 'memcpy_from_file_folio':
> ./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
> 20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
> | ^~
> ./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
> 26 | (__typecheck(x, y) && __no_side_effects(x, y))
> | ^~~~~~~~~~~
> ./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
> 36 | __builtin_choose_expr(__safe_cmp(x, y), \
> | ^~~~~~~~~~
> ./include/linux/minmax.h:67:25: note: in expansion of macro '__careful_cmp'
> 67 | #define min(x, y) __careful_cmp(x, y, <)
> | ^~~~~~~~~~~~~
> ./include/linux/highmem.h:435:23: note: in expansion of macro 'min'
> 435 | len = min(len, PAGE_SIZE - offset);
> | ^~~
Oh, right, PAGE_SIZE is size_t everywhere except on ARM.
> We could use min_t(), but perhaps and explanatorialy named variable is
> nicer?
But buggy because we return the number of bytes copied.
> --- a/include/linux/highmem.h~mm-add-memcpy_from_file_folio-fix
> +++ a/include/linux/highmem.h
> @@ -430,13 +430,14 @@ static inline size_t memcpy_from_file_fo
> {
> size_t offset = offset_in_folio(folio, pos);
> char *from = kmap_local_folio(folio, offset);
> + size_t remaining;
>
> if (folio_test_highmem(folio))
> - len = min(len, PAGE_SIZE - offset);
> + remaining = PAGE_SIZE - offset;
> else
> - len = min(len, folio_size(folio) - offset);
> + remaining = folio_size(folio) - offset;
I don't think remaining is a great name for this. The key thing is
that for any platform we care about folio_test_highmem() is constant false,
so this just optimises away the min() call.
You could salvage this approach by doing
len = min(remaining, len);
memcpy(to, from, len);
return len;
but I think it's probably better to just do min_t on the PAGE_SIZE line.
Stupid ARM.
> - memcpy(to, from, len);
> + memcpy(to, from, min(len, remaining));
> kunmap_local(from);
>
> return len;
> _
>
prev parent reply other threads:[~2023-01-27 2:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 20:15 [PATCH] mm: Add memcpy_from_file_folio() Matthew Wilcox (Oracle)
2023-01-26 23:41 ` Andrew Morton
2023-01-27 2:04 ` Matthew Wilcox [this message]
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=Y9MxKclIVqHMvpmL@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=fmdefrancesco@gmail.com \
--cc=ira.weiny@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.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).