Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7022975ybi; Wed, 5 Jun 2019 09:58:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeOQGPFmFkPek3jajrBw6g2qesU2o1CLXiaWtb+sVmf4AMhromcjeP2DZZNshRrCJIzGTi X-Received: by 2002:a62:770e:: with SMTP id s14mr17475535pfc.150.1559753882999; Wed, 05 Jun 2019 09:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559753882; cv=none; d=google.com; s=arc-20160816; b=d7pmivundEnawNbvTgp8Qv5U1LHE1+xfOoDAwFL8jcOccsjbRmj9NvIMGahqoSJh4o HL8xjpw+DNReUhFxDaJBPht8OPGSQb7vLZblphLOK3vBjwM3EhS6lshP+q7kepbW7R0u lVfZouq3TzvQyBr3Oy/Murq3D25fyb27mU9bn6gUAXtbUKs4R+gBbfAAFsdIXzAsjUO9 Z2AEupKSv7jXLWTdnNRV7YI1HGO6LVnNtliL7uSX3fttmesOtw5VmQyVHaa5p+hAfC2r Hb1EWOkeFLT1E/8sPY6DgJNtoaU2NMhyfLUxksmU4HgwwWmGXzSxX3H9cqfjYi+Lna2N S88Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hZ4cGeRHDextu5CN92g1Wv5jExw3YnRMZLIMsV5cvAM=; b=d64GWyyopus1ker4F2PVR+37dwWNv18Q4W92OTO0+2RyeNrOtUf7UlXijQunzfYKQk UIQ/FM7ntuvzgw0TYDbgIr7n8qL06SLgJw4ScRGXCowz6XKTCwhBmKz6sD4FosF5CxY6 DIdomWBQNLT4ZeLU5yTEfJwyC9PIW1q1ubYqPwf3GwunSZn/Miy2NqGr9dFDg9WwnIY+ E8TrNQD0TVpDBqWTxHZ2D9YYtcaDgyQnNnvr9uQggfnFWbb+PY1JdaQSPHOONCkWOslP bP9Yq8xh1CKoJpdzdboGfKsW3oMT7/7CZ0UovOSfrtKuZhh1/zPE7AXtgggpaLhYGKCh 9ZNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=0mGIO0a1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s15si11308822pgj.350.2019.06.05.09.57.47; Wed, 05 Jun 2019 09:58:02 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=0mGIO0a1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729045AbfFEQ4U (ORCPT + 99 others); Wed, 5 Jun 2019 12:56:20 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39435 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728911AbfFEQ4T (ORCPT ); Wed, 5 Jun 2019 12:56:19 -0400 Received: by mail-pl1-f193.google.com with SMTP id g9so9900466plm.6 for ; Wed, 05 Jun 2019 09:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hZ4cGeRHDextu5CN92g1Wv5jExw3YnRMZLIMsV5cvAM=; b=0mGIO0a16PwCvvaR5KVekuEHAAI6Q2Au9fzMg0rq9cIQZseDxcLyQnlnpLFqWAhwqe Yt+8W6m4lRuJQWYFUXD9kuuXHzivkv9+YZ8UX3eujcruue8CDe5Piz47SrGxpOX96mJ0 ypMmdVL54li0Got7Cg0OG7+PNhDYXWUkLW82vaBWqVdjlLNaQ8uMIUrLZE072HIgWWHw iSPt/Wakz0VQISfqlzp3LI0Yq1DyQh6PFNSW0qKy89hSNq1VtvE5zOv9q4A7nI4ezK1L e07s/PovVfIg66ebjPwJvd25lYq0FNCUJvMgh1gTZa/ieLe5bRjaMJ7PKI0/rNFseEek lqtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hZ4cGeRHDextu5CN92g1Wv5jExw3YnRMZLIMsV5cvAM=; b=KUoiDBurSJishJRofoJuLPdsEEPgbBcF65DewSSqyQzjG9gRY+LgbmzBIcy/lVjMiG JBDSaKHDFzKCeOWl8nQpnjr+70ggPS6lvHVCuPC709d+9bOsGaSHtPvlr59zN6JY6/7G WWdVoiC/QOpzTcWjf580IAYp93vagaFAQnSyxEAuRpzqLiEW3mb6N/T+7xmlCkdMWuRW X6NSKlTY+iwuwyXit6JXoMxF54651tTWuhPNDR0i/cXTx8pQUD+jARIs4nFXOsXDhwHJ xEUY7NE6DuHQLt62HOSTiVksBgYX9E+rZtlbh4DgKDJh22EBChPQbrX3YsA7kj0Qj1w7 nOqQ== X-Gm-Message-State: APjAAAUqCDeKsKCGn/33qARU69cV/21e9hxN8Z+f2h1l69AhWycgz79h /dkCTuyfYwjBv+d2OprUf550Cg== X-Received: by 2002:a17:902:a513:: with SMTP id s19mr41291953plq.261.1559753778277; Wed, 05 Jun 2019 09:56:18 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::2:cd0c]) by smtp.gmail.com with ESMTPSA id d10sm23208447pgh.43.2019.06.05.09.56.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2019 09:56:17 -0700 (PDT) Date: Wed, 5 Jun 2019 12:56:16 -0400 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Shakeel Butt , Vladimir Davydov , Waiman Long Subject: Re: [PATCH v6 07/10] mm: synchronize access to kmem_cache dying flag using a spinlock Message-ID: <20190605165615.GC12453@cmpxchg.org> References: <20190605024454.1393507-1-guro@fb.com> <20190605024454.1393507-8-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190605024454.1393507-8-guro@fb.com> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 04, 2019 at 07:44:51PM -0700, Roman Gushchin wrote: > 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; What does this lock protect? The dying flag could get set right after the unlock.