From patchwork Wed Jan 11 05:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia Zhu X-Patchwork-Id: 41756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3142822wrt; Tue, 10 Jan 2023 21:42:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXv3GJ+Zij1oCt2x6W4FvqoUO/jra0sqUPGIH1H4xLBi3xgBelBGzpWFORD7aoEYjUEspghm X-Received: by 2002:aa7:d689:0:b0:46c:3f90:f5d9 with SMTP id d9-20020aa7d689000000b0046c3f90f5d9mr60506860edr.5.1673415737405; Tue, 10 Jan 2023 21:42:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673415737; cv=none; d=google.com; s=arc-20160816; b=dIOG6FtZgvafuykghKOTWL23G555d1sGXGrWvs8YNhwSiwDdSITuy7uRAJZIjvIRWX Q0evNTmA12IXxGap7wvUUQ8klsBvE1ise/Z3O3swM3LydVdBUudHLvTghApsJWHBfgP1 W6sBtFMlzk8Pt4w/s6fUn578AuHl92215UYb+Id/VIGH1V+3O1UGNKmsY4hmbrgLKhZC WR2No6Lh81c1bk0kiYq0YFer787oD0AAX1HlN6XhCKzdGgctVPZCIug35NCX3W06AZoD fLcHmIph6zk89WG3Z6gxEbuTO701tCxox+TWMnBvZP+kBnBa1DEHIwjors3QpIli90Sv 9X9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pDYD8kdF4QcIxV+XVTzksOOF3bsvD3XSTsyoZ+oU6es=; b=PyvfF63yCQxU9aevZhZjetD8KHqtKFNhsk+ZEkLo67fRwPMsFna+5eWrtjFJjXg4LR +SR2jBOma0OmxpZm9q0ofnUeDIblYTZ1heCBdK56vJKuFVvyu2SuR5mGkYD/8tNcyMCC cBTCC4W0BZKb8kyIBoEXgDVrocx3aTZy8wNwZQC4sgrvjTCBM0Aiag1B+eUECaox04aB x0fs2c2f8NI1wSVbBrkwswL0cMNS2ZMahxQh3Brb41JW6pLFyF2G3gUIaCb5O+SeJPYD 5iL+65yZg8SblptRuwNnrAdtQGKiTtMYDEsW8sUzn6Jy9Y/AvI6OA+0ldALkAQf7qmZZ pr2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=OmLcznBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a056402084b00b0046721c5b7e0si16342812edz.511.2023.01.10.21.41.50; Tue, 10 Jan 2023 21:42:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=OmLcznBU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbjAKFhK (ORCPT + 99 others); Wed, 11 Jan 2023 00:37:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjAKFgf (ORCPT ); Wed, 11 Jan 2023 00:36:35 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 082A53C722 for ; Tue, 10 Jan 2023 21:25:40 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id n12so14733132pjp.1 for ; Tue, 10 Jan 2023 21:25:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pDYD8kdF4QcIxV+XVTzksOOF3bsvD3XSTsyoZ+oU6es=; b=OmLcznBUhwb6V7Iv7/A44e+lcoabUFSifrsud2HZbjVV7xNimVZi/xOnDXpfOVYkOV 0pgBY+uBOAHtdIjKnohFMo4hqlkBl9ZHyeqyzBaySzyKorNmjJiUSWtNAu1MnThr9bZ0 03dCX3pZ6EOLf0aI13y7Ym+iM2d6scbetEoZSNrRqLYPoVSFETLAuGx1cNfb9JjnrSTc mT157ARyhoes8Nqvpe4yrO/lbpCdnXgoypUyCK5igRGq+PUyXMi/WFxz99+plbto03cw sJIne/4ds8ktscqloKaTaaJHVs23pSHwZOS/mCkjRrjfeSok1V4aNUnBCpmKLtHysNCz qxbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pDYD8kdF4QcIxV+XVTzksOOF3bsvD3XSTsyoZ+oU6es=; b=Zy6aaJnJjUuJ7XbdeIknIobbkEg34wMIuPhkZNCeZc3WJS/KS53ofaJlpC3b5aog/I tzS+KbARl+D9FjhXlTv6QeFwu0iTtA9djaruvqso/JnIao2AlkowuECYSECxEPr2elbF lGZMfn/jCxkuRPIf6ofnGOsS2yIUOGR5t9wQAyIrr40BlqjjqD0gEjmCbnFdvHTFTo/x ZPBvIscdffgujBmyU88etqSqmu6m6eKicBHgTx/dRZ5WH4vpHICg8wwHLBoNtuUI0nEI 9ubryGXaT4/fXE6Zw7CC71JCZKkR8B4c7gQUF4yYpykAvW2+gKfX1nRqwqWY3jGh+DOu /X6w== X-Gm-Message-State: AFqh2kqQOSdm/K+15suI2Vkys6g78lbqOqazaHGyZR5joqkoTDY37+DS lMpDHIxFNoNWZKWCOy3xV1ZXaWrs21ygj0mD X-Received: by 2002:a17:902:968d:b0:192:8d74:99e0 with SMTP id n13-20020a170902968d00b001928d7499e0mr46324926plp.4.1673414739479; Tue, 10 Jan 2023 21:25:39 -0800 (PST) Received: from C02G705SMD6V.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id l10-20020a170903244a00b0019334350ce6sm4934520pls.244.2023.01.10.21.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:25:39 -0800 (PST) From: Jia Zhu To: dhowells@redhat.com Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhu , Xin Yin , Jingbo Xu Subject: [PATCH V4 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode Date: Wed, 11 Jan 2023 13:25:14 +0800 Message-Id: <20230111052515.53941-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230111052515.53941-1-zhujia.zj@bytedance.com> References: <20230111052515.53941-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754703580699123730?= X-GMAIL-MSGID: =?utf-8?q?1754703580699123730?= Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/cachefiles/daemon.c | 15 +++++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e3..b8d8f280fb7a 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -355,14 +355,25 @@ static __poll_t cachefiles_daemon_poll(struct file *file, struct poll_table_struct *poll) { struct cachefiles_cache *cache = file->private_data; + struct xarray *xa = &cache->reqs; + struct cachefiles_req *req; + unsigned long index; __poll_t mask; poll_wait(file, &cache->daemon_pollwq, poll); mask = 0; if (cachefiles_in_ondemand_mode(cache)) { - if (!xa_empty(&cache->reqs)) - mask |= EPOLLIN; + if (!xa_empty(xa)) { + xa_lock(xa); + xa_for_each_marked(xa, index, req, CACHEFILES_REQ_NEW) { + if (!cachefiles_ondemand_is_reopening_read(req)) { + mask |= EPOLLIN; + break; + } + } + xa_unlock(xa); + } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) mask |= EPOLLIN; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 2ed836d4169e..3d94990a8b38 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -326,6 +326,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open); CACHEFILES_OBJECT_STATE_FUNCS(close); CACHEFILES_OBJECT_STATE_FUNCS(reopening); + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return cachefiles_ondemand_object_is_reopening(req->object) && + req->msg.opcode == CACHEFILES_OP_READ; +} + #else static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, char __user *_buffer, size_t buflen) @@ -353,6 +360,11 @@ static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *ob { return 0; } + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return false; +} #endif /*