2022-10-07 17:14:30

by Jens Axboe

[permalink] [raw]
Subject: [PATCHSET RFC 0/4] Add support for epoll min_wait

Hi,

This adds support for EPOLL_CTL_MIN_WAIT, which allows setting a minimum
time that epoll_wait() should wait for events on a given epoll context.
Some justification and numbers are in patch 4, patches 1-3 are really
just prep patches.

Sending this as an RFC to hash out the API, basically. This is
obviously a per-context type of operation in this patchset, which isn't
necessarily ideal for any use case. Questions to be debated:

1) Would we want this to be available through epoll_wait() directly?
That would allow this to be done on a per-epoll_wait() basis, rather
than be tied to the specific context.

2) If the answer to #1 is yes, would we still want EPOLL_CTL_MIN_WAIT?

I think there are pros and cons to both, and perhaps the answer to both
is "yes". There are some benefits to doing this at epoll setup time,
for example - it nicely isolates it to that part rather than needing
to be done dynamically everytime epoll_wait() is called. This also
helps the application code, as it can turn off any busy'ness tracking
based on if the setup accepted EPOLL_CTL_MIN_WAIT or not.

Anyway, tossing this out there as it yielded quite good results in
some initial testing, we're running more of it.

--
Jens Axboe



2022-10-07 17:29:21

by Jens Axboe

[permalink] [raw]
Subject: [PATCH 3/4] eventpoll: move expires to epoll_wq

This makes the expiration available to the wakeup handler. No functional
changes expected in this patch, purely in preparation for being able to
use the timeout on the wakeup side.

Signed-off-by: Jens Axboe <[email protected]>
---
fs/eventpoll.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 01b9dab2b68c..79aa61a951df 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1765,6 +1765,7 @@ static int ep_autoremove_wake_function(struct wait_queue_entry *wq_entry,
struct epoll_wq {
wait_queue_entry_t wait;
struct hrtimer timer;
+ ktime_t timeout_ts;
bool timed_out;
};

@@ -1825,7 +1826,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
{
int res, eavail;
u64 slack = 0;
- ktime_t expires, *to = NULL;
+ ktime_t *to = NULL;
struct epoll_wq ewq;

lockdep_assert_irqs_enabled();
@@ -1834,7 +1835,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,

if (timeout && (timeout->tv_sec | timeout->tv_nsec)) {
slack = select_estimate_accuracy(timeout);
- to = &expires;
+ to = &ewq.timeout_ts;
*to = timespec64_to_ktime(*timeout);
} else if (timeout) {
/*
--
2.35.1