From patchwork Fri Feb 5 06:27:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12069321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5791AC433E6 for ; Fri, 5 Feb 2021 06:29:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D059A64F9C for ; Fri, 5 Feb 2021 06:29:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D059A64F9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 20C216B0005; Fri, 5 Feb 2021 01:29:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BD096B006C; Fri, 5 Feb 2021 01:29:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0ACA26B006E; Fri, 5 Feb 2021 01:29:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id EBAD46B0005 for ; Fri, 5 Feb 2021 01:29:03 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B7696181AEF1F for ; Fri, 5 Feb 2021 06:29:03 +0000 (UTC) X-FDA: 77783236566.21.quiet94_5716d78275e2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id A0543180442C0 for ; Fri, 5 Feb 2021 06:29:03 +0000 (UTC) X-HE-Tag: quiet94_5716d78275e2 X-Filterd-Recvd-Size: 4167 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Feb 2021 06:29:02 +0000 (UTC) Received: by mail-pf1-f181.google.com with SMTP id x23so2171423pfn.6 for ; Thu, 04 Feb 2021 22:29:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QF0he1VW/PCEQZ3zvHTH+OFfohkfMVY0GDe6DZx57Hw=; b=mj7FWoJGFrcDOyAz41eFXfoppM9M6PPJ32NbJyxstX+ZDQjXJigyQZplmJkH1qTaAI tm89hJvYutfGv0GWNXUUQeCzoJ4C1a7kocoby20QK3xTwDOYU/yJA0TF1WaRDHIUUUdC 0EWmCqXSeA0fyGWqsNXnOD836itIMNkR8oUG61F/cNHeTPby+jkXrI5RCBcFZzO81HU8 BN1Tb9aUvc0GqHGTD/r/CFvwf9C+OvZYdrFV4VIhdqahmaktNx4YjXoYrf4mTytMSB+O rtJ4q/JfOEKmZiEiZ6H65IwVAg6QM2ai3mfUyEUMJMhZ7LKuc7hL/E3I8Uwbj2NN4jIy JCNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QF0he1VW/PCEQZ3zvHTH+OFfohkfMVY0GDe6DZx57Hw=; b=W99eTJFQk3UgZNaZtCezpgDZ9TypN1V9FUU76TvOswJ4J+n3vrbub8RjaMwZnf7Qm2 zEqXcfTlcp9X5YBahuwaneEEPltMLFF7lBUbJaZ1i2fo7lzibVpioO2AsrVgtLQQGs8B rOkz5Rpzihx+NsGHjGaa1oE/kZ3HUZuthzoEV3snAAq5od/2EuSfzNfbwrlTjFmWHQUx AsnTJg3tctrGpj7hOMt3P1EiZ96BVrYf/XlEsVHZibw+EmacmC0qQXD03DxUJIb2/ymT ER0jqyRqLYtxzQ08qNNre/RF7HQhzkvmEF2afbCe7RVITJ5qvnXcQ3ZU7nTZDLiIyAtC /vqg== X-Gm-Message-State: AOAM530vlYcJPKj2Cr67mpDhcAvWZoRrAWOToymzNTXgiXvu4aPVbh6F 74zFVdn9CKq95PI4ajZzZU+n8w== X-Google-Smtp-Source: ABdhPJz3xSak1Dn+1ZNBcoidjGDQlEMM7oxnX3oxqr4zZSU6RqBaCShF9omCB+EjG8E8nejz7cbpsQ== X-Received: by 2002:a63:db05:: with SMTP id e5mr3016291pgg.104.1612506541740; Thu, 04 Feb 2021 22:29:01 -0800 (PST) Received: from localhost.localdomain ([240e:b1:e401:3::f]) by smtp.gmail.com with ESMTPSA id z2sm8644919pgl.49.2021.02.04.22.28.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Feb 2021 22:29:01 -0800 (PST) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH] mm: memcontrol: remove rcu_read_lock from get_mem_cgroup_from_page Date: Fri, 5 Feb 2021 14:27:19 +0800 Message-Id: <20210205062719.74431-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 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: The get_mem_cgroup_from_page() is called under page lock, so the page memcg cannot be changed under us. Also, css_get is enough because page has a reference to the memcg. If we really want to make the get_mem_cgroup_from_page() suitable for arbitrary page, we should use page_memcg_rcu() instead of page_memcg() and call it after rcu_read_lock(). Signed-off-by: Muchun Song --- mm/memcontrol.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 87f01bc05d1f..6c7f1ea3955e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1063,16 +1063,15 @@ EXPORT_SYMBOL(get_mem_cgroup_from_mm); */ struct mem_cgroup *get_mem_cgroup_from_page(struct page *page) { - struct mem_cgroup *memcg = page_memcg(page); + struct mem_cgroup *memcg; if (mem_cgroup_disabled()) return NULL; - rcu_read_lock(); /* Page should not get uncharged and freed memcg under us. */ - if (!memcg || WARN_ON_ONCE(!css_tryget(&memcg->css))) - memcg = root_mem_cgroup; - rcu_read_unlock(); + memcg = page_memcg(page) ? : root_mem_cgroup; + css_get(&memcg->css); + return memcg; } EXPORT_SYMBOL(get_mem_cgroup_from_page);