Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1262597imm; Tue, 3 Jul 2018 08:10:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfrf+tOMm9ZDY0f3GmDWLIJRtOB1fpXdIvo3+Ce28FoK029DhyMVMRfYpHwR9BwbTdWk88N X-Received: by 2002:a17:902:5381:: with SMTP id c1-v6mr25709133pli.137.1530630659402; Tue, 03 Jul 2018 08:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530630659; cv=none; d=google.com; s=arc-20160816; b=h0NEVi2j6CiU9f8zQnjj/O1l0R5HHObWn9//d1yb+q02GhMSLkIGVjqkcTUNolJrS6 ksbeiJmjG3ekXQFMU5+H5uExoKdVzrXfslXMuPbKMaZp6bUZR9U12TpYjuTBukA8UoLv rjIkOtHxfv4F74iyjL/6AKA1Vh/0EuaEJ8JpMGYUFZToPaU3idpWftcS0k7dBe/8p0va UCGe5hncjw406JHZIinaWSMxJBZkuKGdczyqEKSAMrAsylek2ctmkgOZN3UGzIFDdJIt SRO1o5xaHlIxRRu7dFw3iDt/8ZABVnUQc3CHvVhPt89+vUu/T2KT8M0haP+1lofGFJlL 3PLg== 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=lGwDrx1nn6aZhN7pKlGi7jUOUb4d2BKvdbnM2cvitkk=; b=RhBX04GJeUO60jbKSawtNRlENONnQ9ro2TDeRkqQzKAqt52M1gYULXq80rtKZC1r1L Eqp5DjjRBUjtSevZBHyP0pfmRBx1c/LLmDZc5YFb/rDOCC9PV3oE3nrO34uzrniiAP9Z cuoosj4c8J8/8HGon7vEM168BOC2C+ew57pq6WXCifmF+JfcEKhxex18g3yhn0xgOdc6 8DLnOR1SBqw7ZfZpab7n/9riafx8Vf01sLWBA6sPk66G8F+bQL+mnxkdjQYOZUVMpOpb jFViRktMbMQtT5Xytui3FLPt6fstVB6osXBdi7EGZBPl/sxtioO2UIXwenSBX/Ask8wI JtWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=WtTkU8kl; 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 g4-v6si1353634plm.181.2018.07.03.08.10.44; Tue, 03 Jul 2018 08:10:59 -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=WtTkU8kl; 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 S933649AbeGCPJj (ORCPT + 99 others); Tue, 3 Jul 2018 11:09:39 -0400 Received: from mail-db5eur01on0123.outbound.protection.outlook.com ([104.47.2.123]:31104 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933039AbeGCPJe (ORCPT ); Tue, 3 Jul 2018 11:09:34 -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=lGwDrx1nn6aZhN7pKlGi7jUOUb4d2BKvdbnM2cvitkk=; b=WtTkU8kljaeNHqg7B5shFa00tWkGTIzcluaVmeeFs0XDGTNLxEblbR1v8MVU+xTEHC+kXhNYELJz+Kyzw/1KcUTmtUbBofm9GzqIMNtEOb6GRGWl0NeQfOOMkQUV1MxsA49waQ4zMvxeW4YmXa6dWFSSLSiq/wmLmQznid2YCB0= Received: from localhost.localdomain (185.231.240.5) by DB6PR0801MB1334.eurprd08.prod.outlook.com (2603:10a6:4:a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.18; Tue, 3 Jul 2018 15:09:29 +0000 Subject: [PATCH v8 05/17] mm: Assign memcg-aware shrinkers bitmap to memcg From: Kirill Tkhai To: 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, akpm@linux-foundation.org, ktkhai@virtuozzo.com Date: Tue, 03 Jul 2018 18:09:26 +0300 Message-ID: <153063056619.1818.12550500883688681076.stgit@localhost.localdomain> In-Reply-To: <153063036670.1818.16010062622751502.stgit@localhost.localdomain> References: <153063036670.1818.16010062622751502.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: [185.231.240.5] X-ClientProxiedBy: DB6P193CA0011.EURP193.PROD.OUTLOOK.COM (2603:10a6:6:29::21) To DB6PR0801MB1334.eurprd08.prod.outlook.com (2603:10a6:4:a::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cfac2bf8-4bbf-435e-07b0-08d5e0f6fa94 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:DB6PR0801MB1334; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1334;3:/qxvYNCrkQwkaMiujbzFCMb/QadDRlrkB/zpTif7N4gj2U3pXQfN0+P70aOP6BbXEq2pmMUBiy5qkdzIku37h8UPGfJWEYKvS1rdiYNIuZMk61D+h2IqWpS9Gk64q4R4B53gtk2R7uUPZbMZF7oZ1oaKHP7MatfSnUsj3drVMpn7KYx634myqjdrJU7PLQEorqfmwgCm2mH+4wdSxVQ36mBJlCiV4LmkHAn1obM//7UXUxQ/D9DbvzWTdW7oFFsx;25:gk19Uhpx5/zmlQsogppaTuP5ieIayiDdjWvEVvJ6vg+JSFBG6WaXhh1zzgQEpdGIseuPnHRzWgfBub0bgccXsVQETFC2Iqcb8XspyCeK27Z2pDBkEhJJW5smroi42Wusxv3QBjoYRgLIp3BJ8ipmO/VbfM2ByqjKS3fpj2U1+gmUj+ovBMOwm3udqU5DUGIeMYSPZ7IqJi/ICciEXhzykL0SUCj4nYdL2+StF4K73oYrhz4x8FvLvco6eqg49RIX/23fkt4xZ6u1InBL0zdaxJXfam+g8UlvOrqn/4B+SMC3vjKMDOYuhKeAaWxCTQxKB/v9DKCHLwzMXMRYEGQAqA==;31:G/gQvE9H/cSuDHaeKS8HGhvzrFnINY9KsojJOJ/puWZ5QOzw4oP5HDosZkteNfarPwM1eDZLZTsAZcN33DKocpatyUdtWsk/mixmDCLL4l74Kq+SVomPyzCSwVdwCUE4SS4i3EcCwuMye2g8S4E0JiVorMpqlpQHSz6biMQwJFVp5C/PJNHDguGE1DuGgWcwHK0wZh5f6xs5Dj3kEkEeGmxYs4WlZMi+Uk7Ans2FcYY= X-MS-TrafficTypeDiagnostic: DB6PR0801MB1334: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1334;20:YA779x2g1IPjjOvgb+VUTZI2XnaoPC85NMXiwbAyHMOIVuuNo4JV5nxl5t/FJDd5Ywp98U4Tg39pqZBKCUIgI0eHguyYCx96GtQRnvCDSwlPgpGZnbsZ55WPBs/qZ+u2H3bBSD5+WfqESg2YFhlpL/xZnXOQJ17wVGFkQIdSd8G5TrgwztohNAAFICw1NShvrPtCVGzkkuiyQG1q0Gmq3jGKiGSbdyzN/35YF7T5afFieH0eNuSXgCkEe8J20a/947+eCBxiN2dza7O8sNyH3YmOEJxhqkF8Yb6ZwqTGgoGfJW5Q3LZ4BGFxZSYWgqiYcRNrS65fXIBrSyzMuTSRXdfLBkAYYNMRJdfL7Aomu+C4guvi6t2K0o6o2SngKqmGxC5aPEH6z+co48Z4JxZmkh1D+OuXt2HZ2TxWaWrrimG5vvh7pOX/A0gEu9w3Zj/TEWO1F34/+RmoqQseWZHGhljHyQY1irX/dcC8w39a+N2vsakoh7hDRXgjP7C7YUE6 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(209352067349851)(131327999870524)(85827821059158)(211936372134217)(153496737603132); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231280)(944501410)(52105095)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011)(7699016);SRVR:DB6PR0801MB1334;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0801MB1334; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1334;4:NvZ7bQ4+/pBUOI9oYjno7WqrXWCOFcnVh6S9mu3OjW9xv52GatfWPeHW6T7EtFzgprDO60o3vMXeZy59ydekBfJom54qFln+r5n8DrWJzESFryD7vbvsnTJjfuaSGHzZLtXM/0iXR7MHw0BKUkE0E3S1/6UqDZ95KggIgmplbWI993Ed+lQQlC6lu09ErHoEQHn/+U2IIqThOYXIgdIGC+xoS08xWdpKco4WlWcJX6xZYh0K7DaNCR5xX+T3gf6NAERnA7OdUlRZPJQ9r1M8xPrReQ1KLQUdZqR9stZMynaRWQBN8NUu98wvWOK4t1Mb0Siv+B2HK1KGWuiCTBDYCQmMspKuVWOppTpgNOlcQJedKRxxXAJLTZOfAMpPfKS+VF0Jc/hcOQBrNXbFsUYHZSeZcp+U6nfOyiZtqVQxdWVZNVRuYEgy4yw7OBlgqueASvi4bSF18mCiTJKcR5ZQmg== X-Forefront-PRVS: 0722981D2A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(136003)(376002)(366004)(396003)(39850400004)(346002)(189003)(199004)(53936002)(5660300001)(39060400002)(6116002)(3846002)(106356001)(23676004)(316002)(2486003)(86362001)(478600001)(33896004)(7696005)(105586002)(52116002)(76176011)(6666003)(7736002)(50466002)(8936002)(305945005)(7416002)(81156014)(81166006)(230700001)(386003)(25786009)(2906002)(6506007)(8676002)(66066001)(103116003)(68736007)(97736004)(14444005)(486006)(26005)(186003)(956004)(58126008)(16526019)(9686003)(61506002)(47776003)(55016002)(446003)(476003)(11346002)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0801MB1334;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?MTtEQjZQUjA4MDFNQjEzMzQ7MjM6cjZudU1MOVZrVVVFVTVrSVc3TFhSZGdW?= =?utf-8?B?ZFp2Y2NUN1k0dU5rcDdXVktGbW04RE56d3dUWkRGeWNIZjlva0tCL09YVmFw?= =?ut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: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1334;7:w5tJzWdLHegT2yLsC7641EU95mhi407AlkJJNcae1ds44UfXTSbHW48Gnrj/3teF8LNG8kAKlmEW46xL0jsTaFsQuofLzIywhe0sSRyEuNRzYlAGlbNvV2eGS8AGKYYgCmSAPCBJBWg92Urtf7nZUD71Mh3KPd7IHsooXkBtd446RAyO1SaNh2bx5CiOAuJKIn1ARVN2UC8CUNua1t5OyjYdoFlFG2xhIQzKIug1xwhBMf8zReb516YqRh4gohlG;20:ibgISA9XDYW8noq1jS1cxlwT55iKZ5GDRkD6o9xXcSfl8+bUPspR6vxbEjCv1ASUh3WRVPEyntU+mI5wWWCxxHnx9s0wlOZnApyy8IfD8UMfgWl9XxvV8DghCiHB1TEqTAGeRfz4ck3IFIJ1f93kWPiGIlf/TUkgDPclcU0v4X8= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2018 15:09:29.4509 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cfac2bf8-4bbf-435e-07b0-08d5e0f6fa94 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1334 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Imagine a big node with many cpus, memory cgroups and containers. Let we have 200 containers, every container has 10 mounts, and 10 cgroups. All container tasks don't touch foreign containers mounts. If there is intensive pages write, and global reclaim happens, a writing task has to iterate over all memcgs to shrink slab, before it's able to go to shrink_page_list(). Iteration over all the memcg slabs is very expensive: the task has to visit 200 * 10 = 2000 shrinkers for every memcg, and since there are 2000 memcgs, the total calls are 2000 * 2000 = 4000000. So, the shrinker makes 4 million do_shrink_slab() calls just to try to isolate SWAP_CLUSTER_MAX pages in one of the actively writing memcg via shrink_page_list(). I've observed a node spending almost 100% in kernel, making useless iteration over already shrinked slab. This patch adds bitmap of memcg-aware shrinkers to memcg. The size of the bitmap depends on bitmap_nr_ids, and during memcg life it's maintained to be enough to fit bitmap_nr_ids shrinkers. Every bit in the map is related to corresponding shrinker id. Next patches will maintain set bit only for really charged memcg. This will allow shrink_slab() to increase its performance in significant way. See the last patch for the numbers. Signed-off-by: Kirill Tkhai Acked-by: Vladimir Davydov Tested-by: Shakeel Butt --- include/linux/memcontrol.h | 14 +++++ mm/memcontrol.c | 120 ++++++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 5 ++ 3 files changed, 139 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 62309f180ee6..d8c38eafa251 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -113,6 +113,15 @@ struct lruvec_stat { long count[NR_VM_NODE_STAT_ITEMS]; }; +/* + * Bitmap of shrinker::id corresponding to memcg-aware shrinkers, + * which have elements charged to this memcg. + */ +struct memcg_shrinker_map { + struct rcu_head rcu; + unsigned long map[0]; +}; + /* * per-zone information in memory controller. */ @@ -126,6 +135,9 @@ struct mem_cgroup_per_node { struct mem_cgroup_reclaim_iter iter[DEF_PRIORITY + 1]; +#ifdef CONFIG_MEMCG_KMEM + struct memcg_shrinker_map __rcu *shrinker_map; +#endif struct rb_node tree_node; /* RB tree node */ unsigned long usage_in_excess;/* Set to the value by which */ /* the soft limit is exceeded*/ @@ -1284,6 +1296,8 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg) return memcg ? memcg->kmemcg_id : -1; } +extern int memcg_expand_shrinker_maps(int new_id); + #else #define for_each_memcg_cache_index(_idx) \ for (; NULL; ) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 74247a580cdd..f81581e26667 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -320,6 +320,120 @@ EXPORT_SYMBOL(memcg_kmem_enabled_key); struct workqueue_struct *memcg_kmem_cache_wq; +static int memcg_shrinker_map_size; +static DEFINE_MUTEX(memcg_shrinker_map_mutex); + +static void memcg_free_shrinker_map_rcu(struct rcu_head *head) +{ + kvfree(container_of(head, struct memcg_shrinker_map, rcu)); +} + +static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, + int size, int old_size) +{ + struct memcg_shrinker_map *new, *old; + int nid; + + lockdep_assert_held(&memcg_shrinker_map_mutex); + + for_each_node(nid) { + old = rcu_dereference_protected( + mem_cgroup_nodeinfo(memcg, nid)->shrinker_map, true); + /* Not yet online memcg */ + if (!old) + return 0; + + new = kvmalloc(sizeof(*new) + size, GFP_KERNEL); + if (!new) + return -ENOMEM; + + /* Set all old bits, clear all new bits */ + memset(new->map, (int)0xff, old_size); + memset((void *)new->map + old_size, 0, size - old_size); + + rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_map, new); + if (old) + call_rcu(&old->rcu, memcg_free_shrinker_map_rcu); + } + + return 0; +} + +static void memcg_free_shrinker_maps(struct mem_cgroup *memcg) +{ + struct mem_cgroup_per_node *pn; + struct memcg_shrinker_map *map; + int nid; + + if (mem_cgroup_is_root(memcg)) + return; + + for_each_node(nid) { + pn = mem_cgroup_nodeinfo(memcg, nid); + map = rcu_dereference_protected(pn->shrinker_map, true); + if (map) + kvfree(map); + rcu_assign_pointer(pn->shrinker_map, NULL); + } +} + +static int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) +{ + struct memcg_shrinker_map *map; + int nid, size, ret = 0; + + if (mem_cgroup_is_root(memcg)) + return 0; + + mutex_lock(&memcg_shrinker_map_mutex); + size = memcg_shrinker_map_size; + for_each_node(nid) { + map = kvzalloc(sizeof(*map) + size, GFP_KERNEL); + if (!map) { + memcg_free_shrinker_maps(memcg); + ret = -ENOMEM; + break; + } + rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_map, map); + } + mutex_unlock(&memcg_shrinker_map_mutex); + + return ret; +} + +int memcg_expand_shrinker_maps(int new_id) +{ + int size, old_size, ret = 0; + struct mem_cgroup *memcg; + + size = DIV_ROUND_UP(new_id + 1, BITS_PER_BYTE); + old_size = memcg_shrinker_map_size; + if (size <= old_size) + return 0; + + mutex_lock(&memcg_shrinker_map_mutex); + if (!root_mem_cgroup) + goto unlock; + + for_each_mem_cgroup(memcg) { + if (mem_cgroup_is_root(memcg)) + continue; + ret = memcg_expand_one_shrinker_map(memcg, size, old_size); + if (ret) + goto unlock; + } +unlock: + if (!ret) + memcg_shrinker_map_size = size; + mutex_unlock(&memcg_shrinker_map_mutex); + return ret; +} +#else /* CONFIG_MEMCG_KMEM */ +static int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) +{ + return 0; +} +static void memcg_free_shrinker_maps(struct mem_cgroup *memcg) { } #endif /* CONFIG_MEMCG_KMEM */ /** @@ -4541,6 +4655,11 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css) { struct mem_cgroup *memcg = mem_cgroup_from_css(css); + if (memcg_alloc_shrinker_maps(memcg)) { + mem_cgroup_id_remove(memcg); + return -ENOMEM; + } + /* Online state pins memcg ID, memcg ID pins CSS */ atomic_set(&memcg->id.ref, 1); css_get(css); @@ -4593,6 +4712,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css) vmpressure_cleanup(&memcg->vmpressure); cancel_work_sync(&memcg->high_work); mem_cgroup_remove_from_trees(memcg); + memcg_free_shrinker_maps(memcg); memcg_free_kmem(memcg); mem_cgroup_free(memcg); } diff --git a/mm/vmscan.c b/mm/vmscan.c index f9ca6b57d72f..d8b1958c751d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -182,6 +182,11 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) if (id < 0) goto unlock; + if (memcg_expand_shrinker_maps(id)) { + idr_remove(&shrinker_idr, id); + goto unlock; + } + if (id >= shrinker_nr_max) shrinker_nr_max = id + 1; shrinker->id = id;