Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp419748rdg; Thu, 12 Oct 2023 09:16:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiYKoY/zQC9pqKN2C1Hnjwf2ImeyOLEONhczhd+bHVouEkZV7JxdnA4UmA8Irg/QZITtqA X-Received: by 2002:a05:6a20:1593:b0:155:5c28:ea74 with SMTP id h19-20020a056a20159300b001555c28ea74mr26134943pzj.12.1697127383462; Thu, 12 Oct 2023 09:16:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697127383; cv=none; d=google.com; s=arc-20160816; b=gDU4902ZvctvZAtn5tszW1XOWLUGL4nQKKmQLyEKcP4ByYjrVav4Q2dZ7HejCaH+kp LkOT81qm6ja2DPTcaipWphN/KB54+alHJ3yaYV4/oK4iNawRATTO9XudkwPupJd8Nryl wHjN8uX4YaVW0Jah8suw7/CWNPAlrqTOLZk/F/7wluc4Oyt4G/rXI/uxxMtBoqEreXnR 4tSGVGxgO+z4Z7gw3wvthqO1iJhq0nRCNH0RrWITJLdKddMDrh0zisbB13vkjTNkGWPj SBw4R5zROyjIa/OC9fcYpNcfVxI6A7SxFERu8bECd4Qh38znIOX/tANF5/rArzUhi88B epkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yK0UlD3djzpWABLGKAkWK+EBIxdVaT62RUBs+nKaYeM=; fh=8H81pgWrL5wcv+H+xCMmmDVBCgWs13i2QgpwPvCFmL8=; b=wVjdidadIYcdbDwBoMytWnCUvgyfygfC9fnJUhVEyu2pksLhhZ6U/OWdp7kW6ORcT9 Z7xy8opkAnfnq4iClMcaqGivA9F3+rTtoalXTnDyozN0pyiEXr1jMyPFQMCy8wq3twQn YXVEGbIv00QixJsHmmgMW25hKQ/FZCO7UoNJixto/ho76v2EMJAgMEB2kkaNmEUrnh23 UXaHHJm7SJnKcCKBW3f7fEEJnuLSc7wOIbC3Lf/Zrlz0yiCJTJRPvm4aaUF3sPsOEHuU xED43bVm2mh6M6VIOUk0oh9urrZN5P4GOhqzHFF50KsUTh+ERXZWSYrxZViErVM+odh3 2MfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T1G+hA6b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id s5-20020a17090aad8500b00278f79e4fabsi2671644pjq.93.2023.10.12.09.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 09:16:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T1G+hA6b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0ABCE808986A; Thu, 12 Oct 2023 09:16:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344060AbjJLQQH (ORCPT + 99 others); Thu, 12 Oct 2023 12:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344059AbjJLQQG (ORCPT ); Thu, 12 Oct 2023 12:16:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF367CC for ; Thu, 12 Oct 2023 09:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697127319; 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=T1G+hA6bW2V0p8V9/nDu1QDxfc8aMtajGajTGv/Bo4inLtNVVGlBRUXZyOcWva/3YNobFP O2L0imzQUAInpE4lRsH1N5o3qipCCUo2HEg2KqLZn5Ay8qowu1kTvwboTcftVIRZxRAcwq hWF6sJSUU5/mGndLx97/DNEoehyrE+o= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 12 Oct 2023 09:16:21 -0700 (PDT) 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; -- 2.39.3