From: Jens Axboe <axboe@kernel.dk>
To: "viro@zeniv.linux.org.uk" <viro@zeniv.linux.org.uk>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] eventfd: convert to using ->write_iter()
Date: Mon, 3 May 2021 08:57:45 -0600 [thread overview]
Message-ID: <7b98e3c2-2d9f-002b-1da1-815d8522b594@kernel.dk> (raw)
Had a report on writing to eventfd with io_uring is slower than it
should be, and it's the usual case of if a file type doesn't support
->write_iter(), then io_uring cannot rely on IOCB_NOWAIT being honored
alongside O_NONBLOCK for whether or not this is a non-blocking write
attempt. That means io_uring will punt the operation to an io thread,
which will slow us down unnecessarily.
Convert eventfd to using fops->write_iter() instead of fops->write().
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
diff --git a/fs/eventfd.c b/fs/eventfd.c
index e265b6dd4f34..02c55e5e1a3e 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -264,17 +264,18 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
return sizeof(ucnt);
}
-static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t count,
- loff_t *ppos)
+static ssize_t eventfd_write(struct kiocb *kiocb, struct iov_iter *from)
{
+ struct file *file = kiocb->ki_filp;
struct eventfd_ctx *ctx = file->private_data;
+ size_t count = iov_iter_count(from);
ssize_t res;
__u64 ucnt;
DECLARE_WAITQUEUE(wait, current);
if (count < sizeof(ucnt))
return -EINVAL;
- if (copy_from_user(&ucnt, buf, sizeof(ucnt)))
+ if (copy_from_iter(&ucnt, count, from) != count)
return -EFAULT;
if (ucnt == ULLONG_MAX)
return -EINVAL;
@@ -282,7 +283,8 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
res = -EAGAIN;
if (ULLONG_MAX - ctx->count > ucnt)
res = sizeof(ucnt);
- else if (!(file->f_flags & O_NONBLOCK)) {
+ else if (!(file->f_flags & O_NONBLOCK) &&
+ !(kiocb->ki_flags & IOCB_NOWAIT)) {
__add_wait_queue(&ctx->wqh, &wait);
for (res = 0;;) {
set_current_state(TASK_INTERRUPTIBLE);
@@ -331,7 +333,7 @@ static const struct file_operations eventfd_fops = {
.release = eventfd_release,
.poll = eventfd_poll,
.read_iter = eventfd_read,
- .write = eventfd_write,
+ .write_iter = eventfd_write,
.llseek = noop_llseek,
};
--
Jens Axboe
next reply other threads:[~2021-05-03 14:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-03 14:57 Jens Axboe [this message]
2021-05-03 16:12 ` [PATCH] eventfd: convert to using ->write_iter() David Laight
2021-05-03 17:57 ` Jens Axboe
2021-05-03 18:02 ` Matthew Wilcox
2021-05-03 18:05 ` Jens Axboe
2021-05-04 8:07 ` David Laight
2021-05-09 13:22 ` [eventfd] cd8a8dd187: WARNING:at_include/linux/thread_info.h:#eventfd_write kernel test robot
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=7b98e3c2-2d9f-002b-1da1-815d8522b594@kernel.dk \
--to=axboe@kernel.dk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).