Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4868985imm; Tue, 7 Aug 2018 08:39:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdtc9Xj8+SCNVZOq09LZ9cZTV7itU73nPsJSDzK3xbHqt3ipB0OHWJ2f2NsFfL62qME0iC8 X-Received: by 2002:aa7:8118:: with SMTP id b24-v6mr22294829pfi.78.1533656377597; Tue, 07 Aug 2018 08:39:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533656377; cv=none; d=google.com; s=arc-20160816; b=KYRxmbbX/d+Ce8aqVMHMBhTM7KVriQY8THMAxhCV2pZUfAMKYpPA0/fOynvsktDjwE qIFvS8W8/6y3VLPHyv5F/cHQIYDoc6nAgsn19IRuQlN5BcLekdtM1/vJzzdBZ9uKvvI+ PtdPS8qlhZ62EUfX8zlCeU3Gcza1A+QfoLCeqpnAZP5SaSuEWPVwhRpwDqJGuv4rWg6v HNeOSQ8peOFQKI82qOAbAlYeD7QIGeWMFizlMlFcF+OxOL4t5fVWTWKFztwcDmbdjQhi 4HhBzLD/9cB6sdafg8iUluZJn7D3FmNze/KoDofRvVU3R+LaZeg5RIM8YWFsY86wPH7h QcsQ== 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=IOgHna0IjgNaMkcfTG3lH2LiLelmPRrnFUp70X32rg8=; b=oAhOGlxvrOXvwgf9Amgk0tnD+2SZKjreykjGfQDth30+MY460hB6ybKyLQDf3VMobk gah29SqBASfBJs09LmupFpWrROn02+lu7l3Ht+pM0csZWlxHQbNkLcGXSwAIgXzRdX90 bk01f7IUFIqrpj65Hn/8E6nEWO1hVuURFH+S30EeeF5eVaFz1bcaIWoEeXF6XAEBLWHY OeUxPC00m1gP/NyYpjhI4NWuSfjNUQpnBkSFLlqNN2LzFQFSYKjj1jiTb96SsLk+0A0o D3hSXVft6zNSGU//UrTVwF19mPS7ocAWjG7xmqkJI105D3S5Mmq4ZuG5dX0FJtoJm3Ir 8GqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=FXqBnciJ; 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 x17-v6si1203387pln.465.2018.08.07.08.39.21; Tue, 07 Aug 2018 08:39:37 -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=FXqBnciJ; 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 S2390021AbeHGRww (ORCPT + 99 others); Tue, 7 Aug 2018 13:52:52 -0400 Received: from mail-ve1eur01on0103.outbound.protection.outlook.com ([104.47.1.103]:21464 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388677AbeHGRww (ORCPT ); Tue, 7 Aug 2018 13:52:52 -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=IOgHna0IjgNaMkcfTG3lH2LiLelmPRrnFUp70X32rg8=; b=FXqBnciJoI192137vBDlbX128rGMK68+IF9JW+o8GdPomPVZmQiUbXOkEvJAyoJrF2CfUMxrcdGiHA5r0u+R8WCNiOzr8rOwfNwDbjEYbXwa4h0G4HljOIBO5iNdMUzOctjgnGpQj+PedxzeR2xcuPwMb/rvrE+NhEqer9iTAKc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (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; Tue, 7 Aug 2018 15:37:50 +0000 Subject: [PATCH RFC 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, ktkhai@virtuozzo.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 Date: Tue, 07 Aug 2018 18:37:46 +0300 Message-ID: <153365626605.19074.16202958374930777592.stgit@localhost.localdomain> In-Reply-To: <153365347929.19074.12509495712735843805.stgit@localhost.localdomain> References: <153365347929.19074.12509495712735843805.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: LO2P265CA0164.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::32) To HE1PR0801MB2026.eurprd08.prod.outlook.com (2603:10a6:3:50::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 679832a7-3215-43b5-fe22-08d5fc7bbeaa 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:SGApD3x/zPMVBpLYc2HjeYF1T9qt1J58SZ83TLV2FOa8bED4wE9QuUuwL6ZY3g5bH8hq0eOt+t0p/lGIndvxYiYXs+0pSbYrcQIem18kuqpVgo6TKrz8ai6LS5GNAGLGIDsJcv9o6E78c2BgxM5szuestHVE3vXV0sHyfpLzq206Ft8LG+Sk4kQpxQlmQX4EvdyxcMs/wq3NUT7P/yYqcHOL1iNr75eGuyug0wgp5rrIvpsrCdpFQa7DDVvoZXLx;25:DTMTrlSl/4trqRgA6h0vG75bXkH5Nt4Gga5sB1mGeH/slK5A/aEIuOH31eMhaLQTjBzcrOu5HYo4tkKHE7uQV20xz6sAnPVAZnoM3PPASYn0ez04keffS0y5VQaW5ca9+E5lFhkGTiulZh5Mjqv2PFDO2plLjKUjc+0c53M+gnl9/glhGNNzt7cl0g29+zywp1+9HDVSkeJcBolQM8xuGPjf8YU45+79wkWzsnwhWK0dwpLmTR0AyFoPcOtO2UlW3CgfcJqilhmMCi6yI3zcyCnszs7YMPFxvnoGioH+jIyd90p2A/OkO/JqRjdYaNyr695bVg6YuYdq9yciDsQtuw==;31:6dGbsOQbxf7P2y9yJ1ZpRWVs7Ehy2GJEOUCVn5tPlIyExISRz6sL5rn/gJkDhwAZWmAEXqVH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riScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(6072148)(201708071742011)(7699016);SRVR:HE1PR0801MB2026;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB2026; X-Forefront-PRVS: 0757EEBDCA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(39850400004)(396003)(376002)(346002)(366004)(136003)(199004)(189003)(55016002)(105586002)(7696005)(97736004)(3846002)(6116002)(23676004)(2486003)(230700001)(25786009)(106356001)(47776003)(14444005)(66066001)(52116002)(81156014)(9686003)(8936002)(103116003)(8676002)(217873002)(81166006)(76176011)(6666003)(61506002)(316002)(53936002)(305945005)(5660300001)(68736007)(476003)(2906002)(386003)(6506007)(39060400002)(478600001)(26005)(58126008)(50466002)(33896004)(11346002)(486006)(86362001)(446003)(956004)(186003)(7736002)(7416002)(16526019)(7406005)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0801MB2026;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtIRTFQUjA4MDFNQjIwMjY7MjM6TnQyT1ZndmZvVWV0UEQ0ZjhPTE1veFc1?= =?utf-8?B?TloxYm50VjY5VDNlbGFRcTJXbXE5ZW9CUWFhQkw3YzZ2dWltZU45K1E2dDN3?= =?utf-8?B?VmUyNFVaQk1OSysvNkthNWJhc2lJWmd4bERkUmluZTk5T0w0TGoreVpBZnZy?= =?utf-8?B?eFZRSUJaYWxRUWRTOVd6dWwxbHo0MHE3K1lkc2IzWHVqclNOa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8M03QoHM4 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB2026;20:LrQHlzuO4ScRNp+WX0KrOLhI3m17GrFfUcUmpJgpeH2Umo2/L1+eSWmRGeDp3BcbId7L32gt3I7inGyOavULUXGFiihsz6xzGcx5H91AE1fsk1zPqNreXeAlll6Q0hncBrYQeCiQ5tSXtIZid8nAqapkk0X9wmiNl7O2YV3F/iI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2018 15:37:50.5971 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 679832a7-3215-43b5-fe22-08d5fc7bbeaa 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 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 --- mm/vmscan.c | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index da135e1acd94..9dda903a1406 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_STATIC_SRCU(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(&srcu); + kfree(shrinker->nr_deferred); shrinker->nr_deferred = NULL; } @@ -567,14 +570,12 @@ 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; - + srcu_id = srcu_read_lock(&srcu); map = rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_map, true); if (unlikely(!map)) @@ -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(&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(&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(&srcu, srcu_id); - up_read(&shrinker_rwsem); -out: cond_resched(); return freed; }