Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6132715ybi; Tue, 4 Jun 2019 19:48:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4krc2UhmuOkcmA7DYqTUc5/2p7LbUWDRf2ZQ/6XuUeGHqzZGZeJfJbbhCf84DqJUOmdBn X-Received: by 2002:a63:dc09:: with SMTP id s9mr1029034pgg.425.1559702899002; Tue, 04 Jun 2019 19:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559702898; cv=none; d=google.com; s=arc-20160816; b=RAr+riT9S8bAf2rtMHh83+Rh1bFzXv2sRp9rpiYsrtYhFF2OQ5+xCedtgptg7jmT+y Jmr5mpZll/MbfqQWXjxdmPmRO20xa+07UqZDFDhtGnmW9SB4I0v0yrfdY9oqdRJG2DdZ FPbb37lme012E9z8tIhWRW6lFyi8122EUkgos/LAbIdQ/VxYMFfpOo6zdlgYXRpJnvfW XsMYpruypr8pvChFvqmMbiaZhHlclu+/IE4FFkFvG0XGGp16x4p++i3VHvOaFR+O30RZ 9DsJ6QfMA0OGaEREqUn63KVSIcn+ye9sKceDQUySkjHzijoSp+rclenswPDIFnzIxhQM 2xlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature; bh=RAtQP8kdt+P/ff/UupI77hj0Bc++zM2YWzYBwAXPM6o=; b=bEEbqgzufkDdCJoAHUZqxxuh9nJXU9DUO8t8aeN1OnOU6H4kIOw/uFArI7Lx4PFkUn SDJbfCOBz+0D+oYgoGVEEA4vrI9hhqF+EydpkWPpO51T6U7l67O4eqmFk/7vph6e1R/T SBEuHpmTbh9dVdtrjj/HIVQX48lD18GatJogb5ZWF+RXSy4QgX5gGxZ6MaFFbqpv89ja O6+4ctDFg8fW/XbiJ/iwAIhgCc2ytjeLys1jUH/XmSwFAGxSBDhTm1oN9I3AYmHYfnYV gWoMZq7kv3jx/iZq6oIINe7H63VX5wAfgESU5MTZhmJoH08TgQNKfUdaA0U2KnJggtqd 9agQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=N1ORyrtC; 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=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a59si26224535pla.348.2019.06.04.19.48.03; Tue, 04 Jun 2019 19:48:18 -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=@fb.com header.s=facebook header.b=N1ORyrtC; 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=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726527AbfFECpC (ORCPT + 99 others); Tue, 4 Jun 2019 22:45:02 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:52266 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfFECpB (ORCPT ); Tue, 4 Jun 2019 22:45:01 -0400 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x552iAeu001296 for ; Tue, 4 Jun 2019 19:45:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=RAtQP8kdt+P/ff/UupI77hj0Bc++zM2YWzYBwAXPM6o=; b=N1ORyrtCMpqM8ArTqyLILrOwr/rNYmMHMW9zOhG/NRyrlupsDadIRbH+Gt2zpNdLeTHX 6UchQ5coq6wyjYdFSjdBnNAWvDe9iDo/95rKavvBdoQXJ/GeLh+EHLugjQxPcLLLU5BB wHHKtT2bs17nxlMXfdM9vV2V0bZEmZnb0uA= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2swq1tjy3n-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 04 Jun 2019 19:45:00 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Tue, 4 Jun 2019 19:44:59 -0700 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 8FE2012C7FDCE; Tue, 4 Jun 2019 19:44:58 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: Andrew Morton CC: , , , Johannes Weiner , Shakeel Butt , Vladimir Davydov , Waiman Long , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH v6 07/10] mm: synchronize access to kmem_cache dying flag using a spinlock Date: Tue, 4 Jun 2019 19:44:51 -0700 Message-ID: <20190605024454.1393507-8-guro@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190605024454.1393507-1-guro@fb.com> References: <20190605024454.1393507-1-guro@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-05_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=758 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906050015 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the memcg_params.dying flag and the corresponding workqueue used for the asynchronous deactivation of kmem_caches is synchronized using the slab_mutex. It makes impossible to check this flag from the irq context, which will be required in order to implement asynchronous release of kmem_caches. So let's switch over to the irq-save flavor of the spinlock-based synchronization. Signed-off-by: Roman Gushchin --- mm/slab_common.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 09b26673b63f..2914a8f0aa85 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -130,6 +130,7 @@ int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t nr, #ifdef CONFIG_MEMCG_KMEM LIST_HEAD(slab_root_caches); +static DEFINE_SPINLOCK(memcg_kmem_wq_lock); void slab_init_memcg_params(struct kmem_cache *s) { @@ -629,6 +630,7 @@ void memcg_create_kmem_cache(struct mem_cgroup *memcg, struct memcg_cache_array *arr; struct kmem_cache *s = NULL; char *cache_name; + bool dying; int idx; get_online_cpus(); @@ -640,7 +642,13 @@ void memcg_create_kmem_cache(struct mem_cgroup *memcg, * The memory cgroup could have been offlined while the cache * creation work was pending. */ - if (memcg->kmem_state != KMEM_ONLINE || root_cache->memcg_params.dying) + if (memcg->kmem_state != KMEM_ONLINE) + goto out_unlock; + + spin_lock_irq(&memcg_kmem_wq_lock); + dying = root_cache->memcg_params.dying; + spin_unlock_irq(&memcg_kmem_wq_lock); + if (dying) goto out_unlock; idx = memcg_cache_id(memcg); @@ -735,14 +743,17 @@ static void kmemcg_cache_deactivate(struct kmem_cache *s) __kmemcg_cache_deactivate(s); + spin_lock_irq(&memcg_kmem_wq_lock); if (s->memcg_params.root_cache->memcg_params.dying) - return; + goto unlock; /* pin memcg so that @s doesn't get destroyed in the middle */ css_get(&s->memcg_params.memcg->css); s->memcg_params.work_fn = __kmemcg_cache_deactivate_after_rcu; call_rcu(&s->memcg_params.rcu_head, kmemcg_rcufn); +unlock: + spin_unlock_irq(&memcg_kmem_wq_lock); } void memcg_deactivate_kmem_caches(struct mem_cgroup *memcg) @@ -852,9 +863,9 @@ static int shutdown_memcg_caches(struct kmem_cache *s) static void flush_memcg_workqueue(struct kmem_cache *s) { - mutex_lock(&slab_mutex); + spin_lock_irq(&memcg_kmem_wq_lock); s->memcg_params.dying = true; - mutex_unlock(&slab_mutex); + spin_unlock_irq(&memcg_kmem_wq_lock); /* * SLAB and SLUB deactivate the kmem_caches through call_rcu. Make -- 2.20.1