From patchwork Sat Jun 29 04:38:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 11023703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F72C14C0 for ; Sat, 29 Jun 2019 04:38:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 626F628868 for ; Sat, 29 Jun 2019 04:38:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54C212886C; Sat, 29 Jun 2019 04:38:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C899A28868 for ; Sat, 29 Jun 2019 04:38:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6B836B0003; Sat, 29 Jun 2019 00:38:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C1C358E0003; Sat, 29 Jun 2019 00:38:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABCB28E0002; Sat, 29 Jun 2019 00:38:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f79.google.com (mail-wr1-f79.google.com [209.85.221.79]) by kanga.kvack.org (Postfix) with ESMTP id 5FB176B0003 for ; Sat, 29 Jun 2019 00:38:25 -0400 (EDT) Received: by mail-wr1-f79.google.com with SMTP id e8so3252406wrw.15 for ; Fri, 28 Jun 2019 21:38:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent:sender; bh=7X2W3Oissv5OiKS46GmHz0NE2MD/ntnmf9adwVaIXfc=; b=j3ULMkQILfffe+rKw6GzIshFPXn4KjLGo/ZOJd9hASLtcGJE0xIz7cVOUWSQJpcCw0 c9X8U67MYhQUnbcs3W3UFi5/k8mycSis44mraQ+22sTLHlvUb9wrt6WWkhhODbFFVJyL xZtC5uwjlO15Xm9jMjU5CeobzZgDw9WtkCa3/4jG66jwoPCyxNaXpPD7GbVE1N37xAcb VJMjKHbq/gvixz0ePzHtjMRAM11AVDXPsO97XlWGXlMSzndVrpUg8ewnH4gfZVCrLc2N lHfz1d6mTsNY1+3rtU1dc1fMNf1pq+a6FEO5QIsdxh2N1jA4Eis0bsmnmhjYACJAs9qJ Uu4A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of viro@ftp.linux.org.uk designates 195.92.253.2 as permitted sender) smtp.mailfrom=viro@ftp.linux.org.uk X-Gm-Message-State: APjAAAWjLoqkXT5hvZiBx1g9bmfFQxjNkECbYOSIxNWbBk4ymCMT2ToP COuwsGCCuHeA+hX8pI62OOAwOnHcGnXP3a7I7F9+hePSmjSeDBIFJaq/VLMV1uoVlxHB7ObxFbx 2wo5a6uNFYLFFQd+es0zbPrsEdrJ5KzFuZ72rtf3vqKmX3lPJnYvf8cfdwO8aK/aAuA== X-Received: by 2002:adf:e9c6:: with SMTP id l6mr10876107wrn.216.1561783104790; Fri, 28 Jun 2019 21:38:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuqsXwjdE5RHzBvXmtLc0GYbQcJXQjkY7J0347fW88DRfNpk2iRzMTB7FKZCKmwHgxgctT X-Received: by 2002:adf:e9c6:: with SMTP id l6mr10876043wrn.216.1561783103907; Fri, 28 Jun 2019 21:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561783103; cv=none; d=google.com; s=arc-20160816; b=PP4Ur7e8dPjKPRzsoWS+kmCCLo2e3zgtuKaLSiLlE70MRDAuDHQjGkQQtnfo62yq3/ +bkh0SpCMwciaOf0lx07H0ORCGSs+bjKLow6f3alkbyvpWo5f60JVpUYzU2/Q9em4iz5 GtaWZLR6fgQwtb3NIz2JKjvAMcohZx9HkzdFC5ZvFEjelxV0uz5WWKMgVtB9RPibiqRV FYJDm6M5LLKukrG/fvfEZWTqOaiIqFA+Ufpom1tFu6fRxQNosLtwR40Rz0WK52Gn2mn6 fwPFQQ78Q040TcvNFP/vPsgtggnvLis3bJVjDcWZagKLhi+kN6uTLVHP+4nHCYKeNS3r AkPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:user-agent:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=7X2W3Oissv5OiKS46GmHz0NE2MD/ntnmf9adwVaIXfc=; b=bly71xsLv615z1W4BoaWwjqAJziBwsqB9USIlo2tO510oz1Llyp7vxZ4Xh8kxa2rr/ GT3khsUFWNadGB+bidR+h3BWyUu60qLh26QJma7foOHo+W+43M1TyNNl27iI2VeZXcQL ABo8RcD6EOTt0IGxq1v1/wLa2e7Kx2CK2ibsXreuHzTNv0g2hCrgCWPBsNI5ke9aJ92/ 4J7FVNZBGGoddMDmRm7dVZdKFxiNBcOe20ItMYeoczLABavJ0Wbczp7Z9aKPRzZ+Rt1T lD70dLW4OUR9a2hEv/4Pw8HqGZ8dcOk+qa/N0kL22m73/96PG7IyVl0UFr4Mhl5r8l8t YjkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of viro@ftp.linux.org.uk designates 195.92.253.2 as permitted sender) smtp.mailfrom=viro@ftp.linux.org.uk Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk. [195.92.253.2]) by mx.google.com with ESMTPS id m25si2724793wmi.43.2019.06.28.21.38.23 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 21:38:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of viro@ftp.linux.org.uk designates 195.92.253.2 as permitted sender) client-ip=195.92.253.2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of viro@ftp.linux.org.uk designates 195.92.253.2 as permitted sender) smtp.mailfrom=viro@ftp.linux.org.uk 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-Disposition: inline In-Reply-To: <20190629040844.GS17978@ZenIV.linux.org.uk> User-Agent: Mutt/1.11.3 (2019-02-01) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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? Signed-off-by: Al Viro Signed-off-by: Al Viro 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); } }