Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp55595imm; Tue, 3 Jul 2018 13:51:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc+JuPiQrtS+c99EO3T0c31GR69sTa9OrFpnrIbLlhmuShSGc/WlWkZi/SlZe2xcx6yXgaD X-Received: by 2002:a65:4b04:: with SMTP id r4-v6mr21151716pgq.175.1530651067222; Tue, 03 Jul 2018 13:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530651067; cv=none; d=google.com; s=arc-20160816; b=PjyO07xTQ+SNCXgyWUgcfFm7T3qq1wi7+qaqHwp7BbjuUJpZCQ1d5Z0WwEwcZkvbpz dHsy3xNX6IbiBUJiGlYUs08RJJzOXb1yazp5LlAOxmn4Nbw8CXh27Ml2hqnrNAfw3TNw JVE/oWRyRvjfc2P9fxDEI/dBP640T5dOVmzaaj3Yd5ReM+QIbVJi0VECYvVvLLpiYBSK lgt+f1wMoEJaAhh2iZLWqedpdw47o032d4rRItH8Q45MirvmEI0WTotvbbD98fC7ncRp j7FIMDOjYOXKtPoCWfsT0kt03M3HBkvZjooE8YJGKXojlXrQ4TXKx/06Fc34PcRwFKhV wG0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=C6xiXZJrTjwGusNIQac+VYUhV/0Gz//O0+l4mP7l1gU=; b=yyXcy4LCz3c6DnCfMzVec4w5Gb//sMXmAezX/a/qADiLRnN0aS/wKgWGu7M+LhPQOp YEKsRnWXUHPpw3UkY5SpN3IcRxiKHVIUzmfOOReW2rNXciP7Q8xlhIcw+GkUi0YzAysA OPbWDYFpDwhov0gKfBOQhbo76xKxMtbqwMS6JZE8Ym20j1D9J8kTWifLNizBeK1v76RO z/JTAD8gPQhQPq9xpF0uzOyV6kBa1RcVMNhpsVUqojZUQ4VqDFB4kKrgBT3BkyG8pg8o tO0AD/qx0O71KovHU2G9yYQXLRNmmB2RqX5INCjUp4ICG+qLQQRWDRnAsrQ9n9xDTHfr 0v4w== 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 d18-v6si1647199pgp.214.2018.07.03.13.50.51; Tue, 03 Jul 2018 13:51:07 -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 S1752949AbeGCUuH (ORCPT + 99 others); Tue, 3 Jul 2018 16:50:07 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:41682 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752466AbeGCUuG (ORCPT ); Tue, 3 Jul 2018 16:50:06 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0E61BD37; Tue, 3 Jul 2018 20:50:05 +0000 (UTC) Date: Tue, 3 Jul 2018 13:50:00 -0700 From: Andrew Morton To: Kirill Tkhai Cc: vdavydov.dev@gmail.com, shakeelb@google.com, viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, tglx@linutronix.de, pombredanne@nexb.com, stummala@codeaurora.org, gregkh@linuxfoundation.org, sfr@canb.auug.org.au, guro@fb.com, mka@chromium.org, penguin-kernel@I-love.SAKURA.ne.jp, chris@chris-wilson.co.uk, longman@redhat.com, minchan@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, jbacik@fb.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, lirongqing@baidu.com, aryabinin@virtuozzo.com Subject: Re: [PATCH v8 05/17] mm: Assign memcg-aware shrinkers bitmap to memcg Message-Id: <20180703135000.b2322ae0e514f028e7941d3c@linux-foundation.org> In-Reply-To: <153063056619.1818.12550500883688681076.stgit@localhost.localdomain> References: <153063036670.1818.16010062622751502.stgit@localhost.localdomain> <153063056619.1818.12550500883688681076.stgit@localhost.localdomain> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 03 Jul 2018 18:09:26 +0300 Kirill Tkhai wrote: > Imagine a big node with many cpus, memory cgroups and containers. > Let we have 200 containers, every container has 10 mounts, > and 10 cgroups. All container tasks don't touch foreign > containers mounts. If there is intensive pages write, > and global reclaim happens, a writing task has to iterate > over all memcgs to shrink slab, before it's able to go > to shrink_page_list(). > > Iteration over all the memcg slabs is very expensive: > the task has to visit 200 * 10 = 2000 shrinkers > for every memcg, and since there are 2000 memcgs, > the total calls are 2000 * 2000 = 4000000. > > So, the shrinker makes 4 million do_shrink_slab() calls > just to try to isolate SWAP_CLUSTER_MAX pages in one > of the actively writing memcg via shrink_page_list(). > I've observed a node spending almost 100% in kernel, > making useless iteration over already shrinked slab. > > This patch adds bitmap of memcg-aware shrinkers to memcg. > The size of the bitmap depends on bitmap_nr_ids, and during > memcg life it's maintained to be enough to fit bitmap_nr_ids > shrinkers. Every bit in the map is related to corresponding > shrinker id. > > Next patches will maintain set bit only for really charged > memcg. This will allow shrink_slab() to increase its > performance in significant way. See the last patch for > the numbers. > > ... > > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -182,6 +182,11 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) > if (id < 0) > goto unlock; > > + if (memcg_expand_shrinker_maps(id)) { > + idr_remove(&shrinker_idr, id); > + goto unlock; > + } > + > if (id >= shrinker_nr_max) > shrinker_nr_max = id + 1; > shrinker->id = id; This function ends up being a rather sad little thing. : static int prealloc_memcg_shrinker(struct shrinker *shrinker) : { : int id, ret = -ENOMEM; : : down_write(&shrinker_rwsem); : id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); : if (id < 0) : goto unlock; : : if (memcg_expand_shrinker_maps(id)) { : idr_remove(&shrinker_idr, id); : goto unlock; : } : : if (id >= shrinker_nr_max) : shrinker_nr_max = id + 1; : shrinker->id = id; : ret = 0; : unlock: : up_write(&shrinker_rwsem); : return ret; : } - there's no need to call memcg_expand_shrinker_maps() unless id >= shrinker_nr_max so why not move the code and avoid calling memcg_expand_shrinker_maps() in most cases. - why aren't we decreasing shrinker_nr_max in unregister_memcg_shrinker()? That's easy to do, avoids pointless work in shrink_slab_memcg() and avoids memory waste in future prealloc_memcg_shrinker() calls. It should be possible to find the highest ID in an IDR tree with a straightforward descent of the underlying radix tree, but I doubt if that has been wired up. Otherwise a simple loop in unregister_memcg_shrinker() would be needed.