From: Linus Torvalds <torvalds@linux-foundation.org>
To: David Laight <David.Laight@aculab.com>
Cc: David Howells <dhowells@redhat.com>,
Al Viro <viro@zeniv.linux.org.uk>, Jens Axboe <axboe@kernel.dk>,
Christian Brauner <christian@brauner.io>,
Matthew Wilcox <willy@infradead.org>,
Jeff Layton <jlayton@kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] iov_iter: Don't deal with iter->copy_mc in memcpy_from_iter_mc()
Date: Thu, 17 Aug 2023 17:31:09 +0200 [thread overview]
Message-ID: <CAHk-=wj1WfFGxHs4k6pn5y6V8BYd3aqODCjqEmrTWP8XO78giw@mail.gmail.com> (raw)
In-Reply-To: <2190704172a5458eb909c9df59b6a556@AcuMS.aculab.com>
On Thu, 17 Aug 2023 at 17:16, David Laight <David.Laight@aculab.com> wrote:
>
> gcc for x86-64 make a pigs-breakfast when the bitfields are 'char'
> and loads the constant from memory using pc-relative access.
I think your godbolt tests must be with some other model than what the
kernel uses.
For example, for me, iov_iter_init generates
testl %esi, %esi # direction test
movb $1, (%rdi) # bitfields
movq $0, 8(%rdi)
movq %rdx, 16(%rdi)
movq %r8, 24(%rdi)
movq %rcx, 32(%rdi)
setne 1(%rdi) # set the direction byte
with my patch for me. Which is pretty much optimal.
*Without& the patch, I get
movzwl .LC1(%rip), %eax
testl %esi, %esi
movb $0, (%rdi)
movb $1, 4(%rdi)
movw %ax, 1(%rdi)
movq $0, 8(%rdi)
movq %rdx, 16(%rdi)
movq %r8, 24(%rdi)
movq %rcx, 32(%rdi)
setne 3(%rdi)
which is that disgusting "move two bytes from memory", and makes
absolutely no sense as a way to "write 2 zero bytes":
.LC1:
.byte 0
.byte 0
I think that's some odd gcc bug, actually.
> Otherwise pretty must all variants (with or without the bitfield)
> get initialised in a single write.
So there may well be some odd gcc code generation issue that is
triggered by the fact that we use an initializer to set those things,
and we then have two bytes (with my patch) followed by a hole, or
three bytes (without it) followed by a hole.
But that bitfield thing improves things at least for me. I think the
example code you used for godbolt is actually something else than what
the kernel does.
Linus
next prev parent reply other threads:[~2023-08-17 15:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 12:07 [PATCH v3 0/2] iov_iter: Convert the iterator macros into inline funcs David Howells
2023-08-16 12:07 ` [PATCH v3 1/2] iov_iter: Convert iterate*() to " David Howells
2023-08-16 12:07 ` [PATCH v3 2/2] iov_iter: Don't deal with iter->copy_mc in memcpy_from_iter_mc() David Howells
2023-08-16 12:28 ` David Laight
2023-08-16 13:00 ` David Howells
2023-08-16 14:19 ` David Laight
2023-08-16 18:50 ` Linus Torvalds
2023-08-16 20:35 ` David Howells
2023-08-17 4:18 ` Linus Torvalds
2023-08-17 8:41 ` David Laight
2023-08-17 14:38 ` Linus Torvalds
2023-08-17 15:16 ` David Laight
2023-08-17 15:31 ` Linus Torvalds [this message]
2023-08-17 16:06 ` David Laight
2023-08-18 15:19 ` David Howells
2023-08-18 15:42 ` David Laight
2023-08-18 16:48 ` David Howells
2023-08-18 21:39 ` David Laight
2023-08-18 11:42 ` David Howells
2023-08-18 12:16 ` David Laight
2023-08-18 12:26 ` Matthew Wilcox
2023-08-18 12:41 ` David Laight
2023-08-18 13:33 ` David Howells
2023-08-18 11:39 ` David Howells
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='CAHk-=wj1WfFGxHs4k6pn5y6V8BYd3aqODCjqEmrTWP8XO78giw@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=David.Laight@aculab.com \
--cc=axboe@kernel.dk \
--cc=christian@brauner.io \
--cc=dhowells@redhat.com \
--cc=jlayton@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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