Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp73560pxk; Wed, 23 Sep 2020 23:08:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE1KFiK1oCS2s8WXc15E5EBkOBr14C2hnD/kea0N44FV2dA4xBC4OSAvIWbbWnIhYJsEY4 X-Received: by 2002:a50:9fa1:: with SMTP id c30mr2773656edf.207.1600927687324; Wed, 23 Sep 2020 23:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600927687; cv=none; d=google.com; s=arc-20160816; b=AgSfdDqujwx5/8Mf0zfO5gQ7nGspJAGYe492Gt9bOfP70VQUBCOFUE4swshUVBzX3F 6idDPOo5iBJ13ceCrb+UEbG3kkBgJgbEl7KL0bFw6KdlGD8WnfiLRLtilZw6aXPecxX8 RVSgHEY5Oashtpgeak7yr95SMEcpDeZEvKsDE9q2JBhCCC2bE8zZIkIbp1Qpbnv6zIKZ BVY/C/XjISOsuZ81bcSCKPFMR2tDkh7G8KJajHHpkKRoMMg3PrU5VAnLjPKPPZnVtQGs pHsu9NbiVBa9c+zdewtHJxEGAinLVliBuP96gJdwfyiUPO2f+hEhpYC6GHzBvpHmYJfe 7mVA== 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 :message-id:date:subject:cc:to:from; bh=kBeF83bzpxN5d0SbXRaKK1IuG5BSrkPCFLuK9vHduTU=; b=CbPCDar8vkQGoHzEnRroQ/zBhnFoc2KUje7fZyp+H7nJWPj8Vmh34Q+ZfvGnGGyTzg la8/OPEAW3c7uqKYrezQ7QaW5x94e8jQNoUdp9sZwAT5uqrrir4Rk2dFvVwzZLvl5Czi SS8V1upl15COG6ROInB5l/1LjPAvEr4Ri+TS7EuCvx++8yfWjzKs9uv3tAeKMGK9JdjT OhZFhrFl7kQYkjZ51coA0iqRZKZ4H29SsUVSRfFHcNd2y3g0bv+f9UAnUlBeEK9Po0W/ SoeUwKqJZ4cIUEUWrI2NqEX/uFjUFKAAGI5tInAcT5HdF0CMg/CzmMTljczrr9dyto4B oMsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x23si1293316ejj.642.2020.09.23.23.07.29; Wed, 23 Sep 2020 23:08:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726844AbgIXGAG (ORCPT + 99 others); Thu, 24 Sep 2020 02:00:06 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:41129 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726799AbgIXGAG (ORCPT ); Thu, 24 Sep 2020 02:00:06 -0400 X-IronPort-AV: E=Sophos;i="5.77,296,1596470400"; d="scan'208";a="99567075" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Sep 2020 14:00:02 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id 0A1AF48990E8; Thu, 24 Sep 2020 14:00:01 +0800 (CST) Received: from G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 24 Sep 2020 13:59:58 +0800 Received: from localhost.localdomain (10.167.225.206) by G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 24 Sep 2020 13:59:58 +0800 From: Hao Li To: , CC: , , , , , Subject: [PATCH v2] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set Date: Thu, 24 Sep 2020 13:59:58 +0800 Message-ID: <20200924055958.825515-1-lihao2018.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 0A1AF48990E8.ADB91 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lihao2018.fnst@cn.fujitsu.com X-Spam-Status: No Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If DCACHE_REFERENCED is set, fast_dput() will return true, and then retain_dentry() have no chance to check DCACHE_DONTCACHE. As a result, the dentry won't be killed and the corresponding inode can't be evicted. In the following example, the DAX policy can't take effects unless we do a drop_caches manually. # DCACHE_LRU_LIST will be set echo abcdefg > test.txt # DCACHE_REFERENCED will be set and DCACHE_DONTCACHE can't do anything xfs_io -c 'chattr +x' test.txt # Drop caches to make DAX changing take effects echo 2 > /proc/sys/vm/drop_caches What this patch does is preventing fast_dput() from returning true if DCACHE_DONTCACHE is set. Then retain_dentry() will detect the DCACHE_DONTCACHE and will return false. As a result, the dentry will be killed and the inode will be evicted. In this way, if we change per-file DAX policy, it will take effects automatically after this file is closed by all processes. I also add some comments to make the code more clear. Signed-off-by: Hao Li --- v1 is split into two standalone patch as discussed in [1], and the first patch has been reviewed in [2]. This is the second patch. [1]: https://lore.kernel.org/linux-fsdevel/20200831003407.GE12096@dread.disaster.area/ [2]: https://lore.kernel.org/linux-fsdevel/20200906214002.GI12131@dread.disaster.area/ fs/dcache.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/dcache.c b/fs/dcache.c index ea0485861d93..97e81a844a96 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -793,10 +793,17 @@ static inline bool fast_dput(struct dentry *dentry) * a reference to the dentry and change that, but * our work is done - we can leave the dentry * around with a zero refcount. + * + * Nevertheless, there are two cases that we should kill + * the dentry anyway. + * 1. free disconnected dentries as soon as their refcount + * reached zero. + * 2. free dentries if they should not be cached. */ smp_rmb(); d_flags = READ_ONCE(dentry->d_flags); - d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | DCACHE_DISCONNECTED; + d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | + DCACHE_DISCONNECTED | DCACHE_DONTCACHE; /* Nothing to do? Dropping the reference was all we needed? */ if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry)) -- 2.28.0