Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2219394pxy; Tue, 3 Aug 2021 00:13:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8WjzFXVFVs+3Db/WYvqEBzZBHyx6X4t+U3JNDZQa1YG5YDjyV/NIFZtJgLjpCgaEQ4Cou X-Received: by 2002:a05:6402:2547:: with SMTP id l7mr4638816edb.314.1627974794700; Tue, 03 Aug 2021 00:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627974794; cv=none; d=google.com; s=arc-20160816; b=ikhVLW7Rg7vEyE9wYUYzrmolYmqwO7Ckp5gvHsSurpDtm+ZbHeQ+w12Cx37+yea+wP VI7H4+8jVUOYcHNUanZgdqW/cEMyji6kpMHIXg2d+mQMUz2D5g3kYKxrcJ5l26boKzR9 TsW0WM7tEcnb9mmSlRwceDh0UFMeJLVWG8vjKE+r+Ea5GuLp3MWMQ02jQooGa86dTP5e CfymarCTTsqmu6wbjB838yGuqqD+IVLOkO9/ovAPs+auqMvUd1hGVttW/zL8llr2xpdi rwC8sA6HS/R9ZNA9xoq/5GU1I/XKulSGHPx6Ihia+duYdbRhkLl1Q90xAO0y6xRfirlB Ky5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yTB1aRzTEEw2dTSaIA3iMc8Rd5LQIIGML6amfYHIZt4=; b=lhL4CnMjckh/qpGT7YLvOo42mFbHnlzmrwiJ9Gu3nIplEeGznWXpyXyzS9OcjqST9p QIPv9QawnWJOaFrfPl4FqGOh2BA6Fnb7bEbSE0u8J+2M3uK0fWuODT5BdBB/82h2Ey3f 6HqSNJEWJ7fL5YvM+KSQE9XEavbk/F8/RScBS099QtJ6RbCqsArHfmgAn1Liw3FlTIKd l3fSurDu7VrI8fIFNzsQ3n9JeCgZu0fsJF46hUmCt+pjgPEh5ckPIp4C6XIqQ4e9h5uT A7UKgaJxnmt5GK+GdWv1E0VMjQSbGZbvd1SYS1xe09qXgIORoskzluZoxT7enz08/6ql 8l2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=bwvEpu8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si12231375edd.167.2021.08.03.00.12.51; Tue, 03 Aug 2021 00:13:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=bwvEpu8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234076AbhHCHLm (ORCPT + 99 others); Tue, 3 Aug 2021 03:11:42 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34348 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234020AbhHCHLj (ORCPT ); Tue, 3 Aug 2021 03:11:39 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7723B2205F; Tue, 3 Aug 2021 07:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1627974687; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yTB1aRzTEEw2dTSaIA3iMc8Rd5LQIIGML6amfYHIZt4=; b=bwvEpu8IwlMFzHs+yKzQ5BkflANLVPluliOGC2khS0BvVK9MnKiTUjZtExbHtFh63auwUB A2SyUrkYvGA5kzCzUMoQ2b6UCYU84Nn/R6P49iaFug5gcjrDZ5SLblSEEmEXSS6LWs/dko mnKrOFfiafycrcdUJ2jxarlFUwEfmJk= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 114E2A3BCB; Tue, 3 Aug 2021 07:11:26 +0000 (UTC) Date: Tue, 3 Aug 2021 09:11:25 +0200 From: Michal Hocko To: Miaohe Lin Cc: Roman Gushchin , hannes@cmpxchg.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, shakeelb@google.com, willy@infradead.org, alexs@kernel.org, richard.weiyang@gmail.com, songmuchun@bytedance.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Subject: Re: [PATCH 2/5] mm, memcg: narrow the scope of percpu_charge_mutex Message-ID: References: <20210729125755.16871-1-linmiaohe@huawei.com> <20210729125755.16871-3-linmiaohe@huawei.com> <4a3c23c4-054c-2896-29c5-8cf9a4deee98@huawei.com> <95629d91-6ae8-b445-e7fc-b51c888cad59@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <95629d91-6ae8-b445-e7fc-b51c888cad59@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 03-08-21 14:29:13, Miaohe Lin wrote: [...] > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 616d1a72ece3..6210b1124929 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2208,11 +2208,11 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages) > */ > static void drain_all_stock(struct mem_cgroup *root_memcg) > { > - static DEFINE_MUTEX(percpu_charge_mutex); > int cpu, curcpu; > + static atomic_t drainer = ATOMIC_INIT(0); > > /* If someone's already draining, avoid adding running more workers. */ > - if (!mutex_trylock(&percpu_charge_mutex)) > + if (atomic_cmpxchg(&drainer, 0, 1) != 0) > return; > /* > * Notify other cpus that system-wide "drain" is running > @@ -2244,7 +2244,7 @@ static void drain_all_stock(struct mem_cgroup *root_memcg) > } > } > put_cpu(); > - mutex_unlock(&percpu_charge_mutex); > + atomic_set(&drainer, 0); atomic_set doesn't imply memory barrier IIRC. Is this safe? -- Michal Hocko SUSE Labs