From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98191C4360C for ; Tue, 8 Oct 2019 08:20:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 56E0D206B6 for ; Tue, 8 Oct 2019 08:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 56E0D206B6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E74328E0005; Tue, 8 Oct 2019 04:20:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFBF98E0003; Tue, 8 Oct 2019 04:20:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC38B8E0005; Tue, 8 Oct 2019 04:20:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id A24548E0003 for ; Tue, 8 Oct 2019 04:20:42 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 05FBA181AC9B4 for ; Tue, 8 Oct 2019 08:20:42 +0000 (UTC) X-FDA: 76019921124.11.turn39_7a787156cfc03 X-HE-Tag: turn39_7a787156cfc03 X-Filterd-Recvd-Size: 7487 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Oct 2019 08:20:41 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AA896AEA1; Tue, 8 Oct 2019 08:20:39 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 25BBF1E4801; Tue, 8 Oct 2019 10:20:39 +0200 (CEST) Date: Tue, 8 Oct 2019 10:20:39 +0200 From: Jan Kara To: Roman Gushchin Cc: Dave Chinner , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Kernel Team , "tj@kernel.org" , Jan Kara Subject: Re: [PATCH] cgroup, blkcg: prevent dirty inodes to pin dying memory cgroups Message-ID: <20191008082039.GA5078@quack2.suse.cz> References: <20191004221104.646711-1-guro@fb.com> <20191008040630.GA15134@dread.disaster.area> <20191008053854.GA14951@castle.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191008053854.GA14951@castle.dhcp.thefacebook.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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: On Tue 08-10-19 05:38:59, Roman Gushchin wrote: > On Tue, Oct 08, 2019 at 03:06:31PM +1100, Dave Chinner wrote: > > On Fri, Oct 04, 2019 at 03:11:04PM -0700, Roman Gushchin wrote: > > > This is a RFC patch, which is not intended to be merged as is, > > > but hopefully will start a discussion which can result in a good > > > solution for the described problem. > > > > > > -- > > > > > > We've noticed that the number of dying cgroups on our production hosts > > > tends to grow with the uptime. This time it's caused by the writeback > > > code. > > > > > > An inode which is getting dirty for the first time is associated > > > with the wb structure (look at __inode_attach_wb()). It can later > > > be switched to another wb under some conditions (e.g. some other > > > cgroup is writing a lot of data to the same inode), but generally > > > stays associated up to the end of life of the inode structure. > > > > > > The problem is that the wb structure holds a reference to the original > > > memory cgroup. So if the inode was dirty once, it has a good chance > > > to pin down the original memory cgroup. > > > > > > An example from the real life: some service runs periodically and > > > updates rpm packages. Each time in a new memory cgroup. Installed > > > .so files are heavily used by other cgroups, so corresponding inodes > > > tend to stay alive for a long. So do pinned memory cgroups. > > > In production I've seen many hosts with 1-2 thousands of dying > > > cgroups. > > > > > > This is not the first problem with the dying memory cgroups. As > > > always, the problem is with their relative size: memory cgroups > > > are large objects, easily 100x-1000x larger that inodes. So keeping > > > a couple of thousands of dying cgroups in memory without a good reason > > > (what we easily do with inodes) is quite costly (and is measured > > > in tens and hundreds of Mb). > > > > > > One possible approach to this problem is to switch inodes associated > > > with dying wbs to the root wb. Switching is a best effort operation > > > which can fail silently, so unfortunately we can't run once over a > > > list of associated inodes (even if we'd have such a list). So we > > > really have to scan all inodes. > > > > > > In the proposed patch I schedule a work on each memory cgroup > > > deletion, which is probably too often. Alternatively, we can do it > > > periodically under some conditions (e.g. the number of dying memory > > > cgroups is larger than X). So it's basically a gc run. > > > > > > I wonder if there are any better ideas? > > > > > > Signed-off-by: Roman Gushchin > > > --- > > > fs/fs-writeback.c | 29 +++++++++++++++++++++++++++++ > > > mm/memcontrol.c | 5 +++++ > > > 2 files changed, 34 insertions(+) > > > > > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > > > index 542b02d170f8..4bbc9a200b2c 100644 > > > --- a/fs/fs-writeback.c > > > +++ b/fs/fs-writeback.c > > > @@ -545,6 +545,35 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id) > > > up_read(&bdi->wb_switch_rwsem); > > > } > > > > > > +static void reparent_dirty_inodes_one_sb(struct super_block *sb, void *arg) > > > +{ > > > + struct inode *inode, *next; > > > + > > > + spin_lock(&sb->s_inode_list_lock); > > > + list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) { > > > + spin_lock(&inode->i_lock); > > > + if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) { > > > + spin_unlock(&inode->i_lock); > > > + continue; > > > + } > > > + > > > + if (inode->i_wb && wb_dying(inode->i_wb)) { > > > + spin_unlock(&inode->i_lock); > > > + inode_switch_wbs(inode, root_mem_cgroup->css.id); > > > + continue; > > > + } > > > + > > > + spin_unlock(&inode->i_lock); > > > + } > > > + spin_unlock(&sb->s_inode_list_lock); > > > > No idea what the best solution is, but I think this is fundamentally > > unworkable. It's not uncommon to have a hundred million cached > > inodes these days, often on a single filesystem. Anything that > > requires a brute-force system wide inode scan, especially without > > conditional reschedule points, is largely a non-starter. > > > > Also, inode_switch_wbs() is not guaranteed to move the inode to the > > destination wb. There can only be WB_FRN_MAX_IN_FLIGHT (1024) > > switches in flight at once and switches are run via RCU callbacks, > > so I suspect that using inode_switch_wbs() for bulk re-assignment is > > going to be a lot more complex than just finding inodes to call > > inode_switch_wbs() on.... > > We can schedule it only if the number of dying cgroups exceeds a certain > number (like 100), which will make it relatively rare event. Maybe we can > add some other conditions, e.g. count the number of inodes associated with > a wb and skip scanning if it's zero. > > Alternatively the wb structure can keep the list of associated inodes, > and scan only them, but then it's not trivial to implement without > additional complication of already quite complex locking scheme. > And because inode_switch_wbs() can fail, we can't guarantee that a single > pass over such a list will be enough. That means the we need to schedule > scans periodically until all inodes will be switched. > > So I really don't know which option is better, but at the same time > doing nothing isn't the option too. Somehow the problem should be solved. I agree with Dave that scanning all inodes in the system can get really expensive quickly. So what I rather think we could do is create another 'IO list' (linked by inode->i_io_list) where we would put inodes that reference the wb but are not in any other IO list of the wb. And then we would switch inodes on this list when the wb is dying... One would have to be somewhat careful with properly draining this list since new inodes can be added to it while we work on it but otherwise I don't see any complication with this. Honza -- Jan Kara SUSE Labs, CR