Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp61357imm; Tue, 3 Jul 2018 13:59:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIZSfgpQIHxoLEwy3N8KOvNxJJjvnLWJ5rXAyeUd75sLS9QbAzAn0yI9ijmtakZGDY56NI6 X-Received: by 2002:a17:902:7c16:: with SMTP id x22-v6mr31014894pll.77.1530651561373; Tue, 03 Jul 2018 13:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530651561; cv=none; d=google.com; s=arc-20160816; b=bAxxCH76K6lCHZOP6sSYOINtGS6w+1W8XMzGMlUz7EmMAvhDvH57X3cHcDGMNINGSt IOWC+/fMMwH91qtt5H/v2D/Gn6ZF3qi4vNHRMpLH0tjkYo3sycf+KbWCPaLBjWxup4xt 4vVnZveEimBWjjiX3XT1fzLXdVuMgPB7/9GS2hR0LXVYG5L4GLS+6Gx2KzKaz0sBKI48 ZsgGDLoIjH+H6zMJExf6eMQjY5JLPqWQ/5SA4cbRnjZmNGH+V5h3Gl27fuPV9gGJuS8r PQaj9izFNCZe6Iacl0TP7TuAxNd/42EzCbB+q8RCqa9UsRFn/76mLC1D17wDojiCj7DX u+CQ== 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=xrLclTi3kQPh4AwwQhkSQPCvGPYNaGSb4PqLphkSe3w=; b=NtaONXsHYJXJV85CtP6GOkRGiQ562B0GtciT46Dcgf1WAfNuOnIUDK5mIEoor3AzSq e5YqpiDxO2E8f1kQpzzLtE9RHBaTWzKP35aAAJl9w/X7DoXqXc3/qYn2682vobKSVDh5 NsTKKeD+1CKTktL54muVD7SijxTtC49928N6aBdlYt6LN/95dxaNjHW0jL6JnBF9kA1a KOdtab1j76HBkEmN0910/QrEMoRfaxR5nctCs00CO/3SQkwxcZQSFyzy6sbnTvBluyc7 ociD4yMrc9q77JLihBjDRG/QkYsr7NQlQjCanDE/TPkk1lQBV6adImRTPTH2ip2lGzL8 Ea0Q== 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 x17-v6si1827798pfn.286.2018.07.03.13.59.06; Tue, 03 Jul 2018 13:59:21 -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 S1753101AbeGCU6R (ORCPT + 99 others); Tue, 3 Jul 2018 16:58:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43856 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752719AbeGCU6P (ORCPT ); Tue, 3 Jul 2018 16:58:15 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A82B0D5D; Tue, 3 Jul 2018 20:58:14 +0000 (UTC) Date: Tue, 3 Jul 2018 13:58:13 -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 14/17] mm: Iterate only over charged shrinkers during memcg shrink_slab() Message-Id: <20180703135813.ed4eef6a4a2df32fa1085e4c@linux-foundation.org> In-Reply-To: <153063066653.1818.976035462801487910.stgit@localhost.localdomain> References: <153063036670.1818.16010062622751502.stgit@localhost.localdomain> <153063066653.1818.976035462801487910.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:11:06 +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. > > ... > > @@ -541,6 +555,67 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, > return freed; > } > > +#ifdef CONFIG_MEMCG_KMEM > +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; Why trylock? Presumably some other code path is known to hold the lock for long periods? Dunno. Comment it, please. > + /* > + * 1) Caller passes only alive memcg, so map can't be NULL. > + * 2) shrinker_rwsem protects from maps expanding. > + */ > + map = rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_map, > + true); > + BUG_ON(!map); > + > + for_each_set_bit(i, map->map, 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 (unlikely(!shrinker)) { > + clear_bit(i, map->map); > + continue; > + } > + BUG_ON(!(shrinker->flags & SHRINKER_MEMCG_AWARE)); Fair enough as a development-time sanity check but we shouldn't need this in production code. Or make it VM_BUG_ON(), at least. > + /* See comment in prealloc_shrinker() */ > + if (unlikely(list_empty(&shrinker->list))) > + continue; > + > + 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; > +}