Received: by 10.192.165.148 with SMTP id m20csp923668imm; Thu, 10 May 2018 02:54:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrOTw34FsT6RZ2RTaj/MmnVmjKFdnJr0pS5KFZd5u1Vb24v9tH4ZOaRxKr6I3xAFlRJ09UB X-Received: by 2002:a17:902:2a43:: with SMTP id i61-v6mr762254plb.54.1525946093083; Thu, 10 May 2018 02:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525946093; cv=none; d=google.com; s=arc-20160816; b=y2V6+tZajIg1Ya8ABnKMb9MgdEl32jcobCSZlteHcIuL4QJSh2R08qoWMcpm/vH2C/ GPWhSJdz9k+nQgXHALZZgt6yEz6meovkyXO+ja4pqCA3F3Sx8zQcQaCoU5gN2Ko56ge5 DJsUGrIaS5SeQp0Nuq9Rl7O1W5vOd651VjC1PSfiR5ZEFnDKUrPFKcDZchrfEp3V5D66 G7soPFX3sx48qJDBS7qIShS3d5rX01mqSHgJi3uPnextRGsoRJj9Gk3zPkvUVLwLRT4h 52kiYZgSGBleDgVM0UumA88SXX0RjYEeoaZ0BPD4Bs7EGv03QJOJrMpCulzVCyACdTqo CuTw== 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=H32YWD1cM0yVnGiOjrbNIUiAwtkUBs3L/HxRaNiexuA=; b=nOh1CAqw++svUKr/G9wNQVpJBAcv+xs51c1D0c6oWapdR4MXiqroFvbP0ldGChMIYU fdWNaujqLU/nMqR0k0Ai1DpYOdXCd93WPcw06fKMz7vruGaI8HtT11RZbyPJtcUeJyui rwU9K8JXFO2tzOeP9btq5Kd/xWz+IdVw3kx6WmoiKj2MEfzpu64eW3drUNFLYXgYJ5n0 r7fOvVJocqbRHHy2nEIh8cWh7ttGdA1y76C9lnSI3BtaIxSwpg4Zb/tqK6xQ5Q4ee8sF 4T7lql20h4RRSTJW4BgVULH2vGExcNAaU5/6dBYVDYLJMDCDpaHmwHlM4B/Mj/ot4GRG W3MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=Eu3L+Y1s; 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 z15-v6si366560pgr.615.2018.05.10.02.54.39; Thu, 10 May 2018 02:54:53 -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=Eu3L+Y1s; 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 S935247AbeEJJyH (ORCPT + 99 others); Thu, 10 May 2018 05:54:07 -0400 Received: from mail-ve1eur01on0127.outbound.protection.outlook.com ([104.47.1.127]:42912 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934661AbeEJJyB (ORCPT ); Thu, 10 May 2018 05:54:01 -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; bh=H32YWD1cM0yVnGiOjrbNIUiAwtkUBs3L/HxRaNiexuA=; b=Eu3L+Y1sN3+Rvdrx6jqYhNichp32RyeB90UFXesDE7iBsy8k6kZX/ZsaVAX/NyR0lVHIhJjQCkFriqupZQyhzaEq9OS3OW61eXZQGewtRsN88CUVYx/a/Zc15bsZSLBp7AmJ0WbkyHBwJnBRIp0zEwEd+t5r/+eGNpgTtqqefjY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by VI1PR0801MB1343.eurprd08.prod.outlook.com (2603:10a6:800:3b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.735.17; Thu, 10 May 2018 09:53:57 +0000 Subject: [PATCH v5 11/13] 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: Thu, 10 May 2018 12:53:55 +0300 Message-ID: <152594603565.22949.12428911301395699065.stgit@localhost.localdomain> In-Reply-To: <152594582808.22949.8353313986092337675.stgit@localhost.localdomain> References: <152594582808.22949.8353313986092337675.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: AM0PR0202CA0011.eurprd02.prod.outlook.com (2603:10a6:208:1::24) To VI1PR0801MB1343.eurprd08.prod.outlook.com (2603:10a6:800:3b::7) 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:VI1PR0801MB1343; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1343;3:NS3TSTt1ZB9jI8NHtEtdGDrWZ1Rhz1eOhOCxXho7DMwhjtaFcs6odn+L3jViQQaqF31zNeKJEndb+e6jI6ib9locRzIVIRSwopbkmh1Stup030wKwPIyh4OksVzujIOYCkh5ZmEpVwjv4B49xORMJWnEvnERsWGfeNzya9GH0IQj3RhmqhpBcjrMKO4svVZNeon9ZuAZmpPvuPnlVII1pq+coTNKJ+ID3bmccUI8s2K7TjDhNBhDCE/T4Aamw7Wx;25:E+8LoXt2A/LZ8IQ4yV85khvYZ/Bj8RYkJXJTf8FHNH10W/6OQLM0hGgg59a0Wj4kRfJJ2uBpvhR3G0l1V8jZBF4jWChrWLzODTVgMakiSPqdwLTUnrfRMyCBk4hyGzinEkAa6cw1JARKZ6L86BR+10eOlUOo83BRP0F6sfr0BQsd+XThWWVX8omHecNdjCPynJxUvj0bJX1xUu2iR1hFahZ/Lm+7h9beUew25I/dUImnDd8hS/E/C1goulWAZpPMP5f9vyzBpFIx42okUS/vIjt689jeH59MQC/qNHMKXQfdjbS0KaXIiGDXIwBzl7tgKB+WmZlTWLaWBYrjkVhUjw==;31:dZ4ymB5Y+9QM5uUB/TxYWDY6uE0KAloG7HBX6vtWfamCU2Y/PRcW0UTVeNId0hKy2A4fDGaDvwiduS294Ee+WE5wmPzqmXGxmWwTmv9F/CNS3vDnp4vlToYQdQeU3u2HWcfkZmk71YbTn/GP0QQjTneNr+AUJ+EAmfS93/BvD+GnbV5gTscMKbRwA2+SxyQ2cfnG966D9QLIA0d0zIy9sN7JJfnDcdu34K7ISGErj0k= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1343: X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1343;20:Zgs5QFAABIvQ4c58vqlFP6VtmrInhsE2gYDKrFPDPyTnakpz2a6l1aNh4b7qvJhkOBr4KJK2RFte1eMRmTWwuW1a5Qi7lQyrM3pPWTxM/FMwwwNbt2Q8CAs+yvZbHsQxxT8EMKwbh1vnjOAbD207J5s7Ag8jSi85lrDAgr2ihRVzVXy7kioqpWAZcgCTx3tyFBnnkuiFA7Y0dXoYRs1yir2W/60tq2vnN4RtihjmNROb+uEDMEK7f4uB+4jlTl76hYXoDG+wYXe9os/WLfKJSnt5rp1cH6ZpR0lym1f+OVUAybtRCfpzN+EEB68m+TzYnvDA2Id2zjtWnW0kbKG4FCNcFX6hUBLNYUyKGiiLYv2KlxYxQTdUiqY9u0KBK5Ack6HAwHn4EfqTRR6ZPmK4zP4m+KhGSYS29y60MqcQDK5wEwEGGYpnub3Kl/RXeKhDSPbqspW6BamLEuSNGCVcBvSVCgnBj1r28AtOoBY/PqioY3P8urc06oRRBFG7VjOU;4:UNeClYu+Bk4EctSah3i/RoYuIaHI+QZ2MLH8CM0dxD/pAb8vB0IWXoUWhdhvxPHdhRXR72try6y6Rbpua2jE2hVHAHbs3F95kPZOVkQ4wG4XaUa60uSA2N4rKUPt3zUexef8y5PDylBVD+K6AS7rMXCWBGstKTFlZaYGxOVE1NXoIzvZVM49c4JSOg9SiTB5sKB3mFbT1OHPw5Cmz3YW0MzP5JV69LeZ6VhgU6UVGYSp6EUpIHVwie7xdqwX7vmyFPu/GTaXY4JI2i7VJ5+55A== 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)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:VI1PR0801MB1343;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1343; X-Forefront-PRVS: 066898046A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(346002)(366004)(376002)(396003)(39850400004)(39380400002)(189003)(199004)(25786009)(6506007)(5660300001)(103116003)(230700001)(39060400002)(97736004)(476003)(53936002)(486006)(81166006)(47776003)(81156014)(105586002)(106356001)(8936002)(66066001)(956004)(11346002)(55016002)(9686003)(8676002)(68736007)(7696005)(23676004)(61506002)(2486003)(7736002)(52116002)(26005)(305945005)(55236004)(316002)(86362001)(6116002)(3846002)(186003)(16526019)(33896004)(386003)(59450400001)(58126008)(76176011)(6636002)(446003)(7416002)(478600001)(50466002)(2906002)(921003)(1121003)(309714004);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1343;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?MTtWSTFQUjA4MDFNQjEzNDM7MjM6ZHkzNnN5eGhnczN3K0NDdHZSb0xlRm1M?= =?utf-8?B?VnZVWjdBVXBscmFxVkh0RUhZOHY3bWVNMUJtTElRamQ4ZHZsYnU0U2RTVVEx?= =?utf-8?B?VG9MQ1NVby9Ld3BkUm9WNUdIUnRGbmtjUUNlV3RuaW93Rk0wdVFUSzVKVStp?= =?utf-8?B?Z24zTFlOMjFSMXU0eHRsVWJzbzlFTW5EQTZvSys0azZJTDRrZVAySk9xbkR3?= =?utf-8?B?R0pWbnRRSEFsMDNZYmpnaiswcnBnT2RkRFhaUWV1OXRDYi9qM2Nycng4VlZM?= =?utf-8?B?UnJ2ZVpSQzBCVmI3SUFEanpaMWFGVE9sQ2luYzFiTENuSEtac1NwZTA2aWtp?= =?utf-8?B?a1pkbVJnemsvUDM0OU82WkRHaUJCUDZrS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nSKOOnHf7r3+t3NzjSDCqZpAvnGAwKHWaNkf53VHvpD7Frwo55zYYI= X-MS-Office365-Filtering-Correlation-Id: 1ab96571-7986-4264-55c8-08d5b65bf3db X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2018 09:53:57.3559 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ab96571-7986-4264-55c8-08d5b65bf3db X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1343 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 --- 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 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); 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. + */ + 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; + } + if (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_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) + 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; if (!(shrinker->flags & SHRINKER_NUMA_AWARE))