linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] epoll: remove the on_list check for 'struct epitem'
@ 2013-10-30 18:32 Jason Baron
  2013-10-31 23:09 ` Stephen Rothwell
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Baron @ 2013-10-30 18:32 UTC (permalink / raw)
  To: akpm
  Cc: paulmck, normalperson, nzimmer, viro, nelhage, davidel,
	linux-kernel, linux-fsdevel

By removing the 'int on_list' field from 'struct epitem', we avoid hitting the
BUILD_BUG_ON() for 'struct epitem' being larger than 128 bytes.

In file included from include/linux/init.h:4:0,
                 from fs/eventpoll.c:14:
fs/eventpoll.c: In function 'eventpoll_init':
include/linux/compiler.h:321:20: error: call to '__compiletime_assert_2137' declared with attribute error: BUILD_BUG_ON failed: sizeof(void *) <= 8 && sizeof(struct epitem) > 128
    prefix ## suffix();    \

The check to make sure that the 'struct epitem' was actually linked via
epi->fllink was added to avoid having the list removal primitives called twice
for the same 'struct epitem'. However, the double call possibility was removed
by 'Subject: epoll: optimize EPOLL_CTL_DEL using rcu'. There, the call to
'list_del_init()' in eventpoll_release_file() was removed (we now rely on the
list delete happening entirely in 'ep_remove()', which is called from
eventpoll_release_file()).

There is also the question as to whether multiple ep_remove() calls could
happen concurrently. This can not happen since EPOLL_CTL_DEL can't
race with eventpoll_release_file() or ep_free() - it has to do an fget()
to proceed. Further, eventpoll_release_file() can not race with ep_free(),
since they both acquire the 'epmutex'.

Signed-off-by: Jason Baron <jbaron@akamai.com>
---
 fs/eventpoll.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 755bda0..69de7a6 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -171,9 +171,6 @@ struct epitem {
 
 	/* The structure that describe the interested events and the source fd */
 	struct epoll_event event;
-
-	/* The fllink is in use. Since rcu can't do 'list_del_init()' */
-	int on_list;
 };
 
 /*
@@ -710,10 +707,7 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
 
 	/* Remove the current item from the list of epoll hooks */
 	spin_lock(&file->f_lock);
-	if (epi->on_list) {
-		list_del_rcu(&epi->fllink);
-		epi->on_list = 0;
-	}
+	list_del_rcu(&epi->fllink);
 	spin_unlock(&file->f_lock);
 
 	rb_erase(&epi->rbn, &ep->rbr);
@@ -1295,7 +1289,6 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
 	epi->event = *event;
 	epi->nwait = 0;
 	epi->next = EP_UNACTIVE_PTR;
-	epi->on_list = 0;
 	if (epi->event.events & EPOLLWAKEUP) {
 		error = ep_create_wakeup_source(epi);
 		if (error)
@@ -1329,7 +1322,6 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
 	/* Add the current item to the list of active epoll hook for this file */
 	spin_lock(&tfile->f_lock);
 	list_add_tail_rcu(&epi->fllink, &tfile->f_ep_links);
-	epi->on_list = 1;
 	spin_unlock(&tfile->f_lock);
 
 	/*
@@ -1370,8 +1362,7 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
 
 error_remove_epi:
 	spin_lock(&tfile->f_lock);
-	if (epi->on_list)
-		list_del_rcu(&epi->fllink);
+	list_del_rcu(&epi->fllink);
 	spin_unlock(&tfile->f_lock);
 
 	rb_erase(&epi->rbn, &ep->rbr);
-- 
1.8.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] epoll: remove the on_list check for 'struct epitem'
  2013-10-30 18:32 [PATCH] epoll: remove the on_list check for 'struct epitem' Jason Baron
@ 2013-10-31 23:09 ` Stephen Rothwell
  2013-10-31 23:20   ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Rothwell @ 2013-10-31 23:09 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jason Baron, paulmck, normalperson, nzimmer, viro, nelhage,
	davidel, linux-kernel, linux-fsdevel

