From patchwork Thu Oct 12 16:15:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 13419426 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C967CDB46E for ; Thu, 12 Oct 2023 16:15:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE5088D0133; Thu, 12 Oct 2023 12:15:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D955E8D0002; Thu, 12 Oct 2023 12:15:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5D0A8D0133; Thu, 12 Oct 2023 12:15:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B7BF38D0002 for ; Thu, 12 Oct 2023 12:15:22 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9334A120634 for ; Thu, 12 Oct 2023 16:15:22 +0000 (UTC) X-FDA: 81337309284.07.D2F26C1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id DBD654001E for ; Thu, 12 Oct 2023 16:15:20 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h0n7MH1w; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697127321; a=rsa-sha256; cv=none; b=LC16SncQaVXCaoX0Ea9ted3AwzZKR11xthtOEQNSM308ElPXMdR1xiPmQgamYeWRv9yojl lTH4SJbuxdPBFnMN94WeUbrM8vKL86XYLTBWbm76TMIyzzXmEUs8g+DLhAcp7y6HHEuEm3 osr6MxmJQ1sS9LNGnvjR9Fb4EpWcCjk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h0n7MH1w; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697127321; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=yK0UlD3djzpWABLGKAkWK+EBIxdVaT62RUBs+nKaYeM=; b=ZsKl6Pbwqm1UUzvVfZeMh7ENC9QTi8szlLGN8iINm7e/CVsKm6pxszIsuugZGvOdgp7nOY qWzZiCKAKMG5lmkIX2XVgKu0B9ihWyavXd1PLShr8uqAAZGHgorTf+Aw3CwWsrbGBz8ePZ 3U36N+lvozDq78kOSeKH7v54X3F3390= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697127320; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yK0UlD3djzpWABLGKAkWK+EBIxdVaT62RUBs+nKaYeM=; b=h0n7MH1w9NF22cHLJ/FK/qrYakvJz35QFOnyosUSamY4fel73+nI6z6wEykkcuZfRCcCjI CyUHH15oEN/V+NM97rTaIl25O+TlYDn2qI8x0xexoCotaKgUF5OH/ZqP0rLOS6Fw2QbQf7 eIJfFuz5t8UVNzlyi6nVgxA+aWXB3t8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-283-YrMuxBEwOPq_N8GMot6KQA-1; Thu, 12 Oct 2023 12:15:14 -0400 X-MC-Unique: YrMuxBEwOPq_N8GMot6KQA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B071C1C01521; Thu, 12 Oct 2023 16:15:13 +0000 (UTC) Received: from llong.com (unknown [10.22.32.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30BCB40C6F79; Thu, 12 Oct 2023 16:15:13 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Waiman Long Subject: [PATCH] mm: memcontrol: Don't css_get() on root_mem_cgroup in get_mem_cgroup_from_mm() Date: Thu, 12 Oct 2023 12:15:04 -0400 Message-Id: <20231012161504.3445042-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DBD654001E X-Stat-Signature: akz8ipckyu3upkybd7m7ibuii94tbxty X-HE-Tag: 1697127320-765760 X-HE-Meta: U2FsdGVkX18kH1xIQoWp1g9E75XcBps+Fzccf3/Gvz4Vm3JA4YOuUl5H5pKWz/7S86PMzwLpKk+h1rrvh3LY7QykWK01vXo2IRhUUiXHmHvSZkhQ4/W5YyVUytcZfqPHgpooCTIcafaZ00a62VL8FIERFr0F7g7HIwj59nyLYYASf+/tOtmDMV9CtejC4TYcfyK31AGlFeheTfGZ6hwTy0TTsd75i52Wc86PLsJyx74+ryWjra/vHcjSZhHFEsutQzYVOrD+wY34+01su3+wsBlxUuHFLpHrq8OEPQInTAh2rmOhNuAMs2CboZkBb1GsMgpMDh9rsaO98d/0OxDTNVf8zvhX9R/dwHhODpSFjAO7UVOTD/ksNrNeATWWv3r58oymwPbDjO3qEPF/jt6UKYwRU45/52GlwMeZwgawYXykXOzMIU/wokRGR5U/9nT4ks9EoZikneZIYGimykczSfiD10sg8LdIV3Zyy4bW5DD/Gzlo6sbTySCyOCx8imE7KtmMfJDI5sH3CZojfHtYeW9SihlGQ+aVOTn0gLThjXBaSDGyM+io2j+YemM6ooNM0+SSTOyiM8r/yzLpGgBNjSHGZkxuQh5fjFZ9/99nbtf71eU8ke9iFnmRbZG7CXlmE/WZ4s71w9APF/aWO1xBhkyud7grg4kBgcvj9nhDm5pYdsw0JN5BjqA4RjPazUuFQPfIUjBGL8uMF0H69UCQJDRVgZCge4OavR97msB91aBjFROO0gK8yp7NooQVSMv/b3KZlfcJ5gfhZEuIyCOuQkhbG3w57pOPi5COPLftwMJD5/EWlc2p6fapew/lpDu5/bSX41Vs2LtuFmuT5OsyL8tr3VMo6lVO5FpXldqoOckk/ZnRsquextfVyZmV0pOdHsZR9ccknPCsMtyIkCE2J1xLVG3XMDTDCQZSMYTFY+/8NIZDJZ/fje75z8Qzc75DimOAkTnc8+4y6wUZOV5 /rUDJDhz PSc1T72buC0tDAHh0dadsR7yTlHOiuZpBu2gm70HI/LrSRcBhoJwol6/rqxOWmyAp7ehO/+OL1xFQqOjvhQAIbwTFRjDl1xTwvw2V93It/i9wIiyCO1XnVhOQ+zojmYrYqQ21/c2tK/uuaPxDM2Pxqcp+2tUa3VGYGKyly5h8ylzizaA4LRHOC3tb4MvLxWyK8iITKsqyuAvnodmqZHU5MDSD9Q== 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: As reference counting in the root memcg is disabled, there is no need to get a reference if root memcg is to be returned. Signed-off-by: Waiman Long --- mm/memcontrol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5b009b233ab8..2b3864194042 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1060,8 +1060,10 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) rcu_read_lock(); do { memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); - if (unlikely(!memcg)) + if (unlikely(!memcg)) { memcg = root_mem_cgroup; + break; + } } while (!css_tryget(&memcg->css)); rcu_read_unlock(); return memcg;