Received: by 10.192.165.148 with SMTP id m20csp1174311imm; Wed, 2 May 2018 15:46:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoNAIo7meyGDpoYTD40s9B1cEucfH3fng5Qv2wWV2Vn5Jt47HBGBBPyOZC/S4WxBMHuok1N X-Received: by 2002:a17:902:bd8e:: with SMTP id q14-v6mr22191751pls.322.1525301160375; Wed, 02 May 2018 15:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525301160; cv=none; d=google.com; s=arc-20160816; b=dhQ03EV7X7p0SMt3QNSwcLFJe/3Rri1CKdxo/BExuoL1vZFD3qFmjd8dln4Q/P+vbm bRkpLl3V/UmPBU+43/AF+s2BsBF/cQfyNBHlalykrTHbmHosWZeD+cBGwv68jh82Edn8 NaQL21LR6KvxVi6mJOdFCDNyuF/TplcE3zNiUPfoSPWx6Z0veaGHUyb83IsBey4kH7H0 I3Dqen6A21Ue+hZ/VaiELDnzANfn7mNq65rHAQZYH+bJjR4hiDkNKxYa1Ac3uWMnLsRL pk5PTgEev//rIpFJdsqLZVSKXE16mf4kplFrltLcg1NcSu0SGV1UbfBgofJmcKx+aVrA nskw== 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:arc-authentication-results; bh=toO1gfy1Qqziifa0znExxFxepepqDP/94+2JZ0LaKPA=; b=oK4kCpLt+CMltW33Y3xfYEXGqy/lGcVEFqeeEb324Lzf5qaTPtS7uZFaEYwR7W9myJ BLquh/hR/ak00oRi6zXIxueJy79poXKD6vBoucVw8X16oGllC8dtcmIyRqhwMAYpfkT8 47UU2cEfIcDOkVLuQBm9juXfMidg2n8kdmNNcEZJqaWVTVvFX+omiZHVN5szWqCprip7 POxfL2LJJ/jhOQ27fZ2neV9RYv2uzpQRq6PGyCvEWXisX+qpIxeVtlBJl953NWpwwa54 AXmUkdjQS/MmBOwGuztF/kfsHg4StdmW9wxPHFqoN9fFaXUqhBiDBn8J1jI51pzT7HZE wtLA== 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 f34-v6si12418404plf.362.2018.05.02.15.45.46; Wed, 02 May 2018 15:46:00 -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 S1751698AbeEBWpg (ORCPT + 99 others); Wed, 2 May 2018 18:45:36 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:58918 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751045AbeEBWpf (ORCPT ); Wed, 2 May 2018 18:45:35 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fE0VB-0001uo-6d; Wed, 02 May 2018 22:45:33 +0000 Date: Wed, 2 May 2018 23:45:33 +0100 From: Al Viro To: Miklos Szeredi Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, miklos@szeredi.hu Subject: Re: [PATCH] dcache: fix quadratic behavior with parallel shrinkers Message-ID: <20180502224533.GW30522@ZenIV.linux.org.uk> References: <20180502222635.1862-1-mszeredi@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180502222635.1862-1-mszeredi@redhat.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 03, 2018 at 12:26:35AM +0200, Miklos Szeredi wrote: > When multiple shrinkers are operating on a directory containing many > dentries, it takes much longer than if only one shrinker is operating on > the directory. > > Call the shrinker instances A and B, which shrink DIR containing NUM > dentries. > > Assume A wins the race for locking DIR's d_lock, then it goes onto moving > all unlinked dentries to its dispose list. When it's done, then B will > scan the directory once again, but will find that all dentries are already > being shrunk, so it will have an empty dispose list. Both A and B will > have found NUM dentries (data.found == NUM). > > Now comes the interesting part: A will proceed to shrink the dispose list > by killing individual dentries and decrementing the refcount of the parent > (which is DIR). NB: decrementing DIR's refcount will block if DIR's d_lock > is held. B will shrink a zero size list and then immediately restart > scanning the directory, where it will lock DIR's d_lock, scan the remaining > dentries and find no dentry to dispose. > > So that results in B doing the directory scan over and over again, holding > d_lock of DIR, while A is waiting for a chance to decrement refcount of DIR > and making very slow progress because of this. B is wasting time and > holding up progress of A at the same time. > > Proposed fix is to check this situation in B (found some dentries, but > all are being shrunk already) and just sleep for some time, before retrying > the scan. The sleep is proportional to the number of found dentries. The thing is, the majority of massive shrink_dcache_parent() can be killed. Let's do that first and see if anything else is really needed. As it is, rmdir() and rename() are ridiculously bad - they should only call shrink_dcache_parent() after successful ->rmdir() or ->rename(). Sure, there are other places where we do large shrink_dcache_parent() runs, but those won't trigger in parallel on the same tree. IOW, let's wait adding complexity until we fix the sources of those calls.