Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5150842ybp; Mon, 7 Oct 2019 21:07:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxMiC7caLa9KzRFD9mfCkZFrxw/U6F1CJ8PB6z3A6SpSiY06ClCUP8k5YY9sls/VKJjABB X-Received: by 2002:aa7:dc49:: with SMTP id g9mr31921494edu.1.1570507647555; Mon, 07 Oct 2019 21:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570507647; cv=none; d=google.com; s=arc-20160816; b=RGQrYe43ULYYcd80J3rkqNVIFGXigI2hPGm1D5d9tzqei8SGGKOTvfe67YTbAWjbHb TP+519AC2bElpaDUl4th/eL18EmcKGrYgelkI052wG6+H6fJF37HmKwL/c6qLz50/2cF 71lKpCW/RkVsPPlCIzyqIDURbAJMwbf8IcYT15z3Bju1k7O3HoWq2y3sa2cpqd8nU3Uu Po+BPuH8naYOT3YWVj7wW6oO3rEuf9DLAs8wRAcijMHF+neA+EAKxUbMlk0RlfyriL8H ZbHjGYxWbkttI2oAzXG+0mjuX9JUq1v6pz0ZxNhBOF3dJm83V44MxgVjt5iac8IoevoI hVGA== 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=Ed/8JhP6jwV7HYO1ZJERi8emIRl7/GmYnXyohzk6KiE=; b=ckj5HToaZZByaFx93c3siHkQAWqXO+nLhCoTbTFRMXGxhnBp0Anx1LsNFt4lQgjQDl vqzOdBtgs1aFCtbfD/njtmm0StXGQL5bu7Z6BBqRuKtWbXcfsTL4Kw65JptnJodXaOc1 ffU+Jp1f/OAKMTJRTgRjkd7ctXqYzEB2k0e2K66Eg3AJFMkfD1qqd/1KMed+JOtqvtPH hqolIGwsvn9/LymFHFfM1qdaEPGNZXxhpbxaywNypclGbIVNj8I3uJI1nTp+obkOFhvT V4SMCyhnBXr4HUH7ohqlor17RkIzkaMEIU7nkOteezmRCsjfxrFhkwZFL3YVrbogj8lY L2SQ== 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 b22si9931662eda.194.2019.10.07.21.07.04; Mon, 07 Oct 2019 21:07:27 -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 S1729917AbfJHEGi (ORCPT + 99 others); Tue, 8 Oct 2019 00:06:38 -0400 Received: from mail104.syd.optusnet.com.au ([211.29.132.246]:53857 "EHLO mail104.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbfJHEGi (ORCPT ); Tue, 8 Oct 2019 00:06:38 -0400 Received: from dread.disaster.area (pa49-181-226-196.pa.nsw.optusnet.com.au [49.181.226.196]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 90A4543E409; Tue, 8 Oct 2019 15:06:31 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.2) (envelope-from ) id 1iHglb-00045v-1P; Tue, 08 Oct 2019 15:06:31 +1100 Date: Tue, 8 Oct 2019 15:06:31 +1100 From: Dave Chinner To: Roman Gushchin Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, tj@kernel.org, Jan Kara Subject: Re: [PATCH] cgroup, blkcg: prevent dirty inodes to pin dying memory cgroups Message-ID: <20191008040630.GA15134@dread.disaster.area> References: <20191004221104.646711-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191004221104.646711-1-guro@fb.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=D+Q3ErZj c=1 sm=1 tr=0 a=dRuLqZ1tmBNts2YiI0zFQg==:117 a=dRuLqZ1tmBNts2YiI0zFQg==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=XobE76Q3jBoA:10 a=FOH2dFAWAAAA:8 a=7-415B0cAAAA:8 a=tDm895Og1OPoIn_jjw4A:9 a=IdxF-Tp9X7UopkWZ:21 a=VORt4evX2LhOaXV9:21 a=CjuIK1q_8ugA:10 a=i3VuKzQdj-NEYjvDI-p3:22 a=biEYGPWJfzWAr4FL6Ov7:22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.... Cheers, Dave. -- Dave Chinner david@fromorbit.com