mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: linux-kernel@vger.kernel.org
Cc: Davide Libenzi <davidel@xmailserver.org>,
	Al Viro <viro@ZenIV.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-fsdevel@vger.kernel.org
Subject: [RFC v3 2/2] epoll: use a local wfcq functions for Level Trigger
Date: Thu, 21 Mar 2013 11:54:47 +0000	[thread overview]
Message-ID: <20130321115447.GB17883@dcvr.yhbt.net> (raw)
In-Reply-To: <20130321115259.GA17883@dcvr.yhbt.net>

Using Davide's epwbench to test, this mostly fixes a performance
regression with level trigger in a single-threaded workload.
Single-threaded level trigger is probably the most common method
of using epoll, so performance is important.

Before (without wfcq at all):
AVG: 5.448400
SIG: 0.003056

Before (with wfcq):
AVG: 7.735375
SIG: 0.000064

Currently (with wfcq local):
AVG: 5.532024
SIG: 0.000244

The margin of error for my tests is pretty high under KVM.  I'm getting
wildly varying (~0.10s) differences between runs on the same boot,
However the difference between using plain wfcq and these new _local
functions is large and outside of the margin of error.

ref: http://www.xmailserver.org/epwbench.c

Somewhat-tested-by: Eric Wong <normalperson@yhbt.net>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 fs/eventpoll.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index e039555..1e04175 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1356,7 +1356,7 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi, struct epoll_even
 	return 0;
 }
 
-static int ep_send_events(struct eventpoll *ep,
+static int ep_send_events(struct eventpoll *ep, bool *eavail,
 			  struct epoll_event __user *uevent, int maxevents)
 {
 	int eventcnt = 0;
@@ -1366,7 +1366,10 @@ static int ep_send_events(struct eventpoll *ep,
 	struct wfcq_node *node, *n;
 	enum epoll_item_state state;
 	poll_table pt;
+	struct wfcq_head lthead;
+	struct wfcq_tail lttail;
 
+	wfcq_init(&lthead, &lttail);
 	init_poll_funcptr(&pt, NULL);
 
 	/*
@@ -1414,7 +1417,7 @@ static int ep_send_events(struct eventpoll *ep,
 		if (revents) {
 			if (__put_user(revents, &uevent->events) ||
 			    __put_user(epi->event.data, &uevent->data)) {
-				wfcq_enqueue(&ep->txlhead, &ep->txltail,
+				wfcq_enqueue_local(&ep->txlhead, &ep->txltail,
 							&epi->rdllink);
 				ep_pm_stay_awake(epi);
 				if (!eventcnt)
@@ -1436,7 +1439,7 @@ static int ep_send_events(struct eventpoll *ep,
 				 * epoll_wait() will check again the events
 				 * availability.
 				 */
-				wfcq_enqueue(&ep->rdlhead, &ep->rdltail,
+				wfcq_enqueue_local(&lthead, &lttail,
 							&epi->rdllink);
 				ep_pm_stay_awake(epi);
 				continue;
@@ -1450,6 +1453,14 @@ static int ep_send_events(struct eventpoll *ep,
 		epi->state = EP_STATE_IDLE;
 	}
 
+	/* grab any events we got while copying */
+	*eavail = ep_events_available(ep);
+
+	/* requeue level-triggered items */
+	if (__wfcq_splice(&ep->txlhead, &ep->txltail, &lthead, &lttail)
+	    != WFCQ_RET_SRC_EMPTY)
+		*eavail = true;
+
 	return eventcnt;
 }
 
@@ -1550,12 +1561,11 @@ wait_queue_loop:
 	 * more luck.
 	 */
 	if (!res) {
-		res = ep_send_events(ep, events, maxevents);
+		res = ep_send_events(ep, &eavail, events, maxevents);
 		if (!res && timeout)
 			goto wait_queue_loop;
 	}
 
-	eavail = ep_events_available(ep);
 	mutex_unlock(&ep->mtx);
 
 	/* we may not have transferred everything, wake up others */
-- 
Eric Wong

  reply	other threads:[~2013-03-21 11:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21 11:52 [RFC v3 1/2] epoll: avoid spinlock contention with wfcqueue Eric Wong
2013-03-21 11:54 ` Eric Wong [this message]
2013-03-21 12:01 ` Eric Wong
2013-03-22  1:39 ` Arve Hjønnevåg
2013-03-22  3:24   ` Eric Wong
2013-03-22  4:07     ` Arve Hjønnevåg
2013-03-22 10:31       ` Eric Wong
2013-03-22 19:24         ` Eric Wong
2013-03-22 22:27           ` Arve Hjønnevåg
2013-03-22 22:18         ` Arve Hjønnevåg
2013-03-22 22:54           ` Eric Wong
2013-03-23 10:16             ` Eric Wong

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=20130321115447.GB17883@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=akpm@linux-foundation.org \
    --cc=davidel@xmailserver.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --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

all inboxes | Powered by JetHome®