[PATCH 1/2] fdmon-poll: reset npfd when upgrading to fdmon-epoll

Stefan Hajnoczi posted 2 patches 5 years, 5 months ago
[PATCH 1/2] fdmon-poll: reset npfd when upgrading to fdmon-epoll
Posted by Stefan Hajnoczi 5 years, 5 months ago
npfd keeps track of how many pollfds are currently being monitored. It
must be reset to 0 when fdmon_poll_wait() returns.

When npfd reaches a treshold we switch to fdmon-epoll because it scales
better.

This patch resets npfd in the case where we switch to fdmon-epoll.
Forgetting to do so results in the following assertion failure:

  util/fdmon-poll.c:65: fdmon_poll_wait: Assertion `npfd == 0' failed.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1869952
Fixes: 1f050a4690f62a1e7dabc4f44141e9f762c3769f ("aio-posix: extract ppoll(2) and epoll(7) fd monitoring")
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 util/fdmon-poll.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util/fdmon-poll.c b/util/fdmon-poll.c
index 488067b679..5fe3b47865 100644
--- a/util/fdmon-poll.c
+++ b/util/fdmon-poll.c
@@ -73,6 +73,7 @@ static int fdmon_poll_wait(AioContext *ctx, AioHandlerList *ready_list,
 
     /* epoll(7) is faster above a certain number of fds */
     if (fdmon_epoll_try_upgrade(ctx, npfd)) {
+        npfd = 0; /* we won't need pollfds[], reset npfd */
         return ctx->fdmon_ops->wait(ctx, ready_list, timeout);
     }
 
-- 
2.26.2

Re: [PATCH 1/2] fdmon-poll: reset npfd when upgrading to fdmon-epoll
Posted by Philippe Mathieu-Daudé 5 years, 5 months ago
On 8/21/20 12:12 PM, Stefan Hajnoczi wrote:
> npfd keeps track of how many pollfds are currently being monitored. It
> must be reset to 0 when fdmon_poll_wait() returns.
> 
> When npfd reaches a treshold we switch to fdmon-epoll because it scales
> better.
> 
> This patch resets npfd in the case where we switch to fdmon-epoll.
> Forgetting to do so results in the following assertion failure:
> 
>   util/fdmon-poll.c:65: fdmon_poll_wait: Assertion `npfd == 0' failed.
> 
> Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1869952
> Fixes: 1f050a4690f62a1e7dabc4f44141e9f762c3769f ("aio-posix: extract ppoll(2) and epoll(7) fd monitoring")
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  util/fdmon-poll.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/util/fdmon-poll.c b/util/fdmon-poll.c
> index 488067b679..5fe3b47865 100644
> --- a/util/fdmon-poll.c
> +++ b/util/fdmon-poll.c
> @@ -73,6 +73,7 @@ static int fdmon_poll_wait(AioContext *ctx, AioHandlerList *ready_list,
>  
>      /* epoll(7) is faster above a certain number of fds */
>      if (fdmon_epoll_try_upgrade(ctx, npfd)) {
> +        npfd = 0; /* we won't need pollfds[], reset npfd */
>          return ctx->fdmon_ops->wait(ctx, ready_list, timeout);
>      }
>  
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>