From patchwork Fri Aug 7 06:20:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11704799 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05DEA138C for ; Fri, 7 Aug 2020 06:20:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA853221E5 for ; Fri, 7 Aug 2020 06:20:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="ICF0VlBE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA853221E5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4E5C78D0049; Fri, 7 Aug 2020 02:20:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4934B8D0026; Fri, 7 Aug 2020 02:20:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ADF98D0049; Fri, 7 Aug 2020 02:20:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id 23E398D0026 for ; Fri, 7 Aug 2020 02:20:31 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E9348181AEF10 for ; Fri, 7 Aug 2020 06:20:30 +0000 (UTC) X-FDA: 77122773420.26.root59_3103b4d26fbe Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id B9D331804B667 for ; Fri, 7 Aug 2020 06:20:30 +0000 (UTC) X-Spam-Summary: 1,0,0,006c5fb0816ea1c8,d41d8cd98f00b204,akpm@linux-foundation.org,,RULES_HIT:41:355:379:800:960:966:967:973:988:989:1260:1263:1345:1359:1381:1431:1437:1534:1542:1711:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2525:2559:2563:2682:2685:2693:2741:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:5007:6261:6653:7576:7903:8599:9025:9545:9592:10004:10913:11026:11232:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12679:12783:12986:13221:13227:13229:14096:14181:14721:14849:21080:21450:21451:21627:21795:21939:21966:21987:21990:30012:30051:30054:30064:30070:30080,0,RBL:198.145.29.99:@linux-foundation.org:.lbl8.mailshell.net-64.100.201.201 62.2.0.100;04yfxnr4iduttdibc4xkwobsrno97opwn8e4awapm7rs7ay8ak951zrpqwn5y56.eoza37cwkmyxk3qweknur6qryyn8cirtozof4q963n388hy484a8jqo8y46rzwz.4-lbl8.mailshell.net-223.238.255.100,Cache IP:none, X-HE-Tag: root59_3103b4d26fbe X-Filterd-Recvd-Size: 3819 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Fri, 7 Aug 2020 06:20:30 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34DEC221E5; Fri, 7 Aug 2020 06:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596781229; bh=/+GjuyI/einNEPcWggkqcOYCxaQ8Rpt+T+rqa38Zqwo=; h=Date:From:To:Subject:In-Reply-To:From; b=ICF0VlBESrUh5vw8C0dxRLkpAmZRmhBBGP/WSdcbcNNMaSO5z7NK4DPnq8I0aB9SL pD8d8LETxQdWF9bIsy0FxzXXYLDlsGL2HjKhNDFK9ihKMxavLHsed88cprvDATEyIu unc2z0X1jtSCv8TQfT0Snj42+OZ1SoFgftHh3P2U= Date: Thu, 06 Aug 2020 23:20:28 -0700 From: Andrew Morton To: akpm@linux-foundation.org, guro@fb.com, linux-mm@kvack.org, mhocko@suse.com, mm-commits@vger.kernel.org, naresh.kamboju@linaro.org, shakeelb@google.com, torvalds@linux-foundation.org, vbabka@suse.cz Subject: [patch 061/163] mm: kmem: make memcg_kmem_enabled() irreversible Message-ID: <20200807062028.9dTsF8Lvx%akpm@linux-foundation.org> In-Reply-To: <20200806231643.a2711a608dd0f18bff2caf2b@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: B9D331804B667 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000158, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Roman Gushchin Subject: mm: kmem: make memcg_kmem_enabled() irreversible Historically the kernel memory accounting was an opt-in feature, which could be enabled for individual cgroups. But now it's not true, and it's on by default both on cgroup v1 and cgroup v2. And as long as a user has at least one non-root memory cgroup, the kernel memory accounting is on. So in most setups it's either always on (if memory cgroups are in use and kmem accounting is not disabled), either always off (otherwise). memcg_kmem_enabled() is used in many places to guard the kernel memory accounting code. If memcg_kmem_enabled() can reverse from returning true to returning false (as now), we can't rely on it on release paths and have to check if it was on before. If we'll make memcg_kmem_enabled() irreversible (always returning true after returning it for the first time), it'll make the general logic more simple and robust. It also will allow to guard some checks which otherwise would stay unguarded. Link: http://lkml.kernel.org/r/20200702180926.1330769-1-guro@fb.com Signed-off-by: Roman Gushchin Reported-by: Naresh Kamboju Tested-by: Naresh Kamboju Reviewed-by: Shakeel Butt Acked-by: Vlastimil Babka Acked-by: Michal Hocko Signed-off-by: Andrew Morton --- mm/memcontrol.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) --- a/mm/memcontrol.c~mm-kmem-make-memcg_kmem_enabled-irreversible +++ a/mm/memcontrol.c @@ -3416,7 +3416,8 @@ static int memcg_online_kmem(struct mem_ if (memcg_id < 0) return memcg_id; - static_branch_inc(&memcg_kmem_enabled_key); + static_branch_enable(&memcg_kmem_enabled_key); + /* * A memory cgroup is considered kmem-online as soon as it gets * kmemcg_id. Setting the id after enabling static branching will @@ -3486,11 +3487,6 @@ static void memcg_free_kmem(struct mem_c /* css_alloc() failed, offlining didn't happen */ if (unlikely(memcg->kmem_state == KMEM_ONLINE)) memcg_offline_kmem(memcg); - - if (memcg->kmem_state == KMEM_ALLOCATED) { - WARN_ON(!list_empty(&memcg->kmem_caches)); - static_branch_dec(&memcg_kmem_enabled_key); - } } #else static int memcg_online_kmem(struct mem_cgroup *memcg)