Received: by 10.192.165.148 with SMTP id m20csp923959imm; Thu, 10 May 2018 02:55:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoxz5cC89nKHs52BzOjXYBGkBY9SJgmcztqw73Mrxad26uYJgzSWrP5VrcovAA2RujsrpoE X-Received: by 2002:a62:f58b:: with SMTP id b11-v6mr708487pfm.113.1525946112047; Thu, 10 May 2018 02:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525946112; cv=none; d=google.com; s=arc-20160816; b=VCTAHZ3JeRSoZaPteapo7Idz1M+S1pe57cB/46iqJ9rJra8SHfZmR2iaTv/RNUQ74C 30r4zsmq5Aqu60Ljn5QP+ap2Mpj4H2SrqiEhVui84WbdDTvvxS34g7wr6OmpW2iXhnJE VIA/qq9bB/ccxHcmFxK3iyO6TW4uGtO7Xsj4OdiEJ1ifDwmgPmplGjzO00ezXb/q4n36 U7opptIaMUTPTgLdNMq7Xhfa6xKlW0oeaX8HXDgEFmlIZJ0HJmTlvRmyMH3hRsJNs6W1 ZGSuV2lyQRYYyVPdrCPIrUIENjK0MJb3jc6G768RWrzj9TxEPAvHpYhJjVCvaHZ7/I37 YBjQ== 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=nLiaIQEkR6LvoUDFu1uhT04EtxhfvJavbLrRQPcdzuI=; b=0qIsuSBU/1eQ8kIx7oDSLrkj7HbJAgbCMjUDit+qExegpPNLK5eLEQ0AK7LcjDz9CO v6om42lTjBN6tBaG9/ZPmryGB7gr5lZxLbPPnj7bHprPfYVLnAFmoMucZrl+VF/ebNU1 l5thqyJNkTlamz6oaRHthp2Lq2rvmOTeulk4+cpuyrcpPVkU6CoPb1rx91U3fEoPS+mL Ze+SWTnLhWBruMcwl4YGQ9Tbl1GDBwnrWnSHyTeYhYFQ7AfLU4Omult3VaZlPuDHs5/C sY5zYOWnIwrFIjSyqUiDlSIkJ62Dqglrk1ehdxnFd0ZRJxkG0oLpbYUZTJeQQK3zmmcj SchQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=HaisNl3n; 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 k10-v6si362380pgo.23.2018.05.10.02.54.58; Thu, 10 May 2018 02:55:11 -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=HaisNl3n; 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 S935326AbeEJJy0 (ORCPT + 99 others); Thu, 10 May 2018 05:54:26 -0400 Received: from mail-ve1eur01on0111.outbound.protection.outlook.com ([104.47.1.111]:63534 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934661AbeEJJyV (ORCPT ); Thu, 10 May 2018 05:54:21 -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=nLiaIQEkR6LvoUDFu1uhT04EtxhfvJavbLrRQPcdzuI=; b=HaisNl3nc8Dy3Rrvil4gfej6YX0+VBTgv3qdI+6HhJA8jdAaKQWd21hAkWUiPqmux/wbjMC6f492uIp3+JAkM2cEmPcEaHLxZbXTtKWORysYqbxP3H0c1FeRlWnTanIfDF2rF4ypAxrxN5rKZ/HDUNDh5rDE8xgpko5HRTk2IFg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by AM5PR0801MB1330.eurprd08.prod.outlook.com (2603:10a6:203:1f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.755.16; Thu, 10 May 2018 09:54:17 +0000 Subject: [PATCH v5 13/13] 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, 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:54:15 +0300 Message-ID: <152594605549.22949.16491037134168999424.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: AM6PR07CA0004.eurprd07.prod.outlook.com (2603:10a6:209:2a::17) To AM5PR0801MB1330.eurprd08.prod.outlook.com (2603:10a6:203:1f::8) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020);SRVR:AM5PR0801MB1330; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0801MB1330;3:wOA2VU1zo7DPjoHvWgMYFiR1489peMvh+fZdmeTCF14gJ1eRHB+mhi/z6D8VM3elcyftNfog0tFJQUCOrKlecCsoU/KNwCan3PjM0+lE+IVJQ7K38A3hqWY7g9FdSD0WxOXZGIlzXDOwCPLB2BpuPqDLEBAFzTYtEaEQPIyX3V2M19Watx+4ASlRqvdunW7mCEWjA6KTSU3b7TsqGNl3yIGSWcXzb+NV3mbn14JI46ufyYKHJ+k52nRmH0ZEsGqn;25:/q3C5Bqf9LXAoxISgbv+SAneGN9E+PodBAF13ii9XkJLMNYM0RYvanENhS1oKeYbMKYEmIY4ihdF3DHT5LVC5XkgtJVw8PxOwvVNFc3ecd8BnsW4kVQHmB9vQBZgT8IiMNjsZhcKm/pcVZGIhvOcvlL2YdkTBmyJntQQEjntTYEdKRmvdOWwXQ57DUqMXCFlpOo/wiqcinKfXCZvmZiNzmsAXF6/l3LyrBrCmDnx4N2NcNion13OY/pIfBwXTViN01r6C5/j7hbtGB8/d1SUbadiUnoGTmFT3BZAeA/+pZkNRenBS5JnG77GP1fzOkFzgWNpErAGLub4Wbm35tacnA==;31:nNePOsgx6/8lEV2oCq+9WSrnaqkdcyNArrK6DVCEkQFNi33KwwO22YxQZzLNfvAwhgc/pWM/QtwBqc2b/4OwjqAQhkFKfLb4WKgjjxA2lNnu8atH5njxkXNSnhtWvWJihtwj3Q15WiKWSocV9Lq4BxisFZaTZMymBzeaqHMK6N+XBb8IBJB6yDrLiG1Y/M+AZ1IqYjafT22R6vIW3SPtxVa4XA27i9Qu+sEuyVUUzfA= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1330: X-Microsoft-Exchange-Diagnostics: 1;AM5PR0801MB1330;20:Oin6tvmQNlWGcuHOZ+u6fM3tuY3ecTCOGcbeCqD3Nl3q+4gcqtuhjgy27U+6RMaWbxo/QQB/ShKlu6933xgwTdJTbmdOlT9tGvgEFbfIaCX1ZHS2VWgB0gLf16SZMEl6/5JHFgAxGZuZUDTvJu6BTRqa4hxEeyWQpJLzWdlDr8EmloPOyxraozbO0DIvnnKcD4rbvJlo4ib+JPwEBcIwIKhd3iCu7d0+0fVbfZLeYmy9GDq/OooWles2tihnf0JvMxd9Vi4RyoURW/r8il/VsbBMmS5FJd7p8va8dV9FKcGmVaOMJNICBviA8ts1hnVBTG/4Ya7eSm6vvNpwVEnCe165vGTxjkKG4iWgHgIk2u/j5nCbewzDO7wlRsPb8Z4RrLhPWt7/KaPQvMiQ+sb0dWsdpBGGehHma+IxsaxJgm9JQZWFc99NgdqMakUrXqr4aEYMHEMuA+DEwxmr6khNYI0vyS7Vo1lma+0zI7XVRGiPZi7aglMDS+M1e6BleQXE;4:aUd2ZuYrZXbJKSe/5Uyd6XQRPB3S0TkoJ6wyqK2q4H+SO0kKA6PJac9UA3mk9hroTdR7ApS7aqs6j36/7cjcTrCjGYaWzfHYW7mOoVPrr9wn4lIccGqgxWANB5luDF/AqSpAJ5+Kpsdc869JSDnP7dPW6ForFEv52CdwGM7zZEXuljGIZ9LVKP+y7YBKmb7MU8c6DaspproYpt4YibfKYtWnfwo+pQfmT8AqplFjR631E7Gh+Hk9fPlg32LvUKW3uh6ogNeNwxVch3szh38cKQ== 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)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:AM5PR0801MB1330;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0801MB1330; X-Forefront-PRVS: 066898046A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(39380400002)(376002)(346002)(366004)(396003)(39850400004)(189003)(199004)(305945005)(186003)(575784001)(86362001)(103116003)(6636002)(2906002)(7736002)(478600001)(230700001)(11346002)(16526019)(52116002)(106356001)(97736004)(53936002)(39060400002)(476003)(58126008)(6506007)(956004)(76176011)(2486003)(7416002)(68736007)(316002)(61506002)(486006)(55016002)(25786009)(105586002)(23676004)(81156014)(7696005)(446003)(47776003)(81166006)(8936002)(50466002)(9686003)(55236004)(5660300001)(386003)(66066001)(59450400001)(8676002)(6116002)(3846002)(33896004)(26005)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0801MB1330;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?MTtBTTVQUjA4MDFNQjEzMzA7MjM6QUFBTnUvakJsNHNYRDNsTlMrSURSblpO?= =?utf-8?B?bkxGd1VneFk2R20vNlkwcmgzK0RnYTB0bWJObXhCMHBLZnVKWFNlMDBMSVVu?= =?utf-8?B?QmlVRi9vZTJwVlJDUWgwZ1l0NVpaWUgxYzVQMEMrOXJjc1V5QWtnRXEyS04z?= =?utf-8?B?S3dRSDNNQU9RUWVOMDlMcWhaOU1zRUhwVmZQRUlyNmdQWW56U0J5MFlhbDJL?= =?utf-8?B?Tk5Mdk9NOFA2cTcyU0lIZURtTUF3OEk2Y3IvU2pxSkc3ZTdzWFVoZ3NxQit2?= =?utf-8?B?VHY2OWJpM09PY1FKMkJlOVNwSGhpQzFlMDQrclBFY1EvNnBSaXRYVDd4Smda?= =?utf-8?B?SVE4RzJJZjIxZ09oNXFsdk9jZzNlbTJNRzN2SzZo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/7uMtG0LfSrnRd4MnwIBFSVn9uD4A6JSJQfwGIQ5FKyuk= X-MS-Office365-Filtering-Correlation-Id: 1440cdf0-7536-453c-deee-08d5b65bff3d X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2018 09:54:17.0686 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1440cdf0-7536-453c-deee-08d5b65bff3d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1330 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, 5 sequential calls of drop caches: $time echo 3 > /proc/sys/vm/drop_caches 1)Before: 0.00user 13.78system 0:13.78elapsed 99%CPU 0.00user 5.59system 0:05.60elapsed 99%CPU 0.00user 5.48system 0:05.48elapsed 99%CPU 0.00user 8.35system 0:08.35elapsed 99%CPU 0.00user 8.34system 0:08.35elapsed 99%CPU 2)After 0.00user 1.10system 0:01.10elapsed 99%CPU 0.00user 0.00system 0:00.01elapsed 64%CPU 0.00user 0.01system 0:00.01elapsed 82%CPU 0.00user 0.00system 0:00.01elapsed 64%CPU 0.00user 0.01system 0:00.01elapsed 82%CPU The results show the performance increases at least in 548 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 436691a66500..82c0bf2d0579 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1283,6 +1283,8 @@ static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg, int nid, int rcu_read_lock(); map = MEMCG_SHRINKER_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 7b0075612d73..189b163bef4a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -586,8 +586,23 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, continue; 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 memcg_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 + memcg_set_shrinker_bit(memcg, nid, i); + } freed += ret; if (rwsem_is_contended(&shrinker_rwsem)) {