Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp821640imm; Wed, 8 Aug 2018 06:23:01 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzQehlpJD1Ip0l1mrtzVayronIcYB3nYzHOV52hdp9Lxw/N3TrjlN9Nkcl+dgj8ZhVcBTrb X-Received: by 2002:a17:902:2e01:: with SMTP id q1-v6mr2635006plb.40.1533734581100; Wed, 08 Aug 2018 06:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533734581; cv=none; d=google.com; s=arc-20160816; b=sOgpSHDR7ouwktE1/GbO11EVYau8RA8P01zPYkOqci+jPsQ6RFDEUK2tAHp3jcyfn1 O85zhJZhvgyOsWqpqVZWltRl8T6sE0AytiWjUjhk2ddvWBgTEF3g2DD+vR31pT/ssiFs X3nT1LXbntdTnb4qDigj5wIC9JWwHtT8DWK/Zxnc3aFkgNCR8GN/HHXyOXUpmMWLzkZB VtjY8PpeqU+QvlLaKvsz6SQaN0tep1uK1MoElzITevHPGFwzUEd49orc3TAj5VrV52QU U9CWQlDjPVQBvJm7NA1YCNdnDMZJLxnxyS0DqLYzbGhygsj3DSIzJGvNl59fwwVLtsbN NFsQ== 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:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:to :from:subject:dkim-signature:arc-authentication-results; bh=PW0WOLFthiKNMQomc+zu4rJAI+6PA5dqVrsYRoLFDfY=; b=auUOzVQ3d0fd8gYD46WWw+SEkYMx//6Hw9T4QVqTxB/slesYWkKlRbzU/b7M4TWeyj WXm8K/CdsEXRilRsvQyD/v6sM/5Lu/kPvuYjjtEI7muA2mUYeqcaFr7Yd7X/w9Q7C4W0 y3Hid3ei07DtkadcTd7kONt/3P+Xh5lgZ3c4hRJWAYpesi1hS1NeNMc+aP2MtQm/xIWE ZAwkue95yrcHxylFCYQAltjwvp7sscV2Xenq47Mw1j2T1eRrTz3r0To6jqAjvib66qd7 JkQDPGrjOUftvwpb3vO90xD2GOieuWjdq52b/VzfdvJtRTxG1l4svv7ee/tvI5z2v05B fbbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=SUmTduri; 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 a24-v6si3398090pls.353.2018.08.08.06.22.45; Wed, 08 Aug 2018 06:23:01 -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=SUmTduri; 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 S1727149AbeHHPkz (ORCPT + 99 others); Wed, 8 Aug 2018 11:40:55 -0400 Received: from mail-db5eur01on0131.outbound.protection.outlook.com ([104.47.2.131]:20054 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726733AbeHHPky (ORCPT ); Wed, 8 Aug 2018 11:40:54 -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=PW0WOLFthiKNMQomc+zu4rJAI+6PA5dqVrsYRoLFDfY=; b=SUmTduriy/ZWlX/dg0vUry7PJQpMQ02lRshhY2Ef9fZ1bna1cpgMAGgyRMh5TgNy2LigaxGeM889FPjj7w3BU2JfRoZMxL/I+yjhqZ1Ezz9wZSlcLZOGW2gnAYTC8Hs92Wv+ynlu1NV+3rQxBsdy184aEab5M3yID9xh73DZ0bQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from [172.16.25.169] (185.231.240.5) by HE1PR0801MB2026.eurprd08.prod.outlook.com (2603:10a6:3:50::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.15; Wed, 8 Aug 2018 13:20:59 +0000 Subject: [PATCH RFC v2 02/10] mm: Make shrink_slab() lockless From: Kirill Tkhai To: akpm@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org, viro@zeniv.linux.org.uk, darrick.wong@oracle.com, paulmck@linux.vnet.ibm.com, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, hughd@google.com, shuah@kernel.org, robh@kernel.org, ulf.hansson@linaro.org, aspriel@gmail.com, vivek.gautam@codeaurora.org, robin.murphy@arm.com, joe@perches.com, heikki.krogerus@linux.intel.com, sfr@canb.auug.org.au, vdavydov.dev@gmail.com, mhocko@suse.com, chris@chris-wilson.co.uk, penguin-kernel@I-love.SAKURA.ne.jp, aryabinin@virtuozzo.com, willy@infradead.org, ying.huang@intel.com, shakeelb@google.com, jbacik@fb.com, mingo@kernel.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <153365347929.19074.12509495712735843805.stgit@localhost.localdomain> <153365626605.19074.16202958374930777592.stgit@localhost.localdomain> <591d2063-0511-103d-bef6-dd35f55afe32@virtuozzo.com> Message-ID: <4ceb948c-7ce7-0db3-17d8-82ef1e6e47cc@virtuozzo.com> Date: Wed, 8 Aug 2018 16:20:54 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <591d2063-0511-103d-bef6-dd35f55afe32@virtuozzo.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: DB6P193CA0016.EURP193.PROD.OUTLOOK.COM (2603:10a6:6:29::26) To HE1PR0801MB2026.eurprd08.prod.outlook.com (2603:10a6:3:50::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 84edffd3-7187-4dd2-4d2b-08d5fd31ca6e X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:HE1PR0801MB2026; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB2026;3:w16ffdMt0MlHNui3JiMf/6e0xp5d68XA71Fa9BbmfF+k1BonhGpO4mryymUyJxVP3tag8Nry3oCbfN3VlYx2lwDrVJyyt4NoZawLpRqQXbrfpCzvrDi5hDqPUjwwFZ2ftht1eQK8f39wBNNkxP1obG4PfsS+TUSM8X9vbWlllZsnOEBL8LvsK6J4y+JCYlZ5kTvFy4cXEn3iuyYoV5E+rQU/q56J8YS5cdF1UNKWqnLIYosGG/68sR+W71pzrXDL;25:oM28E5BuuJD7q0KmIZcC0/keKpd1Ub1ylPH8jvC+RwoUvOFXU/FGWfDBGUCwWcX7Tea+nE5EdRMoTLhwj3m2ueNTZtFNQUXhH/ebRIrOnMYS8S0WaqT97DRkKDK6Kp1i5xiPlJztrgcYlVpwLNW2HWAEMQIb18hjJyuSuGaz/rmCpNDWkf3AOIw8wFbHU3Fa6rBFbO3q7rdkPvqSY33c3QfFi3sOqJlhKk2HRUD6hF3OXLLSMJ2NhRtLwXU0RZYLLCrWzz8CS/DaE5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NFS1QkhB3rFs+HJajTZ1BQRZGkU/3o6FJzT1A02d2vfVXAXx54CCAQGbsDBI2blBGLAXXj8ITsMBhjhu3VnQjXFA8SoHCxJsN7/Xdibv4PdGb0fxdXaPMOT2ESYzFu+PWZmFpWQVsKrb55 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(209352067349851); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231311)(944501410)(52105095)(10201501046)(93006095)(93001095)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011)(7699016);SRVR:HE1PR0801MB2026;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB2026; X-Forefront-PRVS: 07584EDBCD X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(376002)(346002)(366004)(136003)(39850400004)(396003)(189003)(199004)(2906002)(39060400002)(386003)(6486002)(58126008)(26005)(478600001)(5660300001)(77096007)(16576012)(68736007)(305945005)(476003)(7416002)(36756003)(7736002)(7406005)(65826007)(53936002)(186003)(16526019)(956004)(31696002)(11346002)(2616005)(50466002)(86362001)(486006)(446003)(25786009)(230700001)(66066001)(14444005)(47776003)(52116002)(97736004)(3846002)(31686004)(64126003)(105586002)(23676004)(52146003)(2486003)(6116002)(106356001)(76176011)(65806001)(65956001)(316002)(6666003)(81166006)(8936002)(81156014)(8676002)(217873002)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0801MB2026;H:[172.16.25.169];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?MTtIRTFQUjA4MDFNQjIwMjY7MjM6OFlnWnloMHcveGFJM3VtUlB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Ga7iQjUeZWBq0fDg1x6t+NIjmr/Gg000FE9SnrW/SlewU9J55LTJx9mEkyr1ISXSlCFYwHqGM3ykYEUUAI4Pp6Ej0Sci3JLItkhYjYkxSqMxfaQClaChhK3thgdleHBwzzfCyqU4OSdtBCk=;7:D+kKWM/4zt8A58Cm5KPsdPrBnGP7T5btQZ+nFZKYnpcZZATC+9N+1aWo5MhUiFl0BeEopQWnF1j4146H3cksh3+K5UF107EerfCOR4+kHtUFX4+zLeyF24OS2EbYhYZb2HK69laJ5RzS/wio7w+vlC40BMT/SpMzLBN8d/Yh1vzpvu2qTCAYz0ZxgLsCokLbny9HfXxKtbEWDXwZRZwIfPthk1ZOYEgGhEpoItplIktMOvowvMkbqAIumkGv1Sla SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB2026;20:CFid3tb4mVyCAr34YSE+4DykIZZ4dpEHhEkObqiBLZ6AWIGhb7uDbhQrx1Jo4o8GcVer6ugOaCxUG5KWUr1UWlPp4pr7KrO602j5blcd16M7QhSTazvqMOGfh28VyZkbbtADHjf6KZORnB6lSpgR7aPdwRYW001RVe4anM8nWjo= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2018 13:20:59.1586 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84edffd3-7187-4dd2-4d2b-08d5fd31ca6e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB2026 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [Added two more places needed srcu_dereference(). All ->shrinker_map dereferences must be under SRCU, and this v2 adds missed in previous] The patch makes shrinker list and shrinker_idr SRCU-safe for readers. This requires synchronize_srcu() on finalize stage unregistering stage, which waits till all parallel shrink_slab() are finished Note, that patch removes rwsem_is_contended() checks from the code, and this does not result in delays during registration, since there is no waiting at all. Unregistration case may be optimized by splitting unregister_shrinker() in tho stages, and this is made in next patches. Also, keep in mind, that in case of SRCU is not allowed to make unconditional (which is done in previous patch), it is possible to use percpu_rw_semaphore instead of it. percpu_down_read() will be used in shrink_slab_memcg() and in shrink_slab(), and consecutive calls percpu_down_write(percpu_rwsem); percpu_up_write(percpu_rwsem); will be used instead of synchronize_srcu(). Signed-off-by: Kirill Tkhai --- diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 9443cafd1969..94b44662f430 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -82,6 +82,8 @@ struct shrinker { #define SHRINKER_NUMA_AWARE (1 << 0) #define SHRINKER_MEMCG_AWARE (1 << 1) +extern struct srcu_struct shrinker_srcu; + extern int prealloc_shrinker(struct shrinker *shrinker); extern void register_shrinker_prepared(struct shrinker *shrinker); extern int register_shrinker(struct shrinker *shrinker); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4e3c1315b1de..ed40eb4b8300 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -332,8 +332,9 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, lockdep_assert_held(&memcg_shrinker_map_mutex); for_each_node(nid) { - old = rcu_dereference_protected( - mem_cgroup_nodeinfo(memcg, nid)->shrinker_map, true); + old = srcu_dereference_check( + mem_cgroup_nodeinfo(memcg, nid)->shrinker_map, + &shrinker_srcu, true); /* Not yet online memcg */ if (!old) return 0; @@ -347,7 +348,7 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, memset((void *)new->map + old_size, 0, size - old_size); rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_map, new); - call_rcu(&old->rcu, memcg_free_shrinker_map_rcu); + call_srcu(&shrinker_srcu, &old->rcu, memcg_free_shrinker_map_rcu); } return 0; @@ -364,7 +365,8 @@ static void memcg_free_shrinker_maps(struct mem_cgroup *memcg) for_each_node(nid) { pn = mem_cgroup_nodeinfo(memcg, nid); - map = rcu_dereference_protected(pn->shrinker_map, true); + map = srcu_dereference_check(pn->shrinker_map, + &shrinker_srcu, true); if (map) kvfree(map); rcu_assign_pointer(pn->shrinker_map, NULL); @@ -427,13 +429,15 @@ void memcg_set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) { if (shrinker_id >= 0 && memcg && !mem_cgroup_is_root(memcg)) { struct memcg_shrinker_map *map; + int srcu_id; - rcu_read_lock(); - map = rcu_dereference(memcg->nodeinfo[nid]->shrinker_map); + srcu_id = srcu_read_lock(&shrinker_srcu); + map = srcu_dereference(memcg->nodeinfo[nid]->shrinker_map, + &shrinker_srcu); /* Pairs with smp mb in shrink_slab() */ smp_mb__before_atomic(); set_bit(shrinker_id, map->map); - rcu_read_unlock(); + srcu_read_unlock(&shrinker_srcu, srcu_id); } } diff --git a/mm/vmscan.c b/mm/vmscan.c index da135e1acd94..acb087f3ac35 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -168,6 +168,7 @@ unsigned long vm_total_pages; static LIST_HEAD(shrinker_list); static DECLARE_RWSEM(shrinker_rwsem); +DEFINE_SRCU(shrinker_srcu); #ifdef CONFIG_MEMCG_KMEM @@ -192,7 +193,6 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) int id, ret = -ENOMEM; down_write(&shrinker_rwsem); - /* This may call shrinker, so it must use down_read_trylock() */ id = idr_alloc(&shrinker_idr, SHRINKER_REGISTERING, 0, 0, GFP_KERNEL); if (id < 0) goto unlock; @@ -406,7 +406,7 @@ void free_prealloced_shrinker(struct shrinker *shrinker) void register_shrinker_prepared(struct shrinker *shrinker) { down_write(&shrinker_rwsem); - list_add_tail(&shrinker->list, &shrinker_list); + list_add_tail_rcu(&shrinker->list, &shrinker_list); idr_replace(&shrinker_idr, shrinker, shrinker->id); up_write(&shrinker_rwsem); } @@ -432,8 +432,11 @@ void unregister_shrinker(struct shrinker *shrinker) if (shrinker->flags & SHRINKER_MEMCG_AWARE) unregister_memcg_shrinker(shrinker); down_write(&shrinker_rwsem); - list_del(&shrinker->list); + list_del_rcu(&shrinker->list); up_write(&shrinker_rwsem); + + synchronize_srcu(&shrinker_srcu); + kfree(shrinker->nr_deferred); shrinker->nr_deferred = NULL; } @@ -567,16 +570,14 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, { struct memcg_shrinker_map *map; unsigned long freed = 0; - int ret, i; + int ret, i, srcu_id; if (!memcg_kmem_enabled() || !mem_cgroup_online(memcg)) return 0; - if (!down_read_trylock(&shrinker_rwsem)) - return 0; - - map = rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_map, - true); + srcu_id = srcu_read_lock(&shrinker_srcu); + map = srcu_dereference(memcg->nodeinfo[nid]->shrinker_map, + &shrinker_srcu); if (unlikely(!map)) goto unlock; @@ -621,14 +622,9 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, memcg_set_shrinker_bit(memcg, nid, i); } freed += ret; - - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; - } } unlock: - up_read(&shrinker_rwsem); + srcu_read_unlock(&shrinker_srcu, srcu_id); return freed; } #else /* CONFIG_MEMCG_KMEM */ @@ -665,15 +661,13 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, { struct shrinker *shrinker; unsigned long freed = 0; - int ret; + int srcu_id, ret; if (!mem_cgroup_is_root(memcg)) return shrink_slab_memcg(gfp_mask, nid, memcg, priority); - if (!down_read_trylock(&shrinker_rwsem)) - goto out; - - list_for_each_entry(shrinker, &shrinker_list, list) { + srcu_id = srcu_read_lock(&shrinker_srcu); + list_for_each_entry_rcu(shrinker, &shrinker_list, list) { struct shrink_control sc = { .gfp_mask = gfp_mask, .nid = nid, @@ -684,19 +678,9 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, if (ret == SHRINK_EMPTY) ret = 0; freed += ret; - /* - * Bail out if someone want to register a new shrinker to - * prevent the regsitration from being stalled for long periods - * by parallel ongoing shrinking. - */ - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; - } } + srcu_read_unlock(&shrinker_srcu, srcu_id); - up_read(&shrinker_rwsem); -out: cond_resched(); return freed; }