Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp356835ybd; Fri, 28 Jun 2019 21:41:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4sjWVXRTYogR5kFckr45JfobGgOpziRAVu5b9niGo5xa8vTQdXMi1ZeTtlZwNU7zdGy+e X-Received: by 2002:a17:902:2a27:: with SMTP id i36mr15470963plb.161.1561783262441; Fri, 28 Jun 2019 21:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561783262; cv=none; d=google.com; s=arc-20160816; b=mDcZ6gzckCXGt31FMeelSuq84yZdjwdbLdkE77udg4b0NHNM1J58S4a6iVVP2518YS lpKmK0YmLrw6yJczUohO9tZPXKJD2Vwyd3otInNDe7e7kWlhpbkwTn4cX1b9i5VeXPP5 Nb78HPZL2JECBCQdgSj2ZyHn4G0P5RBzggYHRXzs/fzZ90dFEn8e1q7RNV+hXv7BUUCq XYvjBnHopLQWPQ6FaPiFQFcRyWsCoITA5I0IkpDyuCeC/lRjUxPpsiOIh6GVZHEaYJTU DHPq9+kQcFV5526TXxzJ6fLfdwjOF/Zg4f1Z+ztVdsEib8lX7jnzY5NRixrgqMzA57um 1oBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=7X2W3Oissv5OiKS46GmHz0NE2MD/ntnmf9adwVaIXfc=; b=BRWhtWF3rK2UdxaOW4J5JTVh5yO+PKJy0A6mngBFViytd5mo9s8bElO/OaSO6sRkWr VRNB+/v77hnl9hdGkqFb/hfBVS5JJrRfkgvcaGZcqbXh8eiSm3yCltbKGpS7J3AeSDgd ARlF66uGVWReQHKz/OkoLqM0+ww9lOcQ/UW3LJVs4pYffKz99zzs1XboGm5A9YUKk8bW 9O+h4ukzC15vsUADnxzP69HNwMTw7nUi79t26mQRsLrNidR10XXBG+l2kH7GuKack4Vz I/DsIGBSUqDYWf6tUCMkIFgkAXH68/9hh3MrybNuz3mMvU8fCodQmmqIykqn5KnOARCJ 4qXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z9si4006675pju.2.2019.06.28.21.40.14; Fri, 28 Jun 2019 21:41:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726708AbfF2Ei0 (ORCPT + 99 others); Sat, 29 Jun 2019 00:38:26 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:50240 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725799AbfF2Ei0 (ORCPT ); Sat, 29 Jun 2019 00:38:26 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1hh57j-0003uX-CH; Sat, 29 Jun 2019 04:38:03 +0000 Date: Sat, 29 Jun 2019 05:38:03 +0100 From: Al Viro To: Linus Torvalds Cc: "Tobin C. Harding" , Andrew Morton , Roman Gushchin , Alexander Viro , Christoph Hellwig , Pekka Enberg , David Rientjes , Joonsoo Kim , Christopher Lameter , Matthew Wilcox , Miklos Szeredi , Andreas Dilger , Waiman Long , Tycho Andersen , Theodore Ts'o , Andi Kleen , David Chinner , Nick Piggin , Rik van Riel , Hugh Dickins , Jonathan Corbet , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds Subject: shrink_dentry_list() logics change (was Re: [RFC PATCH v3 14/15] dcache: Implement partial shrink via Slab Movable Objects) Message-ID: <20190629043803.GT17978@ZenIV.linux.org.uk> References: <20190411013441.5415-1-tobin@kernel.org> <20190411013441.5415-15-tobin@kernel.org> <20190411023322.GD2217@ZenIV.linux.org.uk> <20190411024821.GB6941@eros.localdomain> <20190411044746.GE2217@ZenIV.linux.org.uk> <20190411210200.GH2217@ZenIV.linux.org.uk> <20190629040844.GS17978@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190629040844.GS17978@ZenIV.linux.org.uk> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 29, 2019 at 05:08:44AM +0100, Al Viro wrote: > > The reason we don't hit that problem with regular memory shrinker is > > this: > > unregister_shrinker(&s->s_shrink); > > fs->kill_sb(s); > > in deactivate_locked_super(). IOW, shrinker for this fs is gone > > before we get around to shutdown. And so are all normal sources > > of dentry eviction for that fs. > > > > Your earlier variants all suffer the same problem - picking a page > > shared by dentries from several superblocks can run into trouble > > if it overlaps with umount of one of those. PS: the problem is not gone in the next iteration of the patchset in question. The patch I'm proposing (including dput_to_list() and _ONLY_ compile-tested) follows. Comments? diff --git a/fs/dcache.c b/fs/dcache.c index 8136bda27a1f..dfe21a649c96 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -860,6 +860,32 @@ void dput(struct dentry *dentry) } EXPORT_SYMBOL(dput); +static void __dput_to_list(struct dentry *dentry, struct list_head *list) +__must_hold(&dentry->d_lock) +{ + if (dentry->d_flags & DCACHE_SHRINK_LIST) { + /* let the owner of the list it's on deal with it */ + --dentry->d_lockref.count; + } else { + if (dentry->d_flags & DCACHE_LRU_LIST) + d_lru_del(dentry); + if (!--dentry->d_lockref.count) + d_shrink_add(dentry, list); + } +} + +void dput_to_list(struct dentry *dentry, struct list_head *list) +{ + rcu_read_lock(); + if (likely(fast_dput(dentry))) { + rcu_read_unlock(); + return; + } + rcu_read_unlock(); + if (!retain_dentry(dentry)) + __dput_to_list(dentry, list); + spin_unlock(&dentry->d_lock); +} /* This must be called with d_lock held */ static inline void __dget_dlock(struct dentry *dentry) @@ -1088,18 +1114,9 @@ static void shrink_dentry_list(struct list_head *list) rcu_read_unlock(); d_shrink_del(dentry); parent = dentry->d_parent; + if (parent != dentry) + __dput_to_list(parent, list); __dentry_kill(dentry); - if (parent == dentry) - continue; - /* - * We need to prune ancestors too. This is necessary to prevent - * quadratic behavior of shrink_dcache_parent(), but is also - * expected to be beneficial in reducing dentry cache - * fragmentation. - */ - dentry = parent; - while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) - dentry = dentry_kill(dentry); } }