From patchwork Wed Jul 12 16:42:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Yang X-Patchwork-Id: 13310761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7526AC0015E for ; Wed, 12 Jul 2023 16:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231601AbjGLQnG (ORCPT ); Wed, 12 Jul 2023 12:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233171AbjGLQm6 (ORCPT ); Wed, 12 Jul 2023 12:42:58 -0400 Received: from out203-205-251-84.mail.qq.com (unknown [203.205.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF46411B; Wed, 12 Jul 2023 09:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1689180157; bh=XS7uVyxvyErmeOipAo/I8ZO89hZtODJtc8bPKLUEKT0=; h=From:To:Cc:Subject:Date; b=Lq+UVddJnobpDppQFwRdLVwvauHhnIaV0sMxZhOUUb5mDGWxCC/gkLglm9xVNvrXY HLpP2+J2E1KYTwNKlpz9ZrGKl6/2HVrusve5TWuHduH3vWYID1ecUYD+zF/dgM9ZDY QJ44rrKHFNdOC9sNoEDyI4V+iEu7Vn6DFVSN5TN8= Received: from localhost.localdomain ([240e:331:c33:db00:13e0:d3eb:116f:835c]) by newxmesmtplogicsvrsza12-0.qq.com (NewEsmtp) with SMTP id AA205AB9; Thu, 13 Jul 2023 00:42:34 +0800 X-QQ-mid: xmsmtpt1689180154t1hg5njof Message-ID: X-QQ-XMAILINFO: My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enyang.linux@foxmail.com To: Alexander Viro , Jens Axboe , Christian Brauner Cc: Wen Yang , Christoph Hellwig , Dylan Yudaken , David Woodhouse , Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] eventfd: avoid unnecessary wakeups in eventfd_write() Date: Thu, 13 Jul 2023 00:42:32 +0800 X-OQ-MSGID: <20230712164232.121991-1-wenyang.linux@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Wen Yang In eventfd_write(), when ucnt is 0 and ctx->count is also 0, current->in_eventfd will be set to 1, which may affect eventfd_signal(), and unnecessary wakeups will also be performed. Fix this issue by ensuring that ctx->count is not zero. Signed-off-by: Wen Yang Cc: Alexander Viro Cc: Jens Axboe Cc: Christian Brauner Cc: Christoph Hellwig Cc: Dylan Yudaken Cc: David Woodhouse Cc: Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- fs/eventfd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/eventfd.c b/fs/eventfd.c index 33a918f9566c..254b18ff0e00 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c @@ -281,10 +281,12 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c } if (likely(res > 0)) { ctx->count += ucnt; - current->in_eventfd = 1; - if (waitqueue_active(&ctx->wqh)) - wake_up_locked_poll(&ctx->wqh, EPOLLIN); - current->in_eventfd = 0; + if (ctx->count) { + current->in_eventfd = 1; + if (waitqueue_active(&ctx->wqh)) + wake_up_locked_poll(&ctx->wqh, EPOLLIN); + current->in_eventfd = 0; + } } spin_unlock_irq(&ctx->wqh.lock);