Received: by 10.192.165.148 with SMTP id m20csp4551549imm; Tue, 24 Apr 2018 04:49:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrDVeHYyMlJxmx39W8SkWZ5SvejOsJTt/Zua8hUbamtX3op5R7KUkRF+0tgvl3R/t14rwRA X-Received: by 10.167.132.150 with SMTP id u22mr893492pfn.102.1524570584553; Tue, 24 Apr 2018 04:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524570584; cv=none; d=google.com; s=arc-20160816; b=LXY7RqRpv7WwfPcn/PGcX2/CUmilSY1xQzrmbCWBi5CKXzzJb/5AKFbbLbEgvLfPSr OA0AwbbnKrncg8bKE1fBs7VHp6B2JyJDOhMVPaoa2MFQhZTWIC7MOBsce+mfzwzrUG0D xP2GNVCR1QZbgkfPftPM5p/ScMw6vllHN6JvpqxyFWe9PUBncW2mmkMTAGS4XEVq+9tM FI1fvZZ3Ngs5Y/L08qL+1tXawCaCgK/2izBeYQrTNGQaNxh8duiFWnkUJWSNamAnYcWf aiEraCtw7Z2GmzJemyfbllS096WzFRh5WcJSnerLmq5JLuTBtoMokAcmAIGRsIITfM5j JalQ== 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=tp0+b9RTwH9haozPXnp1VFb16M/89aoi/rg5bFyRZoc=; b=Q6vph+H6Z+GPqb4O4cJN234g+ApNO3UIWCqeywI9b15PhdCG+Umn3XulLTxh66WQqk +0Zaxdi5mR+Ix6THATldlFq2jy0pvKD/TAcmACAr3mhXwT3yPou4QOz8mALeuHHHVthj U4MTGZrPQ5O4WMsaKh8Cy1L4KNv8UupDPzp4v1HOFFJ4+fSt9y+tn8O2gV7zoJCqCHrU b211/SoRPR0bhv3g9UbelwqiP3BKnCdq1wGZbpYVbJ5DRti47QKsdp4PtXQ2QI2BLNXK pmC7rQJeU40YP6bnmq5/5wy2/njGU4t98lodZbIRTK4sriYasm+HQ2tpeVTjJSpy7ldO JXpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ix8Fe2Xa; 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 m9-v6si13677919pll.67.2018.04.24.04.49.30; Tue, 24 Apr 2018 04:49:44 -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=Ix8Fe2Xa; 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 S1756858AbeDXL2v (ORCPT + 99 others); Tue, 24 Apr 2018 07:28:51 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:39049 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756167AbeDXL2t (ORCPT ); Tue, 24 Apr 2018 07:28:49 -0400 Received: by mail-lf0-f65.google.com with SMTP id p142-v6so19737425lfd.6 for ; Tue, 24 Apr 2018 04:28:48 -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=tp0+b9RTwH9haozPXnp1VFb16M/89aoi/rg5bFyRZoc=; b=Ix8Fe2Xa024u1E7oDMoEncGcBG/xMWs6/l5xaRifg05IIxcTs27ZZl8QztYwjNc9SM ZXds0UZhmzsoy2T8wQ4qdEQmolu8cD35ZWrCHBlUiK/hZUz/ylaPwOn6AaSnK0o8Sj/O Uj5uU5JN2wj8Fzu8d9U85PcHegqMkkaUDFAV7Z6oxvzrRdANVM3ieAW4UMBXt4nGBR82 CKoqQAMJX55eR+PShb0JYGQd9YUvGoQysMFNH0SXcIJrUOwhn7zJDodxQ+0NeW7aah4C vjd4dZSewV+YO1Y1d7eqqBKy3AlSgAQgK+1yVlWTACfin69QrjoNiabHIqHMbzM3TFa8 sRfg== 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=tp0+b9RTwH9haozPXnp1VFb16M/89aoi/rg5bFyRZoc=; b=EL0dGbi5KsmSruFG+1KYb0tfSi7fXowU8Mg9/Dp8cotBVppVJLNeTxiDXeQz2lr7pS zIbEyQkD3o7DWVMCrj1MzQGWw/32EWw6TxwdBplMpuMipLiJCnF3IMcYqJRwJWXq3Myr FH6Q3Yo8C2A4M9Tp0HvwechYNJHk+7zZ1lV/HL/XndfmW+gj6kFuoUlkRT0q3c/q39gI If7Wv2F0aQW+hB2zOiAYAIz2Wl+LKfHFOsq3nL2/WUyCqIdqvEKvUCytujwAys+3awif 0Zfh99P0Mlf0fb+fewfgUp8xus02b7PNq/gC2QGtaEr+UOtt1PSbkFa1U5eTB5Xh6emO wfaA== X-Gm-Message-State: ALQs6tC7i/SkT9JBD/iivDrc/S0rtgmBvHttBLuuLU95FqZIGa3QMyKv c4eSqGapSg1tngvz6dUQKMU= X-Received: by 2002:a19:d390:: with SMTP id k138-v6mr9544983lfg.118.1524569327966; Tue, 24 Apr 2018 04:28:47 -0700 (PDT) Received: from esperanza ([185.6.245.156]) by smtp.gmail.com with ESMTPSA id s25sm2744527ljg.43.2018.04.24.04.28.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Apr 2018 04:28:47 -0700 (PDT) Date: Tue, 24 Apr 2018 14:28:44 +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: <20180424112844.626madzs4cwoz5gh@esperanza> References: <152397794111.3456.1281420602140818725.stgit@localhost.localdomain> <152399121146.3456.5459546288565589098.stgit@localhost.localdomain> <20180422175900.dsjmm7gt2nsqj3er@esperanza> <14ebcccf-3ea8-59f4-d7ea-793aaba632c0@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14ebcccf-3ea8-59f4-d7ea-793aaba632c0@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > >> +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? > > >> + if (id == 1) > >> + memcg = NULL; > >> + ret = memcg_expand_maps(memcg, node, size, old_size); > >> + if (ret) > >> + goto unlock; > >> + } > >> + > >> + /* root_mem_cgroup is not initialized yet */ > >> + if (id == 0) > >> + ret = memcg_expand_maps(NULL, node, size, old_size); > >> + } > >> +unlock: > >> + up_write(&shrinkers_max_nr_rwsem); > >> + return ret; > >> +}