Received: by 10.192.165.148 with SMTP id m20csp4600276imm; Tue, 24 Apr 2018 05:35:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx4//Ejd9x+jlymZfCvxzfdHpvyB6X36ytIURFi6YTUAJ424isFXLu3VnZKHL93q+mJb9aXqQ X-Received: by 10.101.100.16 with SMTP id a16mr18853019pgv.75.1524573323418; Tue, 24 Apr 2018 05:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524573323; cv=none; d=google.com; s=arc-20160816; b=upKUK+2njPqa9oqOWO7KWlLe06CTTISCXEcOu3kLBhWYfCQLwCzo4U4s0dyz7PoKKV PhSsCUB49GksgvvnzTe1YkW0bK10mtFVgq/IIy1Lw7eWL/Jx98adq8wCPj9tmtS5uThw vkYy6lypuQjXnu/R+KOvBUoLKi96B4g28Ah5N2a+fqzZO+5tp63Dunicd2vMLDoufe+W AZxss272+fpTM8p0BrmRNxPM/xWlqn3V7c/edDrRblHBU4bq/ykctnoD7SdHSiiXm0np uNPkVHlrgVkXcidwA+SeOvw4ojZi7VO9BKgXfZJ/UmbDcsSEDN7ZjrxgIYTqEyXTsu6U YquQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=59GXguP/iACvp3qhrW1yKZEP5Oxqbiw2JekNWrZaKVw=; b=md5PG5Wg69NpCfjfYUyllGHKXsUex0h2qZwi77qmTJFYACc694UD7RV/dyKlPTtvDM sr6kfHAKM4WwcrI4FG60JAtfCpl6CXccghlKutjqG0tHJK99r+QC4UQ6/XaMcwMgqOUQ CDTfEB/VA/wHFc+PlLdGKeq0FrggnUVZ6lxTVWmapBYq+wP8pMJhPLcAxmiKIO8CAuyQ tBkQnIM5YevQ3xxZPLz82h/8XepE/cEYVjNc64B2TDLOEH5NLYV+J+IpO8fTZymMMJD0 HgukGQbSXLPJZYp+cYDeIR8RGbm9VdPI/ViKqJm86F1qxeJDRSX6Gq2T3UCvD3PR7TNR vpXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hQ68v7+T; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8-v6si13724294plc.342.2018.04.24.05.35.08; Tue, 24 Apr 2018 05:35:23 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hQ68v7+T; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757584AbeDXMP1 (ORCPT + 99 others); Tue, 24 Apr 2018 08:15:27 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33019 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757564AbeDXMPU (ORCPT ); Tue, 24 Apr 2018 08:15:20 -0400 Received: by mail-lf0-f65.google.com with SMTP id m18-v6so2644072lfb.0 for ; Tue, 24 Apr 2018 05:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=59GXguP/iACvp3qhrW1yKZEP5Oxqbiw2JekNWrZaKVw=; b=hQ68v7+TEQ1xvFlIR7Zivpy91GEGV/cqZJNHay+r7cgqqgonb3RbLPjqbFmir2D46I HT9o1ydat9QWhzt38KeGaW191P/Sb/v9N7k4mmKmhcSmq2W2IQ177+chGd+V0FyGPAjd pTO7g9bdSU76cOpfORtbW66QsAzTZpcl0eC/jFJubC2jte0TT3XBHFWjIGKAoFKl3qy6 MqY1+KRL0YA9JnJp2Ttq329VdNIeTPMYo/hg1vpRroXOde07TrxPZmid2qxLsAASNMSe Jww2dRzBFpLFo6e0hgflCYbH/FSvnVEEPXAMw5wevxYD2gvtl/iNanqS6Rky2LSBMN9M WfLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=59GXguP/iACvp3qhrW1yKZEP5Oxqbiw2JekNWrZaKVw=; b=ObGmBWu0wAzB6Di/Y6Xwn2nqqmTkBqD3fU2YEXkCfI8YBYKYEOKC56d9cJ8RZLIwhS x7DGdC1Xxn6BDPUm73J4M2RwrFJozu8vATAx44+RqXNrn6h6k+VxSTQ+G6g4HOifiAVw JNAsYFXU7ZiCfVSx/+46h3WrJqmxuP7H5AYTlwJdVpZPXEhPbzz61WG8EH5qZ0uLbAaU X0QzjwbieFLlT8yYdeeFWSeBXrBNEwcAwVPJvq695hgcHmPIdfC4UaKbwraO5kQXyz4u wF0hUHybRkmzmEJfSGaHRyKWXeWDOskp0E4ANfTKKdgxqn0UPvK5SNBi9oCNg6hSSdm8 4Wvw== X-Gm-Message-State: ALQs6tDzOBXG9w/jvoUDOBdz2rxhw910S0mpmH36V5XGCgE+hednLX40 0WOK3FbIsEiJbUtdySNIQDs= X-Received: by 10.46.144.3 with SMTP id h3mr15780302ljg.37.1524572118957; Tue, 24 Apr 2018 05:15:18 -0700 (PDT) Received: from esperanza ([185.6.245.156]) by smtp.gmail.com with ESMTPSA id h6sm2766109ljg.3.2018.04.24.05.15.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Apr 2018 05:15:18 -0700 (PDT) Date: Tue, 24 Apr 2018 15:15:16 +0300 From: Vladimir Davydov To: Kirill Tkhai Cc: akpm@linux-foundation.org, 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, hillf.zj@alibaba-inc.com, 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 v2 04/12] mm: Assign memcg-aware shrinkers bitmap to memcg Message-ID: <20180424121516.ihn6lewpidc34ayl@esperanza> References: <152397794111.3456.1281420602140818725.stgit@localhost.localdomain> <152399121146.3456.5459546288565589098.stgit@localhost.localdomain> <20180422175900.dsjmm7gt2nsqj3er@esperanza> <14ebcccf-3ea8-59f4-d7ea-793aaba632c0@virtuozzo.com> <20180424112844.626madzs4cwoz5gh@esperanza> <7bf5372d-7d9d-abee-27dd-5044da5ec489@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7bf5372d-7d9d-abee-27dd-5044da5ec489@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 24, 2018 at 02:38:51PM +0300, Kirill Tkhai wrote: > On 24.04.2018 14:28, Vladimir Davydov wrote: > > On Mon, Apr 23, 2018 at 01:54:50PM +0300, Kirill Tkhai wrote: > >>>> @@ -1200,6 +1206,8 @@ extern int memcg_nr_cache_ids; > >>>> void memcg_get_cache_ids(void); > >>>> void memcg_put_cache_ids(void); > >>>> > >>>> +extern int shrinkers_max_nr; > >>>> + > >>> > >>> memcg_shrinker_id_max? > >> > >> memcg_shrinker_id_max sounds like an includive value, doesn't it? > >> While shrinker->id < shrinker_max_nr. > >> > >> Let's better use memcg_shrinker_nr_max. > > > > or memcg_nr_shrinker_ids (to match memcg_nr_cache_ids), not sure... > > > > Come to think of it, this variable is kinda awkward: it is defined in > > vmscan.c but declared in memcontrol.h; it is used by vmscan.c for max > > shrinker id and by memcontrol.c for shrinker map capacity. Just a raw > > idea: what about splitting it in two: one is private to vmscan.c, used > > as max id, say we call it shrinker_id_max; the other is defined in > > memcontrol.c and is used for shrinker map capacity, say we call it > > memcg_shrinker_map_capacity. What do you think? > > I don't much like a duplication of the single variable... Well, it's not really a duplication. For example, shrinker_id_max could decrease when a shrinker is unregistered while shrinker_map_capacity can only grow exponentially. > Are there real problems, if it defined in memcontrol.{c,h} and use in > both of the places? The code is more difficult to follow when variables are shared like that IMHO. I suggest you try it and see how it looks. May be, it will only get worse and we'll have to revert to what we have now. Difficult to say without seeing the code. > > >>>> +int expand_shrinker_maps(int old_nr, int nr) > >>>> +{ > >>>> + int id, size, old_size, node, ret; > >>>> + struct mem_cgroup *memcg; > >>>> + > >>>> + old_size = old_nr / BITS_PER_BYTE; > >>>> + size = nr / BITS_PER_BYTE; > >>>> + > >>>> + down_write(&shrinkers_max_nr_rwsem); > >>>> + for_each_node(node) { > >>> > >>> Iterating over cgroups first, numa nodes second seems like a better idea > >>> to me. I think you should fold for_each_node in memcg_expand_maps. > >>> > >>>> + idr_for_each_entry(&mem_cgroup_idr, memcg, id) { > >>> > >>> Iterating over mem_cgroup_idr looks strange. Why don't you use > >>> for_each_mem_cgroup? > >> > >> We want to allocate shrinkers maps in mem_cgroup_css_alloc(), since > >> mem_cgroup_css_online() mustn't fail (it's a requirement of currently > >> existing design of memcg_cgroup::id). > >> > >> A new memcg is added to parent's list between two of these calls: > >> > >> css_create() > >> ss->css_alloc() > >> list_add_tail_rcu(&css->sibling, &parent_css->children) > >> ss->css_online() > >> > >> for_each_mem_cgroup() does not see allocated, but not linked children. > > > > Why don't we move shrinker map allocation to css_online then? > > Because the design of memcg_cgroup::id prohibits mem_cgroup_css_online() to fail. > This function can't fail. I fail to understand why it is so. Could you please elaborate? > > I don't think it will be good to dive into reworking of this stuff for this patchset, > which is really already big. Also, it will be assymmetric to allocate one part of > data in css_alloc(), while another data in css_free(). This breaks cgroup design, > which specially introduces this two function to differ allocation and onlining. > Also, I've just move the allocation to alloc_mem_cgroup_per_node_info() like it was > suggested in comments to v1... Yeah, but (ab)using mem_cgroup_idr for iterating over all allocated memory cgroups looks rather dubious to me...