From patchwork Thu Jul 2 18:09:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 11640109 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 758F1912 for ; Thu, 2 Jul 2020 18:12:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 388CF2073E for ; Thu, 2 Jul 2020 18:12:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="qtCdkScl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 388CF2073E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=fb.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 774DD8D001B; Thu, 2 Jul 2020 14:12:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6FEB78D000C; Thu, 2 Jul 2020 14:12:09 -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 5A0F98D001B; Thu, 2 Jul 2020 14:12:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id 43D5F8D000C for ; Thu, 2 Jul 2020 14:12:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 004C0181ABE84 for ; Thu, 2 Jul 2020 18:12:08 +0000 (UTC) X-FDA: 76993929978.27.rub52_5702b0726e8b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 9F0A23D677 for ; Thu, 2 Jul 2020 18:12:01 +0000 (UTC) X-Spam-Summary: 1,0,0,4a623863fe323573,d41d8cd98f00b204,prvs=445236cb71=guro@fb.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1261:1277:1311:1313:1314:1345:1437:1513:1515:1516:1518:1521:1535:1542:1711:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2559:2562:2693:2741:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:4321:4385:4421:5007:6261:6653:7903:9592:10004:10400:11026:11658:11914:12043:12114:12296:12297:12438:12555:12895:12986:13221:13227:13229:14096:14097:14181:14394:14721:21080:21450:21451:21627:21795:21966:21987:30012:30051:30054:30064:30070:30080,0,RBL:67.231.153.30:@fb.com:.lbl8.mailshell.net-62.12.0.100 64.201.201.201;04yfrz9dwgex1bcoh4eu8ckk6da4toc5w9z6kbz1xui8f9in8rw9e595cwuzpud.93pminrqfka6tsqjs65n51dqxhxbtm59ipo6aps6u6fnane3apf43oph735pxfm.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: rub52_5702b0726e8b X-Filterd-Recvd-Size: 5153 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Thu, 2 Jul 2020 18:12:00 +0000 (UTC) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 062I9QMq017291 for ; Thu, 2 Jul 2020 11:12:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=CJyNV5YUA7rqu9aEpTgmUJO26puxcK+5HorI44iY9yM=; b=qtCdkSclKehj8rQos5KGEfYlMxOtWyWajQRZHAYi0E7+CoznFL/NS9xA1g6kVyimnxCs WcK5Dk/ktQyfbqaqU/jziH4RbD0GgCqQNpIenX+hBzlqe9sw12+e9VRUC3CbTn7xczzf JQhFlDayLTTI3j1UNbaMc9ha1kRRIA3agi8= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 320amq2x8q-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 02 Jul 2020 11:12:00 -0700 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 2 Jul 2020 11:11:59 -0700 Received: by devvm1096.prn0.facebook.com (Postfix, from userid 111017) id 11589A2F56B; Thu, 2 Jul 2020 11:09:33 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm1096.prn0.facebook.com To: Andrew Morton CC: Johannes Weiner , Michal Hocko , Shakeel Butt , , Vlastimil Babka , , , Roman Gushchin , Naresh Kamboju , Michal Hocko Smtp-Origin-Cluster: prn0c01 Subject: [PATCH v2] mm: kmem: make memcg_kmem_enabled() irreversible Date: Thu, 2 Jul 2020 11:09:26 -0700 Message-ID: <20200702180926.1330769-1-guro@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-02_09:2020-07-02,2020-07-02 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 phishscore=0 priorityscore=1501 clxscore=1015 lowpriorityscore=0 mlxscore=0 bulkscore=0 mlxlogscore=792 spamscore=0 malwarescore=0 suspectscore=2 cotscore=-2147483648 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020124 X-FB-Internal: deliver X-Rspamd-Queue-Id: 9F0A23D677 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. 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 --- mm/memcontrol.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 50ae77f3985e..0145a77aa074 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3582,7 +3582,8 @@ static int memcg_online_kmem(struct mem_cgroup *memcg) objcg->memcg = memcg; rcu_assign_pointer(memcg->objcg, objcg); - 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 @@ -3643,9 +3644,6 @@ static void memcg_free_kmem(struct mem_cgroup *memcg) /* css_alloc() failed, offlining didn't happen */ if (unlikely(memcg->kmem_state == KMEM_ONLINE)) memcg_offline_kmem(memcg); - - if (memcg->kmem_state == KMEM_ALLOCATED) - static_branch_dec(&memcg_kmem_enabled_key); } #else static int memcg_online_kmem(struct mem_cgroup *memcg)