[-- Attachment #1: Type: text/plain, Size: 1839 bytes --]

Hi Andrew,

On Wed, 30 Oct 2013 18:32:41 +0000 (GMT) Jason Baron <jbaron@akamai.com> wrote:
>
> By removing the 'int on_list' field from 'struct epitem', we avoid hitting the
> BUILD_BUG_ON() for 'struct epitem' being larger than 128 bytes.
> 
> In file included from include/linux/init.h:4:0,
>                  from fs/eventpoll.c:14:
> fs/eventpoll.c: In function 'eventpoll_init':
> include/linux/compiler.h:321:20: error: call to '__compiletime_assert_2137' declared with attribute error: BUILD_BUG_ON failed: sizeof(void *) <= 8 && sizeof(struct epitem) > 128
>     prefix ## suffix();    \
> 
> The check to make sure that the 'struct epitem' was actually linked via
> epi->fllink was added to avoid having the list removal primitives called twice
> for the same 'struct epitem'. However, the double call possibility was removed
> by 'Subject: epoll: optimize EPOLL_CTL_DEL using rcu'. There, the call to
> 'list_del_init()' in eventpoll_release_file() was removed (we now rely on the
> list delete happening entirely in 'ep_remove()', which is called from
> eventpoll_release_file()).
> 
> There is also the question as to whether multiple ep_remove() calls could
> happen concurrently. This can not happen since EPOLL_CTL_DEL can't
> race with eventpoll_release_file() or ep_free() - it has to do an fget()
> to proceed. Further, eventpoll_release_file() can not race with ep_free(),
> since they both acquire the 'epmutex'.
> 
> Signed-off-by: Jason Baron <jbaron@akamai.com>

Do you want me to put this in my copy of the mmotm instead of reverting
these three?

epoll-do-not-take-global-epmutex-for-simple-topologies-fix
epoll: do not take global 'epmutex' for simple topologies
epoll: optimize EPOLL_CTL_DEL using rcu

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] epoll: remove the on_list check for 'struct epitem'
  2013-10-31 23:09 ` Stephen Rothwell
@ 2013-10-31 23:20   ` Andrew Morton
  2013-10-31 23:32     ` Stephen Rothwell
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2013-10-31 23:20 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: Jason Baron, paulmck, normalperson, nzimmer, viro, nelhage,
	davidel, linux-kernel, linux-fsdevel

On Fri, 1 Nov 2013 10:09:12 +1100 Stephen Rothwell <sfr@canb.auug.org.au> wrote:

> Hi Andrew,
> 
> On Wed, 30 Oct 2013 18:32:41 +0000 (GMT) Jason Baron <jbaron@akamai.com> wrote:
> >
> > By removing the 'int on_list' field from 'struct epitem', we avoid hitting the
> > BUILD_BUG_ON() for 'struct epitem' being larger than 128 bytes.
> > 
> > In file included from include/linux/init.h:4:0,
> >                  from fs/eventpoll.c:14:
> > fs/eventpoll.c: In function 'eventpoll_init':
> > include/linux/compiler.h:321:20: error: call to '__compiletime_assert_2137' declared with attribute error: BUILD_BUG_ON failed: sizeof(void *) <= 8 && sizeof(struct epitem) > 128
> >     prefix ## suffix();    \
> > 
> > The check to make sure that the 'struct epitem' was actually linked via
> > epi->fllink was added to avoid having the list removal primitives called twice
> > for the same 'struct epitem'. However, the double call possibility was removed
> > by 'Subject: epoll: optimize EPOLL_CTL_DEL using rcu'. There, the call to
> > 'list_del_init()' in eventpoll_release_file() was removed (we now rely on the
> > list delete happening entirely in 'ep_remove()', which is called from
> > eventpoll_release_file()).
> > 
> > There is also the question as to whether multiple ep_remove() calls could
> > happen concurrently. This can not happen since EPOLL_CTL_DEL can't
> > race with eventpoll_release_file() or ep_free() - it has to do an fget()
> > to proceed. Further, eventpoll_release_file() can not race with ep_free(),
> > since they both acquire the 'epmutex'.
> > 
> > Signed-off-by: Jason Baron <jbaron@akamai.com>
> 
> Do you want me to put this in my copy of the mmotm instead of reverting
> these three?
> 
> epoll-do-not-take-global-epmutex-for-simple-topologies-fix
> epoll: do not take global 'epmutex' for simple topologies
> epoll: optimize EPOLL_CTL_DEL using rcu

Sure.  Here's my epoll-optimize-epoll_ctl_del-using-rcu-fix.patch:

From: Jason Baron <jbaron@akamai.com>
Subject: epoll: remove the on_list check for 'struct epitem'

By removing the 'int on_list' field from 'struct epitem', we avoid hitting
the BUILD_BUG_ON() for 'struct epitem' being larger than 128 bytes.

In file included from include/linux/init.h:4:0,
                 from fs/eventpoll.c:14:
fs/eventpoll.c: In function 'eventpoll_init':
include/linux/compiler.h:321:20: error: call to '__compiletime_assert_2137' declared with attribute error: BUILD_BUG_ON failed: sizeof(void *) <= 8 && sizeof(struct epitem) > 128
    prefix ## suffix();    \

The check to make sure that the 'struct epitem' was actually linked via
epi->fllink was added to avoid having the list removal primitives called
twice for the same 'struct epitem'.  However, the double call possibility
was removed by 'Subject: epoll: optimize EPOLL_CTL_DEL using rcu'.  There,
the call to 'list_del_init()' in eventpoll_release_file() was removed (we
now rely on the list delete happening entirely in 'ep_remove()', which is
called from eventpoll_release_file()).

There is also the question as to whether multiple ep_remove() calls could
happen concurrently.  This can not happen since EPOLL_CTL_DEL can't race
with eventpoll_release_file() or ep_free() - it has to do an fget() to
proceed.  Further, eventpoll_release_file() can not race with ep_free(),
since they both acquire the 'epmutex'.

Signed-off-by: Jason Baron <jbaron@akamai.com>
Reported-by: Wu Fengguang <fengguang.wu@intel.com>
Cc: Nathan Zimmer <nzimmer@sgi.com>
Cc: Eric Wong <normalperson@yhbt.net>
Cc: Nelson Elhage <nelhage@nelhage.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/eventpoll.c |   13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff -puN fs/eventpoll.c~epoll-optimize-epoll_ctl_del-using-rcu-fix fs/eventpoll.c
--- a/fs/eventpoll.c~epoll-optimize-epoll_ctl_del-using-rcu-fix
+++ a/fs/eventpoll.c
@@ -171,9 +171,6 @@ struct epitem {
 
 	/* The structure that describe the interested events and the source fd */
 	struct epoll_event event;
-
-	/* The fllink is in use. Since rcu can't do 'list_del_init()' */
-	int on_list;
 };
 
 /*
@@ -707,10 +704,7 @@ static int ep_remove(struct eventpoll *e
 
 	/* Remove the current item from the list of epoll hooks */
 	spin_lock(&file->f_lock);
-	if (epi->on_list) {
-		list_del_rcu(&epi->fllink);
-		epi->on_list = 0;
-	}
+	list_del_rcu(&epi->fllink);
 	spin_unlock(&file->f_lock);
 
 	rb_erase(&epi->rbn, &ep->rbr);
@@ -1273,7 +1267,6 @@ static int ep_insert(struct eventpoll *e
 	epi->event = *event;
 	epi->nwait = 0;
 	epi->next = EP_UNACTIVE_PTR;
-	epi->on_list = 0;
 	if (epi->event.events & EPOLLWAKEUP) {
 		error = ep_create_wakeup_source(epi);
 		if (error)
@@ -1307,7 +1300,6 @@ static int ep_insert(struct eventpoll *e
 	/* Add the current item to the list of active epoll hook for this file */
 	spin_lock(&tfile->f_lock);
 	list_add_tail_rcu(&epi->fllink, &tfile->f_ep_links);
-	epi->on_list = 1;
 	spin_unlock(&tfile->f_lock);
 
 	/*
@@ -1348,8 +1340,7 @@ static int ep_insert(struct eventpoll *e
 
 error_remove_epi:
 	spin_lock(&tfile->f_lock);
-	if (epi->on_list)
-		list_del_rcu(&epi->fllink);
+	list_del_rcu(&epi->fllink);
 	spin_unlock(&tfile->f_lock);
 
 	rb_erase(&epi->rbn, &ep->rbr);
_


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] epoll: remove the on_list check for 'struct epitem'
  2013-10-31 23:20   ` Andrew Morton
@ 2013-10-31 23:32     ` Stephen Rothwell
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Rothwell @ 2013-10-31 23:32 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jason Baron, paulmck, normalperson, nzimmer, viro, nelhage,
	davidel, linux-kernel, linux-fsdevel

[-- Attachment #1: Type: text/plain, Size: 383 bytes --]

Hi Andrew,

On Thu, 31 Oct 2013 16:20:19 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
>
> Sure.  Here's my epoll-optimize-epoll_ctl_del-using-rcu-fix.patch:
> 
> From: Jason Baron <jbaron@akamai.com>
> Subject: epoll: remove the on_list check for 'struct epitem'

OK, that will go in today.
-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-31 23:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-30 18:32 [PATCH] epoll: remove the on_list check for 'struct epitem' Jason Baron
2013-10-31 23:09 ` Stephen Rothwell
2013-10-31 23:20   ` Andrew Morton
2013-10-31 23:32     ` Stephen Rothwell

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).