Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2359554pxb; Fri, 5 Feb 2021 16:20:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9Lv1Vg/jlBIzw9f5Yj6YGZ64NqiK/x4MJWgTq3QraSin6brNBa6BjZg1O+pkLDXd1HjtY X-Received: by 2002:aa7:c84b:: with SMTP id g11mr6042122edt.169.1612570814421; Fri, 05 Feb 2021 16:20:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612570814; cv=none; d=google.com; s=arc-20160816; b=uB9T6pt2y9Ohg4n9sI3lRNumDydkXOcZw3MHAPoTONJWZcVSyihqHxxZ9uqFvJDDQp JViPyOJlLLt1VIfGjVw4S526LZik0BG1JyHnX4Bkj0ovwajMAuMXxMrURFCjD5obeAG2 L0t+dkDLMnGoT1e5X9pZUY36jmKFwRTLenVxZb4nVjGnERSuBKATT9GwIrK0u0SAgB3z iKIhqM8z8pcgd5dedwehQ/9+EUdwfrkjyFm4aT72zD8G3asdF8CFnjYRmVv4+5eZq8vE umCWeC4cG3NOYP4vi5Tq+PCWtZNGqL95VCqjUlenX14cLNZyyxgpCBlUG2lH64/aWFf9 8gpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=at3tlE+CnMfJFYgoRalXte0nrDzDhLkLsR1wIcNPMOM=; b=I8T4e4Rcq0mt1DN5V+hG/P0/MGq3DqZ2oK4E5RUWwQXgBoLYga0TNNwkrqiEntH3kQ q54SVM7jkAhZTzToe3eUYLmgTjtUjGH8gYTiFS0AQVJ9l6s5F7Ybg7XDiIXcaY29jKX9 4ylXtdhRv8GTkN7YweNegCyvAyDT3EbM/36ljaXCGZjolTvM1CyM/KDVrPYnCeVOGnXW UhED+q1+7BLBbqdUGDJQ1+BM4/2D15dOUAFa70SYMGWzZgZb1VBZ3Mgr/0sG57Vr6JXE m+uW7OBiPFcTebnXA5f0OUlkHaqaudJKLnCfv3i2A6nP24w5BYmYE/cyu2i1tTJg9UUn Vjig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=rh+E2c1R; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si6120290ejj.506.2021.02.05.16.19.50; Fri, 05 Feb 2021 16:20:14 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=rh+E2c1R; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229927AbhBFARM (ORCPT + 99 others); Fri, 5 Feb 2021 19:17:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbhBEM5i (ORCPT ); Fri, 5 Feb 2021 07:57:38 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A33C06178B for ; Fri, 5 Feb 2021 04:56:46 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id c132so4493850pga.3 for ; Fri, 05 Feb 2021 04:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=at3tlE+CnMfJFYgoRalXte0nrDzDhLkLsR1wIcNPMOM=; b=rh+E2c1RBqi2Afh5NbYKEM3yLFpRTWi9kUBJWQ4+8iWFvtpIMOf9ASTnRxKKD+dKrA MJshQOYgCKe27lDY4QZkClKdDAUu9qWUjxOpvFSQTCDOBfkPF82Hynzf0IG1wPGdIzb3 IU5bD6qlsNnrrjF+g3m382MXpUkDMR3Oar4JbCr0JG9Fjh6x+19tfj4EeRFbc/8rQOqk a2gbS5rTBo0mgUTFtn4PFjuvqG5Dg2lg8Qu8xk0/+bqRB77gJgMpLq7CVYlWkf4XImVG 3ZBxBIpcfVcdKow7puYuDSj2Xw70IytFjMpGZ9aV5vKroCNt2CXgHJRdwIoPtBISS2fx ZFsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=at3tlE+CnMfJFYgoRalXte0nrDzDhLkLsR1wIcNPMOM=; b=QGHmtMefPMf2HzF4YVCYN+tEmO048arvLSKZhVfvFvP3fxG6c0Y6X2jmCLEXB0PcLH ViV+58JV93UbxheHtJENE/8+I1SqSWDnRnqzZQqioiGAYiG+BSFJBURe0TanGya+9/5Y FsOid9CocWOSiHL9QXutrwgo6t4mDYGEU3X4/DxTKxUThc/KLmW10agJt8vDaZ0hOP92 xC3the7Ft3XhpiSRgiw/4XTh0apQ+6FU3VEPWwcxw739/9RxktkzBL0tbL8XStRcqfd6 2GjHoDLOfoGU53Kc7L5r7/kPxaED/+9NrFLRHthiC1Ru37XJCLnaUghhIUNkuUNfjK5f Kz9g== X-Gm-Message-State: AOAM533ltK+dP5n6NIV3fKsX0QU6UYUefQ31GdW2xVxTn0yGIgS8MtKU 2/pfk++71ganxXOij9N7HFuzMSBwtl6k+ofIGF6wtiVFGto42rjR X-Received: by 2002:a63:1f21:: with SMTP id f33mr4371823pgf.31.1612529805660; Fri, 05 Feb 2021 04:56:45 -0800 (PST) MIME-Version: 1.0 References: <20210205062719.74431-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Fri, 5 Feb 2021 20:56:07 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm: memcontrol: remove rcu_read_lock from get_mem_cgroup_from_page To: Michal Hocko Cc: Johannes Weiner , Vladimir Davydov , Andrew Morton , Cgroups , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 5, 2021 at 6:32 PM 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. Yeah, there is no comment requiring that. I have seen all the callers of the alloc_page_buffers. I found that it is under page lock. But it seems it is not the key point here. I should delete those comments from the commit log. > > > > > 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. I am sure it is not needed. > > > > > 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. OK. > -- > Michal Hocko > SUSE Labs