Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1381051imm; Tue, 22 May 2018 03:12:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqxpP5fH77uIKrF+OifVuzYBx6w5FYBPVEIp+r2N8X5888BN2I+DQeCFT0KWCtwgJMBK+pg X-Received: by 2002:a17:902:988b:: with SMTP id s11-v6mr24074035plp.304.1526983949965; Tue, 22 May 2018 03:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526983949; cv=none; d=google.com; s=arc-20160816; b=tm2+e/e/q2PjyAPN8FWAEVjUgPlpDvoG1tKwslk0cG3F+X2Otzl0DWLK9fcbeqh5cN QSd8ybGkAuFh7VgiFGxq6WwS8HnPIYJqHcVWpjqIH8+lSLX10AcMXnUDSdpORoEVKw35 /1bzb3Chx02geBugnItSzX2zi0lzRyaLtZjuFTet2ZxxxzgSKf9v+/EBkMvUyJfZZ2ab gpLRHSfcbGfXsr3vjXDusEVfkQPnZRCV+s8C34fzM+JzQowQvo80iB7CubJ9i6LDkCmh bCZy7TFpw7ihvdu7rh5zI2wufl/pA0YxO6EDgXvtiGk1DOtSx4OY+h+EjY3MHX20Rb59 rCGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject :dkim-signature:arc-authentication-results; bh=4oijJ5d9KyctgdtEicyqtPoO/AzCJ55A543+tvd07/M=; b=q12r41q8fL4LkVHDa9h8+irsm1DmD4iOndyW+19PGPtGkajXyiu78Ffgf1r4bmQ4tw qo8XqaqCaDRVJ5KAmtNBxmeUb7LRrCcxj+nJZfI3kyk/R9PqexWpdqqhVodaNcYqnEV/ jLKOIlNl8HnVxuDcMDJUL/vyKdQYSkGxRSoY239jXNsZPCB2XyvPATPtdXlc91LWkjJC bHehebQ7nkLytGsu5W2sBGMaLG5ZsgtJudJo5xQJh2UwxXxVqAUOhCPQRKcTSrhOX3m4 P3PoCVdYMjhRAkgTWWpcoqK6K4Nbh/h/V7QTJWI39MDeCZXGE15UxW/m3Gd+T+BWg/41 hEDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=ZwuR4Tz0; 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=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15-v6si1221834pgv.125.2018.05.22.03.12.15; Tue, 22 May 2018 03:12:29 -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=@virtuozzo.com header.s=selector1 header.b=ZwuR4Tz0; 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=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752308AbeEVKKT (ORCPT + 99 others); Tue, 22 May 2018 06:10:19 -0400 Received: from mail-he1eur01on0125.outbound.protection.outlook.com ([104.47.0.125]:9578 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751443AbeEVKJx (ORCPT ); Tue, 22 May 2018 06:09:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4oijJ5d9KyctgdtEicyqtPoO/AzCJ55A543+tvd07/M=; b=ZwuR4Tz0mELyJLbXTpzPYvnnNfFMHiX+ubdLXeHSXknUTLZ4BKT//M91kqLoYjcMGXAJj9W0AIUM/HdZXgNBQFvQnC4A6JIM/PZUB2BixXZMcjvRy5lRrFeWIvy4ilGCj0Vw5UW5XPzuSXy9AlXfRwTe4WAUxlMfxaULTHpfkD8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by VI1PR0801MB1342.eurprd08.prod.outlook.com (2603:10a6:800:3a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Tue, 22 May 2018 10:09:45 +0000 Subject: [PATCH v7 14/17] mm: Iterate only over charged shrinkers during memcg shrink_slab() From: Kirill Tkhai To: akpm@linux-foundation.org, vdavydov.dev@gmail.com, shakeelb@google.com, viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, ktkhai@virtuozzo.com, 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 Date: Tue, 22 May 2018 13:09:43 +0300 Message-ID: <152698378300.3393.14754283083814172297.stgit@localhost.localdomain> In-Reply-To: <152698356466.3393.5351712806709424140.stgit@localhost.localdomain> References: <152698356466.3393.5351712806709424140.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: AM6P193CA0013.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:3e::26) To VI1PR0801MB1342.eurprd08.prod.outlook.com (2603:10a6:800:3a::28) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:VI1PR0801MB1342; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1342;3:FIao7FOzdzGiKAoF+arv6ubYmD3i0UtpLQg0D/O/+dpcxLuQzwgFhGVh+rPhMAre5IY6pLYT6LJlLXpnZcEPtu3X9Z0TF4bHbNWYoC8BLvClH5PrRYO0UK7/rAdI8qLjRdSqFGzcYHI59JD1DI67Em/AibVFaovQl0HRJyDG/crVpuGa0zpG7l3PDVaB//PQL3AVZrwd3jtfXqxdfo2E0J42xlxtyTjbWixDJfPEc1s5oX/kcpVu2gDuNsJAg/Au;25:d/c/6IV57TA2fek9U/cflM+x4KLdshWLXc2SlvoH/GiUBAo1v2wb1URc0zADL7lfFnvEj3gqi7kXMpq7QCxi8dHFI55vfRyJ5z9Vyync/IQ2GtapfDDKrn1DiDw2U3Ul/K8aH72tS90rBpR10+RVoktPNjyqLxBTXnFlnuxsvnK8HCXcah2EyNrnfO0ApJr/Fj/o0cpfO5b3i6VI6o3Mp6/nOJGwKfgZ3vlTFYwnI3t4vJQ5ju2qepRkIbm3rjGg8yHRltaUCUVu9FsfHD4c9gwBFbur1KgYQne97tSpNn/j3RvxGNQNv6IHQxFadl53YYcXkpj4/TOulDnrnyFPBA==;31:k3T+g2AXVZrn9JzQwcDnzyCgj2Mcwm5jW8NgYiJAvDUke0Ap24s+mLNn4AH8BxJcCY3Nz0de881JCwm+mMGaTpHUToXtGSvEF2Z82A1ubWVMVVdiVE97yBYN6xUPNUudSJ0RiQsO+3/tdcAxl9aSFN2rpnYf7eqW40tl5cScmgWjTpanRJZDYcSXibyf8C5kmMBHmTYVeD3w6331qaPNozZNlveDVLSbPeC9f6kNwZI= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1342: X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1342;20:AzvgOlTV2j+/5+8g2Mwng00XQzdcM7yVcDbIPH6RMINLuHnlAOA37kOlWDL9DPNUyJK9aEURngLStFWppb5eyanbddDppLfwxdozB+SemdCyUajtY8+4gpPQLGvLT6tQPkRMkp6v6+ebcfvZh6pnEgpRj7nPL1p8jNbuWrG4h3MTrLJAl2NbYr3GAlNKXqOSAHcWqp2+ITY0hMdQoL0dqIhq5VXX2ZUHj7OsHCmOyxJm1museCgeVgExyjJmSdcS2wi4eCldSIvCOtMSJZ0CKkBelfQuh1+/jdLIWi9krjmy69OlrKAZEn+zVuIBb4f50MyfDWoDCyyGTVWk3mF4L01gWwvOqzmmKKr3vQM4wJYLfygTmELyWYkU5trGVxYWq77MYVZRvhi72+0aPcqvTxTJEvFuQ810fuO96WpqbNGKad2kjAHSVJZiF8P2Fw7dhjOAk5oHDDPHhRVmtfzSrMuqNKpxkgSYi3lYE6LC9CDK8oz0/RD1AmSj8Ws7BbeH;4:01P3fehXqvm0pXWVOiP24v7VnMnz74Ewsk5zFB2nQA73soghFEH5Mbq6hRU3sIrtghPzbpusiiZRvVkwtwmons9/gUHNOYIQgSRSASvSY8sFMUMvF3SGpfr+WoxgiYfaGVDqhKWC6hHHHLOLBhgvhqf6eljoVm4jXgxnyONE2R9LaffwvhoaIepnpLO9JWbDEK2bnnSHU2L8pLfyQnYhT7zfTlhIabRDT6bGVzni7r6DCx6jPenin6K/wAOJt/7ulvY4m3yLvN3xtMhvn6SOlg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123560045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:VI1PR0801MB1342;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1342; X-Forefront-PRVS: 0680FADD48 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(346002)(39850400004)(396003)(366004)(39380400002)(376002)(189003)(199004)(39060400002)(50466002)(81166006)(61506002)(55016002)(53936002)(103116003)(478600001)(6636002)(7736002)(316002)(305945005)(8676002)(81156014)(66066001)(47776003)(8936002)(105586002)(58126008)(106356001)(230700001)(476003)(97736004)(11346002)(956004)(68736007)(446003)(486006)(25786009)(7416002)(26005)(52116002)(23676004)(386003)(6506007)(9686003)(59450400001)(33896004)(55236004)(86362001)(2486003)(76176011)(6116002)(7696005)(5660300001)(186003)(16526019)(2906002)(3846002)(921003)(1121003)(309714004);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1342;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtWSTFQUjA4MDFNQjEzNDI7MjM6WlFmYmpsbWowellDK2ozWmFIbnlLaTFY?= =?utf-8?B?WDRTZFlUOGRZSndGK1Mxd0thTmNpbW9reVcwcXhGM2JRVlVkY2k4ZndHVEdE?= =?utf-8?B?MllzbmlzK2VWOWVaa1hvNkRLR2JTaGdsOGFwbFBsRzZYZVZYN2hFb2RyTjJX?= =?utf-8?B?ZnlabFM3SVpHN3Y2bFZ6VXBLMnl3eThjVFFXTGhnQk84UjlsR1lRNExSc1Er?= =?utf-8?B?U0x5T0VCRk5wYXVHaGJQSFZmS1lZSVViUjNhU3FVL2N6bzJtUjVIc2huWk1M?= =?utf-8?B?cFpYQTVsRC9kam8yVExrbDJSYWdXU05WS3lQN29XYmgxaTJlbStaeC82dDZ5?= =?utf-8?B?M0VvbEl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W6a6fLC4kdELFXbcDZdddOMp37fyW9V0dIkuiqXsUhVAvVL15IN08QEpKGjkCtvgB4GBZUS9DofmTFvPHCM9jX4c6yOnm0ZM= X-MS-Office365-Filtering-Correlation-Id: 8a5f9f1b-f042-47e4-b3f0-08d5bfcc25ff X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2018 10:09:45.5476 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a5f9f1b-f042-47e4-b3f0-08d5bfcc25ff X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1342 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- mm/vmscan.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d8a1ca350a58..f26ca1e00efb 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -367,6 +367,20 @@ int prealloc_shrinker(struct shrinker *shrinker) goto free_deferred; } + /* + * There is a window between prealloc_shrinker() + * and register_shrinker_prepared(). We don't want + * to clear bit of a shrinker in such the state + * in shrink_slab_memcg(), since this will impose + * restrictions on a code registering a shrinker + * (they would have to guarantee, their LRU lists + * are empty till shrinker is completely registered). + * So, we differ the situation, when 1)a shrinker + * is semi-registered (id is assigned, but it has + * not yet linked to shrinker_list) and 2)shrinker + * is not registered (id is not assigned). + */ + INIT_LIST_HEAD(&shrinker->list); return 0; free_deferred: @@ -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; + + /* + * 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)); + + /* 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; +} +#else /* CONFIG_MEMCG_KMEM */ +static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, + struct mem_cgroup *memcg, int priority) +{ + return 0; +} +#endif /* CONFIG_MEMCG_KMEM */ + /** * shrink_slab - shrink slab caches * @gfp_mask: allocation context @@ -570,8 +645,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 && !mem_cgroup_is_root(memcg)) + return shrink_slab_memcg(gfp_mask, nid, memcg, priority); if (!down_read_trylock(&shrinker_rwsem)) goto out; @@ -583,13 +658,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; if (!(shrinker->flags & SHRINKER_NUMA_AWARE))