Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp144332imm; Mon, 14 May 2018 22:45:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpCwfynH1QI9kD2ZlpiSBtgMZzolOdbO/hHpgfswDw+7G5CiA0sqKavltKw1m5+tl8u7wDB X-Received: by 2002:a65:6205:: with SMTP id d5-v6mr10973171pgv.416.1526363120050; Mon, 14 May 2018 22:45:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526363120; cv=none; d=google.com; s=arc-20160816; b=VoJRsSbjMm1HCQAlfSbeKGWqoMECOq8R+0T4ouFrqmadbWDt38dHYtqeJeStci3bdK GCxkZlTON1NxCXfwhuHOl2pBzbSogvf5sT4+KLHddDHaVD+unnocSkc8xkNXqhz7eVb6 LKadukBkYSU3kzPg6Hj+ewl5PJpYxHevK+s3FxcD1H0j6i80Li8bTMJVDbacqmkObLl4 9MmkICWCooeFCcB3RCDXT27ySdZr0le6GLIs3oEl2lviXJHHYMtelo1Wj3wL01RmpXlG NXAv8Lsx5NzSRVXX/thF7ISFd1NAGXznCmmgqLXc9uSGQNvLiewqr4ScY0vWSHZrNifC LoCQ== 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=aIr8cWPxE/36wYe2+02lluboFVKTnm5dCBcd+PQPt50=; b=VnypTVMhrTZbT55tYYUaUNKfi54V0ZQi+XwIU2DRrRTjDlCe6z0CO/53A9URfh+X+K bjGnX5CebjrZXwzF9Z/zpBS71dy2ezLGSiLi1oDq2esO7l62f1Zx0gdOfVUvJx9f7kgL TEWhZvm4RecmMsM2AP4RJxtrIu43Qw3ydceF+Faf37N4hzqihQZYcG1zXExI5zwj1kKY 2IiLCDBirlZNCNe4kKqXuC0NCWEXaKmwXmT2Of6f39oOjD9SrSIJUlox897jG4NCo+aJ yXygVUEI0OSggWZCGrIavWG2fqgNtYgoEYS11J9l4kKXnHIfG9BEuq+KzEVZlc0z5yha Roxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sI6zCGic; 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 u6-v6si10671500pfm.183.2018.05.14.22.45.05; Mon, 14 May 2018 22:45:20 -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=sI6zCGic; 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 S1752307AbeEOFov (ORCPT + 99 others); Tue, 15 May 2018 01:44:51 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:43780 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752162AbeEOFou (ORCPT ); Tue, 15 May 2018 01:44:50 -0400 Received: by mail-lf0-f66.google.com with SMTP id n18-v6so14987429lfh.10 for ; Mon, 14 May 2018 22:44:49 -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=aIr8cWPxE/36wYe2+02lluboFVKTnm5dCBcd+PQPt50=; b=sI6zCGicBTEuBNnOU43gN3RhfZ2o4HRwolGpvOV/gLmV6k4pZbEstK1tQz4eYnKXgg i7FEwlcl1pXMeof8cIhVXC9jrQx7o3l9aPkt2cmBOSLIXUGKhpBOCTG4JGi3X5gW2n0V DB4CLw9acR2+UAHeLawtVA0t6D3yUgE18Vx14I3EsJO1owUBMETTMHXwBk3jzz1JySEO T8AGcfbZMkqTMv4Ym//MaQU27cU685HYDpZYIRozu+alcbNysTaGbyd0ESbHFW4iRkhR wrTi3P7mFxBK1AzMsF2btD3PROjQxas+2YHOCGFn+kuBhoRK0YGAnxuI35esWcEnevl5 rkIA== 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=aIr8cWPxE/36wYe2+02lluboFVKTnm5dCBcd+PQPt50=; b=WZmPhubA1DqxGQ/U4OnuPwmF6AMIKNXvO7rpranD6UuVJd4IkDbmorcsXwb0d5nCTs U55doHOSGMuysmSdrPpeLRZx3dczN2lVsft5+uQZBUUmuI5/fUQ27fjS7KBI2JSGBbS2 LQ5sYYRchlTUiB38j0oE0ADJLN+u4PnAsmTG64pky+1ndhPDiyueknhcBN9vxwAMk/4S nmb69xRVV5jRarzy0jhVmRbeRS9ogIw0s63UMayS+FPggCZqI91/nGTAjboYF/YbfKfp W9XyAZ5XCvf/mUFh3pAooDFH0CiisQonv/N+ELhxzntSMo34gXFT67gACn7yGUZq2XXo 0CMw== X-Gm-Message-State: ALKqPwfmS6+mmx8Xyvv0DK+PhQclHptoiWTTUrqXgreM4zvFdbiz4Yze dk713Rch34f00XFqvFpvOc4= X-Received: by 2002:a2e:9101:: with SMTP id m1-v6mr6351844ljg.93.1526363088471; Mon, 14 May 2018 22:44:48 -0700 (PDT) Received: from esperanza (81.5.110.211.dhcp.mipt-telecom.ru. [81.5.110.211]) by smtp.gmail.com with ESMTPSA id h28-v6sm2851518lfk.82.2018.05.14.22.44.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 22:44:47 -0700 (PDT) Date: Tue, 15 May 2018 08:44:45 +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, 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 v5 11/13] mm: Iterate only over charged shrinkers during memcg shrink_slab() Message-ID: <20180515054445.nhe4zigtelkois4p@esperanza> References: <152594582808.22949.8353313986092337675.stgit@localhost.localdomain> <152594603565.22949.12428911301395699065.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152594603565.22949.12428911301395699065.stgit@localhost.localdomain> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 10, 2018 at 12:53:55PM +0300, Kirill Tkhai wrote: > Using the preparations made in previous patches, in case of memcg > shrink, we may avoid shrinkers, which are not set in memcg's shrinkers > bitmap. To do that, we separate iterations over memcg-aware and > !memcg-aware shrinkers, and memcg-aware shrinkers are chosen > via for_each_set_bit() from the bitmap. In case of big nodes, > having many isolated environments, this gives significant > performance growth. See next patches for the details. > > Note, that the patch does not respect to empty memcg shrinkers, > since we never clear the bitmap bits after we set it once. > Their shrinkers will be called again, with no shrinked objects > as result. This functionality is provided by next patches. > > Signed-off-by: Kirill Tkhai > --- > include/linux/memcontrol.h | 1 + > mm/vmscan.c | 70 ++++++++++++++++++++++++++++++++++++++------ > 2 files changed, 62 insertions(+), 9 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 82f892e77637..436691a66500 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -760,6 +760,7 @@ void mem_cgroup_split_huge_fixup(struct page *head); > #define MEM_CGROUP_ID_MAX 0 > > struct mem_cgroup; > +#define root_mem_cgroup NULL Let's instead export mem_cgroup_is_root(). In case if MEMCG is disabled it will always return false. > > static inline bool mem_cgroup_disabled(void) > { > diff --git a/mm/vmscan.c b/mm/vmscan.c > index d8a2870710e0..a2e38e05adb5 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -376,6 +376,7 @@ int prealloc_shrinker(struct shrinker *shrinker) > goto free_deferred; > } > > + INIT_LIST_HEAD(&shrinker->list); IMO this shouldn't be here, see my comment below. > return 0; > > free_deferred: > @@ -547,6 +548,63 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, > return freed; > } > > +#ifdef CONFIG_MEMCG_SHRINKER > +static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, > + struct mem_cgroup *memcg, int priority) > +{ > + struct memcg_shrinker_map *map; > + unsigned long freed = 0; > + int ret, i; > + > + if (!memcg_kmem_enabled() || !mem_cgroup_online(memcg)) > + return 0; > + > + if (!down_read_trylock(&shrinker_rwsem)) > + return 0; > + > + /* > + * 1)Caller passes only alive memcg, so map can't be NULL. > + * 2)shrinker_rwsem protects from maps expanding. ^^ Nit: space missing here :-) > + */ > + map = rcu_dereference_protected(MEMCG_SHRINKER_MAP(memcg, nid), true); > + BUG_ON(!map); > + > + for_each_set_bit(i, map->map, memcg_shrinker_nr_max) { > + struct shrink_control sc = { > + .gfp_mask = gfp_mask, > + .nid = nid, > + .memcg = memcg, > + }; > + struct shrinker *shrinker; > + > + shrinker = idr_find(&shrinker_idr, i); > + if (!shrinker) { > + clear_bit(i, map->map); > + continue; > + } The shrinker must be memcg aware so please add BUG_ON((shrinker->flags & SHRINKER_MEMCG_AWARE) == 0); > + if (list_empty(&shrinker->list)) > + continue; I don't like using shrinker->list as an indicator that the shrinker has been initialized. IMO if you do need such a check, you should split shrinker_idr registration in two steps - allocate a slot in 'prealloc' and set the pointer in 'register'. However, can we really encounter an unregistered shrinker here? AFAIU a bit can be set in the shrinker map only after the corresponding shrinker has been initialized, no? > + > + ret = do_shrink_slab(&sc, shrinker, priority); > + freed += ret; > + > + if (rwsem_is_contended(&shrinker_rwsem)) { > + freed = freed ? : 1; > + break; > + } > + } > + > + up_read(&shrinker_rwsem); > + return freed; > +} > +#else /* CONFIG_MEMCG_SHRINKER */ > +static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, > + struct mem_cgroup *memcg, int priority) > +{ > + return 0; > +} > +#endif /* CONFIG_MEMCG_SHRINKER */ > + > /** > * shrink_slab - shrink slab caches > * @gfp_mask: allocation context > @@ -576,8 +634,8 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, > struct shrinker *shrinker; > unsigned long freed = 0; > > - if (memcg && (!memcg_kmem_enabled() || !mem_cgroup_online(memcg))) > - return 0; > + if (memcg && memcg != root_mem_cgroup) if (!mem_cgroup_is_root(memcg)) > + return shrink_slab_memcg(gfp_mask, nid, memcg, priority); > > if (!down_read_trylock(&shrinker_rwsem)) > goto out; > @@ -589,13 +647,7 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, > .memcg = memcg, > }; > > - /* > - * If kernel memory accounting is disabled, we ignore > - * SHRINKER_MEMCG_AWARE flag and call all shrinkers > - * passing NULL for memcg. > - */ > - if (memcg_kmem_enabled() && > - !!memcg != !!(shrinker->flags & SHRINKER_MEMCG_AWARE)) > + if (!!memcg != !!(shrinker->flags & SHRINKER_MEMCG_AWARE)) > continue; I want this check gone. It's easy to achieve, actually - just remove the following lines from shrink_node() if (global_reclaim(sc)) shrink_slab(sc->gfp_mask, pgdat->node_id, NULL, sc->priority); > > if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) >