From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 B9F87C433DB for ; Mon, 8 Feb 2021 10:01:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87BED64E7D for ; Mon, 8 Feb 2021 10:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232107AbhBHKBR (ORCPT ); Mon, 8 Feb 2021 05:01:17 -0500 Received: from mx2.suse.de ([195.135.220.15]:35330 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232094AbhBHJvS (ORCPT ); Mon, 8 Feb 2021 04:51:18 -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=1612777831; 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=DBsRDf6sKqoMXs8BxrjoloByzTHcZkFKh1qcJfej7kE=; b=RxLdmpgIP2mi8IiqRZ8SAFMocjqnRTOjFH2a8wzNNG3Zam8FkcECpEIB1U0+xH5owzyP7q S0kfhi3+LbYmQib6RH4JkfgEhk+vEl1tKs105T7c8HR6vUAB8vci4uGyHYxqjjLNg47t0d Nq8qNK2qyrr65vSyHTHMbjBYjVWP6Vo= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A5A65AE56; Mon, 8 Feb 2021 09:50:31 +0000 (UTC) Date: Mon, 8 Feb 2021 10:50:29 +0100 From: Michal Hocko To: Johannes Weiner Cc: Muchun Song , 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 13:15:40, Johannes Weiner wrote: > On Fri, Feb 05, 2021 at 11:32:24AM +0100, Michal Hocko wrote: > > 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. > > Since alloc_page_buffers() holds the page lock throughout the entire > time it uses the memcg, there is no actual reason for it to use RCU or > even acquire an additional reference on the css. We know it's pinned, > the charge pins it, and the page lock pins the charge. It can neither > move to a different cgroup nor be uncharged. > > So what do you say we switch alloc_page_buffers() to page_memcg()? > > And because that removes the last user of get_mem_cgroup_from_page(), > we can kill it off and worry about a good interface once a consumer > materializes for it. Yes, this makes much more sense than impose a weird locking rules to a more general purpose helper. Thanks! -- Michal Hocko SUSE Labs