Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1834055pxb; Fri, 5 Feb 2021 02:38:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxek/4ifnzp1nNewaAAM5uIxOT2goxL9eWqwmvfmFLQHqKkSTC7JhBDymJBB1ZCs3j082CC X-Received: by 2002:a17:906:7c4b:: with SMTP id g11mr3408834ejp.475.1612521495860; Fri, 05 Feb 2021 02:38:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612521495; cv=none; d=google.com; s=arc-20160816; b=vu9pSsTa8Jj1vN/LD3VjwdU/tjsT4JtzOrk/OZghCD339lquoKB711FOlrB0PhqwAf 9Ksu4fBj0JtOE7Zizd/ruJ9ORYAfA11WLtSKgnPx5mW/Ltp+jAhUvAbkcAThlLDpfNwN GrCsJ/GCmueB3fCTg9N5eWpJI+oLPB7V5sVuAsZ175aRGGzXv5b7f4PWfEUBugxBRdH0 AsmBoilV2a3hsl1Fles0LWzUXw69dQe1Tgo32Jj1CDAGUfqYjCwwP+FwVhcFP6lMMnq1 GLmBQBgtWlGQFV1I3363ByLM58c4H4vo0YJQFzgDoGWd5fneg+ueY+MzmjIl/VRPLxE+ WqSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ACh5Vg4Vj3WoVaDbqs/kysUN1AfSYSlCpU+9KnbgM40=; b=G5jn3+KJ/Xpt7+IIrYGn6Y/ob+4IEu2Y0lLbHV42SHMgTn/xsbdgAvXjgisTdpv6wT aWNGluf0CDLQCcpKUYlUWL7iPFooygmvdEidhB4J5jrTDla8jcqFWLB/zljgVtWotTM1 nyRbrw9GDSL5ZN7ivbPCaho0nxjZ/82lVJnHYzaCWd51gShptaQMhFhH3hnSrlL6Xxz6 qo+h+bJIKmaErLNbExhD8w0QzlbKGJljm6QzQ2IytA9NyYz7RJXOW9NKOXrVUQycsFjX Kyarh5ejr6s83+rhsiJC8CW2FlHNycfMGofjArCKeVEIhbNOlNqHpyCHKzG/8LinsUke SKYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hwvRcbTJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si5059078ejr.536.2021.02.05.02.37.50; Fri, 05 Feb 2021 02:38:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hwvRcbTJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231516AbhBEKf4 (ORCPT + 99 others); Fri, 5 Feb 2021 05:35:56 -0500 Received: from mx2.suse.de ([195.135.220.15]:47602 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231320AbhBEKdO (ORCPT ); Fri, 5 Feb 2021 05:33:14 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1612521146; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ACh5Vg4Vj3WoVaDbqs/kysUN1AfSYSlCpU+9KnbgM40=; b=hwvRcbTJ3MEj6IBdwwkoKfwd7NWUhfVRJzQxI0/0co73u9YtUF+1WTj6RZoYNiQiuFvlwE VdvkdMruE4nY0z5v8xMHShGJwr94gj1gcxWa9jf53SJAL8YbmRWCqt87qpQC/dLOpeMSF5 pMYbJbatpZx7hig7uJJPRQjhHVUDU20= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 05899ACBA; Fri, 5 Feb 2021 10:32:26 +0000 (UTC) Date: Fri, 5 Feb 2021 11:32:24 +0100 From: Michal Hocko To: Muchun Song Cc: Johannes Weiner , Vladimir Davydov , Andrew Morton , Cgroups , Linux Memory Management List , LKML Subject: Re: [External] Re: [PATCH] mm: memcontrol: remove rcu_read_lock from get_mem_cgroup_from_page Message-ID: References: <20210205062719.74431-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 05-02-21 17:14:30, Muchun Song wrote: > On Fri, Feb 5, 2021 at 4:36 PM Michal Hocko wrote: > > > > On Fri 05-02-21 14:27:19, Muchun Song wrote: > > > The get_mem_cgroup_from_page() is called under page lock, so the page > > > memcg cannot be changed under us. > > > > Where is the page lock enforced? > > Because it is called from alloc_page_buffers(). This path is under > page lock. I do not see any page lock enforecement there. There is not even a comment requiring that. Can we grow more users where this is not the case? There is no actual relation between alloc_page_buffers and get_mem_cgroup_from_page except that the former is the only _current_ existing user. I would be careful to dictate locking based solely on that. > > > Also, css_get is enough because page > > > has a reference to the memcg. > > > > tryget used to be there to guard against offlined memcg but we have > > concluded this is impossible in this path. tryget stayed there to catch > > some unexpected cases IIRC. > > Yeah, it can catch some unexpected cases. But why is this path > special so that we need a tryget? I do not remember details and the changelog of that change is not explicit but I suspect it was just because this one could trigger as there are external callers to memcg. Is this protection needed? I am not sure, this is for you to justify if you want to remove it. > > > 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(). > > > > What is the primary motivation to change this code? is the overhead of > > tryget/RCU something that needs optimizing? > > Actually, the rcu_read_lock() is not necessary here. So it is better to > remove it (indeed reduce some code). Please state your reasoning in the changelog including benefits we get from it. -- Michal Hocko SUSE Labs