Received: by 10.192.165.156 with SMTP id m28csp213173imm; Tue, 17 Apr 2018 08:57:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Nn4oSP62hBl22BaZ+0+AmTKOeTiyuwUB7LwxeeuZqDmKibjyHqNn864oOrCSgrhUc25au X-Received: by 10.98.15.195 with SMTP id 64mr2444018pfp.63.1523980620855; Tue, 17 Apr 2018 08:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523980620; cv=none; d=google.com; s=arc-20160816; b=j7E7NhPBiLBW7clLbV3XAMyLGPm520cQkyrL/80FcKcVu2H2cT7JuqONF+BYnTS/D7 tjk2za1gNdw0a8tEZRO92hBX8qD/GY7Ta10LND58/AZR2N7WyiKRaeIwpmOI2o7h0b3k p/bB3NtIof5gv58MVHq1R3HKUhYDkWC/6bjAuMQ3zo3PS+H5aUwjHya4H0/MoK/UB57u b52Nr9FvSdCqLYyrVVsfFsdO2qUTTNWVF1Y2VQzZPmzdlZpVKRIAnLeNCsWSkjKFGx9V B+MycLUBcyvV3bcWCAGKzFyzFoLFnLdyUnIybIAVAKsqdcWQd9qIgRaF0vZEjS7anHQ1 3YbQ== 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=f5GgLY/ZNqbkxS1fKTH8zJMW9BeVLWpCfzN6nYxaNfE=; b=m20JOFlsr425kbiqVrOpJb01oKVZmUmHxInbhsX/Ek/h/kw61xSNmEjbsahOy/DNcc G/qVX3xiu4xYdG3AgtTFak9jiGzOok+CXJ/vOgtCU/cDDUx2fEdXST927ZP83JffZ5Or 1kJLkjKHmea0VJBrj+fkoVlSOyHxY9ghMx7VD+4Ika86LOocp+Hg594MF52ppCZ45yfF jqJPBfgsXeDIE7cG2ZOWpTOorcKNhV6Ms6ahokhXg7MjRseaXrBqG2/8HUeA1K482ITG JrNtPEVgxqyHx5t+v6jl/TlJ3NPC6eRppiQQur0aKyKOaDcWpHbm5PzY6fuPwap5S8/H RfSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=ibivi/cX; 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 q126si8268517pga.95.2018.04.17.08.56.46; Tue, 17 Apr 2018 08:57:00 -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=ibivi/cX; 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 S1753473AbeDQPzM (ORCPT + 99 others); Tue, 17 Apr 2018 11:55:12 -0400 Received: from mail-eopbgr30133.outbound.protection.outlook.com ([40.107.3.133]:56742 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753068AbeDQPzF (ORCPT ); Tue, 17 Apr 2018 11:55:05 -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=f5GgLY/ZNqbkxS1fKTH8zJMW9BeVLWpCfzN6nYxaNfE=; b=ibivi/cXpRE0+2IR0pbsJCs9G5Bmz0XKeDx1HYoJmuMceuegtv/KwbS4VHRePrCiYfuTu9R8395EiSOknkAH3rlXL6mIaExNXLuXAiW9RCqwpqUMRRw8v9u5oIA9J52WEiZ+AiL8bBK4kb/bcQOLmXwHEDAYw6sY4faP8dOPoHs= Received: from localhost.localdomain (195.214.232.6) by AM5PR0801MB1332.eurprd08.prod.outlook.com (2603:10a6:203:1f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.12; Tue, 17 Apr 2018 15:55:00 +0000 Subject: [PATCH v2 12/12] mm: Clear shrinker bit if there are no objects related to memcg 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, hillf.zj@alibaba-inc.com, 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, 17 Apr 2018 21:54:51 +0300 Message-ID: <152399129187.3456.5685999465635300270.stgit@localhost.localdomain> In-Reply-To: <152397794111.3456.1281420602140818725.stgit@localhost.localdomain> References: <152397794111.3456.1281420602140818725.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: HE1PR0802CA0005.eurprd08.prod.outlook.com (2603:10a6:3:bd::15) To AM5PR0801MB1332.eurprd08.prod.outlook.com (2603:10a6:203:1f::10) 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:AM5PR0801MB1332; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0801MB1332;3:7J9XsdRz85hRWhDEt/GIfO3RrsTFECfSqo+AZohXq74VlGZ1MFe2klDsRSvEBq8/pws/Vyf+bszZTAFZSlpXjKAl0mNfVjCN7r+OMoM0656+fKSlLbusy/+ggvZJVe1WB9z5aZWme9QRq0ZMQJuQ6gvNZVcQ1wnj5jY0nslUCNBvHHlh2Oyt0WIhXZ11X/stvAsAz3cy2SQ7F6hiJepMTAWETgBFbVMQQ5DhjN5wJ4rJyR8EPKbpxK8q5B715h2D;25:dj7raF16mPTPfmyEP69tZAR0zR1b3/K+4ceb531C+thiTDYPnUM+t3uK1h9TcUTU9MuV3K7WNM5myB2o8WajftSsA0l81IipdFUyPuCtuy1lpTfxcUO5Sl755FXkuckNAXtw5Y7F+hYYKv4eu1suvorkJw6SaG0XGWb7zTBU6r6/6e8Oq80V61/5THBeAwtRp25l27iZK92FPFLcDkf/bYrd2NWkpK1hn8rbATKas6O3Ok13IZEaWKFj/RqgNBJGTIJveIJ2HjNPm7Xy7v06yUO9dUlTTAucz3ke2JxFZGdIkmURIbLRxdwzwvbyTfhu5+tn9R4ZsjPiAHoBzi3WXw==;31:rPR8qvKgzs6I3DywGqNd4CjsrWCHBLE0/8JD+JoNIVH3AwLHhn3FGP7xfcuDYAXPu6o7nWZuCG85HjU4pG19JMJOLv+wu5ulfj/ucpuPIWjwuiJ9zPMo8TYf2qzE1tCx+G8kgrTvDuUI6ew/gDD7h5G4GL8qfQVg2iLDs/p9GXFSuyZgqyMR9BbTGFU4A6YvudQ9Hje3c8fUNXOE9LtErbS/PScISVuTuds2uEYIayA= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1332: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0801MB1332;20:xhjmS3jaO4gqJc3yd+DiX0ZYQg6CmNIFrnA8xJwKJYMLLbQb2y2ypjnicRLrXZ3potWhUHJkQIW/Gh4ybLmJsuGMvSpYxx8Upxqs5XvVo+MKjT/8Af8thBxp9Qjgly+imY6RDn3TXCi15bk1dHbQvy+OKFpXQd3xCGF3Qpyxd/yLWitJTBviXGSIC74aCw0NpE9U9NdhuJKfKpDKHfLSY0SfQYn+4w/AEHWxPAn+KN8aJvnhPyR+G1MC+R48bVeeEZhljh/pb1idKnOf9PlUguRRauS64EiUlzkU4qJdt+f6Go0uxL7AJ4JNW7lrkWGgPd3Q0sEgxoOVL4LJK4cFFQsUPnWJmn/hV2Ccxa0/lUiHgywPanHY/qznZieZKljCo+yNKUNH+s5iU7tnPM17u3uxW3kr0G3BLysUw4xPNX0VyGH9vufxtLn8SGrbB+Uik9WbrtBJW/bAXF8ZtiilyUISq7C8Uk5WXXeFhXuFaqOt1vaBrNzu2F/gPdCL24BZ;4:g9rkU+6RSvOC3RbonWL5ZVlUpitiBU8RAVEUMjJNewO7VJfdOzZ0sSfF+RA6E0i/FfiB66E0fLia1IQ97Ua8jHjarbDNRYF+aeTAU9J/gF1mZmnkdjN48pRzTzcvuV6NQNHOYdc8SGghuL/HLNPydWKgk3uHv0YjRFCaKw+oj3hF/hrwyRjwUk3O/qfyQH1sxbfNSwctVqpdeOR5XVBbmHZkhnbuaJIlytgUDW9sTzAPLC9b8wN+CA1U61/WbhNLbCUm20v98gWHmKFIQRig0Q== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231232)(944501359)(52105095)(93006095)(93001095)(10201501046)(3002001)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:AM5PR0801MB1332;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0801MB1332; X-Forefront-PRVS: 0645BEB7AA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(39380400002)(346002)(39850400004)(376002)(396003)(366004)(189003)(199004)(25786009)(230700001)(103116003)(478600001)(6666003)(6636002)(106356001)(105586002)(305945005)(7736002)(5660300001)(61506002)(97736004)(7416002)(50466002)(9686003)(53936002)(55016002)(68736007)(81156014)(81166006)(8676002)(2486003)(55236004)(11346002)(47776003)(956004)(476003)(58126008)(486006)(26005)(39060400002)(23676004)(66066001)(186003)(76176011)(16526019)(52116002)(316002)(59450400001)(386003)(33896004)(6506007)(446003)(86362001)(2906002)(3846002)(6116002)(8936002)(7696005)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0801MB1332;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?MTtBTTVQUjA4MDFNQjEzMzI7MjM6aWtIZ2JXMnVERWd6TEtRUG94dFZIQndH?= =?utf-8?B?QTNhT2ZwRW1Kb3ArTUwrWEZMcmlraTB4UFM0Y3dML1lEQUtGejdRUEZ5U1Vj?= =?utf-8?B?eWtYSVU4Y3RmWCtWMDJCVlY2OERwdVZkWlJldDNsbGtuL01VNG9RRW1kTFM3?= =?utf-8?B?TXZPN29uNFRFbnE0SFkvaUNXNGFENk93dXpiemxGRlhkdndKdHVTY3ZPdWFU?= =?utf-8?B?OUZvYURRUExLT0dSSHpobmhuRnNQVU83VVRCdmpMK1p0ZjdqMUh0SFpUYlZ6?= =?utf-8?B?VmhnSGNLSnIxeG9SaFBUemZwWEFNSWJRa05vaFp2RWx0a3hUcjFjU01DKy9P?= =?utf-8?B?aldORlcxZkdTa1poRTBIWE4zWXJVUTA0eDExcVh0N0g4a3VJNW9vbHA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w5aZA/RU3FEYLwC1lPJX4fxTnZlWevc= X-MS-Office365-Filtering-Correlation-Id: 2613c98b-4cf8-42b9-50aa-08d5a47b944c X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2018 15:55:00.0999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2613c98b-4cf8-42b9-50aa-08d5a47b944c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1332 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To avoid further unneed calls of do_shrink_slab() for shrinkers, which already do not have any charged objects in a memcg, their bits have to be cleared. This patch introduces a lockless mechanism to do that without races without parallel list lru add. After do_shrink_slab() returns SHRINK_EMPTY the first time, we clear the bit and call it once again. Then we restore the bit, if the new return value is different. Note, that single smp_mb__after_atomic() in shrink_slab_memcg() covers two situations: 1)list_lru_add() shrink_slab_memcg list_add_tail() for_each_set_bit() <--- read bit do_shrink_slab() <--- missed list update (no barrier) set_bit() do_shrink_slab() <--- seen list update This situation, when the first do_shrink_slab() sees set bit, but it doesn't see list update (i.e., race with the first element queueing), is rare. So we don't add before the first call of do_shrink_slab() instead of this to do not slow down generic case. Also, it's need the second call as seen in below in (2). 2)list_lru_add() shrink_slab_memcg() list_add_tail() ... set_bit() ... ... for_each_set_bit() do_shrink_slab() do_shrink_slab() clear_bit() ... ... ... list_lru_add() ... list_add_tail() clear_bit() set_bit() do_shrink_slab() The barriers guarantees, the second do_shrink_slab() in the right side task sees list update if really cleared the bit. This case is drawn in the code comment. [Results/performance of the patchset] After the whole patchset applied the below test shows signify increase of performance: $echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy $mkdir /sys/fs/cgroup/memory/ct $echo 4000M > /sys/fs/cgroup/memory/ct/memory.kmem.limit_in_bytes $for i in `seq 0 4000`; do mkdir /sys/fs/cgroup/memory/ct/$i; echo $$ > /sys/fs/cgroup/memory/ct/$i/cgroup.procs; mkdir -p s/$i; mount -t tmpfs $i s/$i; touch s/$i/file; done Then, 4 sequential calls of drop caches: $time echo 3 > /proc/sys/vm/drop_caches 1)Before: 0.00user 8.99system 0:08.99elapsed 99%CPU 0.00user 5.97system 0:05.97elapsed 100%CPU 0.00user 5.97system 0:05.97elapsed 100%CPU 0.00user 5.85system 0:05.85elapsed 100%CPU 2)After 0.00user 1.11system 0:01.12elapsed 99%CPU 0.00user 0.00system 0:00.00elapsed 100%CPU 0.00user 0.00system 0:00.00elapsed 100%CPU 0.00user 0.00system 0:00.00elapsed 100%CPU Even if we round 0:00.00 up to 0:00.01, the results shows the performance increases at least in 585 times. Signed-off-by: Kirill Tkhai --- include/linux/memcontrol.h | 2 ++ mm/vmscan.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e1c1fa8e417a..1c5c68550e2f 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1245,6 +1245,8 @@ static inline void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int nr) rcu_read_lock(); map = SHRINKERS_MAP(memcg, nid); + /* Pairs with smp mb in shrink_slab() */ + smp_mb__before_atomic(); set_bit(nr, map->map); rcu_read_unlock(); } diff --git a/mm/vmscan.c b/mm/vmscan.c index 3be9b4d81c13..a8733bc5377b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -579,8 +579,23 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, } ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) - ret = 0; + if (ret == SHRINK_EMPTY) { + clear_bit(i, map->map); + /* + * Pairs with mb in set_shrinker_bit(): + * + * list_lru_add() shrink_slab_memcg() + * list_add_tail() clear_bit() + * + * set_bit() do_shrink_slab() + */ + smp_mb__after_atomic(); + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) + ret = 0; + else + set_shrinker_bit(memcg, nid, i); + } freed += ret; if (rwsem_is_contended(&shrinker_rwsem)) {