Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp847018rwe; Fri, 14 Apr 2023 10:25:10 -0700 (PDT) X-Google-Smtp-Source: AKy350YvFa+DGlRycjBrgVeVV0gW17hvDgE9pv0eVK9c5I8O/RPI9T7+AD1Oez7E1mSlkdK6iSLm X-Received: by 2002:a17:90a:2c05:b0:247:1e1e:57c0 with SMTP id m5-20020a17090a2c0500b002471e1e57c0mr6489408pjd.14.1681493110306; Fri, 14 Apr 2023 10:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681493110; cv=none; d=google.com; s=arc-20160816; b=xgah6s8PKpdiqfkHTTAttUByjVQkYySkyfwRYQuq8glK4VeVe2kTGhniWkxN1Wd49S PGZuIsbW8NIsi1MW0+4Z/TXPytpc5jJNRo6F2g6y9o46TLcVS231X4zkgszWUr8AlJM0 HjpVij18pAIyAz2JVc7SvarLHuR29IDHx0RgF4R6YXSv2HkuQw2je55noOERgnAwESw9 umSi5+oKv2a3UHjrCq4nb8/eVGZc1Ysi3aTwzLPWZfQsyIm1Xwi6Xv04C4hxBS2pedci X4YIgYzh6nC5fv4Aq4HsIJrCkTkeXo13ieuujUEMFwG9II0Wc2M+kZR/PswWwH7+enlY Bodg== 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=jLxzEPuRQOpnZLaEq6SfAsMRmsFnFoLhYkxVpQU9ODc=; b=e44PAepvDHfFrLL/9Ann5WCak4Co4+FtNw4YQTQan0E5hGPm5QtWLwgXI0JvWBfckR 7B4eW4CwS/cixpHy4GOYx2iAO3eCxizVfQuZ8VZGcIE9oriCYaUpxcsIGFuxVaNamLA7 cMX/f2FfSi8jsQPZymO9zzw/yGDKmEXgW2VflsGv6AuH+VEF9sHRua/sktV15JsWOyrE FX9r2cuNQIWK/576khivlJMA8NPNfUVORO7Jwq3jiQeIDeziCOY5shm3PxvSI8LymFRa sXDb7b5YsH/uUSJOAQPe0ztYv2u2pMiP1222Yet+0JmuJWIiTK80SFDyiwGDLkQkXwzN EMVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=BRc8Yf2c; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a17090a6e4600b0024686879af0si7655973pjm.169.2023.04.14.10.24.56; Fri, 14 Apr 2023 10:25:10 -0700 (PDT) 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 header.s=google header.b=BRc8Yf2c; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230027AbjDNRXm (ORCPT + 99 others); Fri, 14 Apr 2023 13:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjDNRXk (ORCPT ); Fri, 14 Apr 2023 13:23:40 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0959AD2D for ; Fri, 14 Apr 2023 10:23:33 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id y11-20020a17090a600b00b0024693e96b58so18264622pji.1 for ; Fri, 14 Apr 2023 10:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681493013; x=1684085013; 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=jLxzEPuRQOpnZLaEq6SfAsMRmsFnFoLhYkxVpQU9ODc=; b=BRc8Yf2ckf5lO1OvMNsi2GkZVI1sUHHIDltwlGPKACNCk2hxZYP/2q9ufEFgfGe1Or xu4A8QcOoUfxEbg2hhp7/ABNsHHUmPVfdSW6w+bSy1/eAwuabrxosHFmZprBL+3okRGB jFUBYONWr5DWLd5EzT82YnoOYRtfeVPw3ykOmYXtk59XYAa7kM2DcIJNbMnvZWrN2VsO sNpcT7ALv+c0DAvVkTbO+7v5ixjLbGDC54ch1VQiLWOKbryDhpiVBCpBpXONm36qMKDN umkVSBDGT5zvnuhKVqqetE4d0+mbpfT1lH0hjGbZvIWkAkfy4cWGt4GMiwjhyD56ljra Om0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681493013; x=1684085013; 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=jLxzEPuRQOpnZLaEq6SfAsMRmsFnFoLhYkxVpQU9ODc=; b=OEXU5wGnNKfynb7PAfEL8PisRjYl239CTLNM4bW6a7iJ9dTjd6jDdvbeOONnWZNRYv snNbizVs0gH01BDnqikmYIZOYJq55Y+AotQFs+h2yewmAFpRexCp9ne6lU8s9oCfxReF evY0Nk2vDe5d5JCDZ8ATK0pp5/gnTbHghDE/HFieqltb88xp2B5yJ+O4A+6mnmSZ/vZW 8gU1m7D8iPFn6mVITjNWZQ9BF6Dm69bsbiCfSH7e6Y6Dg5hQ0TZ+cQBaNmIXFvAgaGE/ FH1cbq8fTESXL79L8UKa4A67lqRACs6hemGFQjpNvvnTfle1YK8jSZBixpKxD3//3Jq5 z67w== X-Gm-Message-State: AAQBX9fJ/m0p9A0H8ouKTLCZiupYl+S933NZN1EdTaqxBZUgCnNSh+ZV p+JD47qhEiKT2Plsm1oPzkv5Zg== X-Received: by 2002:a05:6a20:7347:b0:ee:818a:3497 with SMTP id v7-20020a056a20734700b000ee818a3497mr1941553pzc.35.1681493013176; Fri, 14 Apr 2023 10:23:33 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id q12-20020a631f4c000000b0051b8172fa68sm370315pgm.38.2023.04.14.10.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:23:32 -0700 (PDT) From: Jia Zhu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, jefflexu@linux.alibaba.com, hsiangkao@linux.alibaba.com, Jia Zhu , Xin Yin Subject: [PATCH V6 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode Date: Sat, 15 Apr 2023 01:22:38 +0800 Message-Id: <20230414172239.33743-5-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230414172239.33743-1-zhujia.zj@bytedance.com> References: <20230414172239.33743-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu --- fs/cachefiles/daemon.c | 14 ++++++++++++-- fs/cachefiles/internal.h | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index aa4efcabb5e37..70caa1946207d 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -355,14 +355,24 @@ static __poll_t cachefiles_daemon_poll(struct file *file, struct poll_table_struct *poll) { struct cachefiles_cache *cache = file->private_data; + XA_STATE(xas, &cache->reqs, 0); + struct cachefiles_req *req; __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(&cache->reqs)) { + rcu_read_lock(); + xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) { + if (!cachefiles_ondemand_is_reopening_read(req)) { + mask |= EPOLLIN; + break; + } + } + rcu_read_unlock(); + } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) mask |= EPOLLIN; diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index b9a90f1a0c015..26e5f8f123ef1 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -329,6 +329,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \ CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN); CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE); CACHEFILES_OBJECT_STATE_FUNCS(reopening, 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) @@ -359,6 +366,11 @@ static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *ob static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj) { } + +static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req) +{ + return false; +} #endif /* -- 2.20.1