Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp309880pxa; Thu, 27 Aug 2020 03:01:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg2bT0ykU/gq3+61ZkDDwuaiEMUZbXrVjk/eEMZlfGYds3bYGX0aSqEtmjBzQP86v5T6/Y X-Received: by 2002:a17:906:341b:: with SMTP id c27mr20595528ejb.32.1598522492538; Thu, 27 Aug 2020 03:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598522492; cv=none; d=google.com; s=arc-20160816; b=kJf5HGHxdKuykKJ7NEYRvkqiqgHYQ7mYxKq/cO25HBj7ONNMCGWiOhLznA9+r0NU4y HXyCIJTDm843+5GrY14IlzrOwuOj3Z7HPi443t0y6NEIN950k9oT5GcO+UOoJ735uGYU lDCgnARmpmyX+Mj3KHklrE0lctYuFsHZiYcg4PVP2sZfMp8tw5whPu0wQxOgv4fPHPES kdBNMK66WnP/5wbihwJHOTfz+AOyGo+7GNd62ElGfnFjlY4AzUCVaUaYfAXDeWgt5/91 UPb7gEoGMQydFRMQnE7v9QZK7b6DJ8sN2M1zSu3fbBf+i3UvD81jYPpLk6pKvb2qNzIx i5eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=nDNbaHsN0XxcDx8URrK9xVQ+ckDa3KiHAlVUgGFzPzw=; b=OFj97KG2Br9ZPWr0Ri1cftsHQkk0q44kfyYXVf4Y3LKkYRzadhgfGGaIoKEDqOaiJJ FbQ0j2NqYDWUfs6++a1UQmjCZA90XVMiwh6zC+NVPxuuLi6uTvNVjzWJMM0TD46jbSs8 ik/dQEKk3hlII2ENSh5uRU+1TyI9bHsETz5CTetIji93p2Pe4OkuhErRamvW0tY8vf4s BmazQJb0vNUHQsa1MKEQJT9d6I4rcGKZ0Fkf5whL5q1GQLqh/Y9NgHpcNMwfxTOWBYil 17wV20TYlVd/btHxmfGKR56rdSJVhZKj179s7VXXgsOFRgOTtm6+Q0nNIGERGsepCWb3 Bvuw== 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 gr4si969069ejb.723.2020.08.27.03.01.09; Thu, 27 Aug 2020 03:01:32 -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 S1728384AbgH0J6R (ORCPT + 99 others); Thu, 27 Aug 2020 05:58:17 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:51235 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726093AbgH0J6O (ORCPT ); Thu, 27 Aug 2020 05:58:14 -0400 X-IronPort-AV: E=Sophos;i="5.76,359,1592841600"; d="scan'208";a="98621923" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Aug 2020 17:58:10 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id E5A1F48990D7; Thu, 27 Aug 2020 17:58:08 +0800 (CST) Received: from [10.167.225.206] (10.167.225.206) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 27 Aug 2020 17:58:09 +0800 Subject: Re: [PATCH] fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set To: Dave Chinner CC: , , , References: <20200821015953.22956-1-lihao2018.fnst@cn.fujitsu.com> <20200827063748.GA12096@dread.disaster.area> From: "Li, Hao" Message-ID: <6b3b3439-2199-8f00-ceca-d65769e94fe0@cn.fujitsu.com> Date: Thu, 27 Aug 2020 17:58:07 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.1.1 MIME-Version: 1.0 In-Reply-To: <20200827063748.GA12096@dread.disaster.area> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.167.225.206] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: E5A1F48990D7.AD97A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lihao2018.fnst@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/27 14:37, Dave Chinner wrote: > On Fri, Aug 21, 2020 at 09:59:53AM +0800, Hao Li wrote: >> Currently, DCACHE_REFERENCED prevents the dentry with DCACHE_DONTCACHE >> set from being killed, so the corresponding inode can't be evicted. If >> the DAX policy of an inode is changed, we can't make policy changing >> take effects unless dropping caches manually. >> >> This patch fixes this problem and flushes the inode to disk to prepare >> for evicting it. >> >> Signed-off-by: Hao Li >> --- >> fs/dcache.c | 3 ++- >> fs/inode.c | 2 +- >> 2 files changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/fs/dcache.c b/fs/dcache.c >> index ea0485861d93..486c7409dc82 100644 >> --- a/fs/dcache.c >> +++ b/fs/dcache.c >> @@ -796,7 +796,8 @@ static inline bool fast_dput(struct dentry *dentry) >> */ >> 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; > Seems reasonable, but you need to update the comment above as to > how this flag fits into this code.... Yes. I will change it. Thanks. > >> /* Nothing to do? Dropping the reference was all we needed? */ >> if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry)) >> diff --git a/fs/inode.c b/fs/inode.c >> index 72c4c347afb7..5218a8aebd7f 100644 >> --- a/fs/inode.c >> +++ b/fs/inode.c >> @@ -1632,7 +1632,7 @@ static void iput_final(struct inode *inode) >> } >> >> state = inode->i_state; >> - if (!drop) { >> + if (!drop || (drop && (inode->i_state & I_DONTCACHE))) { >> WRITE_ONCE(inode->i_state, state | I_WILL_FREE); >> spin_unlock(&inode->i_lock); > What's this supposed to do? We'll only get here with drop set if the > filesystem is mounting or unmounting. The variable drop will also be set to True if I_DONTCACHE is set on inode->i_state. Although mounting/unmounting will set the drop variable, it won't set I_DONTCACHE if I understand correctly. As a result, drop && (inode->i_state & I_DONTCACHE) will filter out mounting/unmounting. > In either case, why does > having I_DONTCACHE set require the inode to be written back here > before it is evicted from the cache? Mounting/unmounting won't execute the code snippet which is in that if statement, as I have explained above. However, If I_DONTCACHE is set, we have to execute this snippet to write back inode. I_DONTCACHE is set in d_mark_dontcache() which will be called in two situations: 1. DAX policy is changed. 2. The inode is read through bulkstat in XFS. See commit 5132ba8f2b77 ("xfs: don't cache inodes read through bulkstat") for more details. For the first case, we have to write back the inode together with its dirty pages before evicting. For the second case, I think it's also necessary to write back inode before evicting. Thanks, Hao Li > > Cheers, > > Dave.