Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp286393pxb; Wed, 14 Apr 2021 15:37:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9G1to34Ng2zoMAhRf7J8ePcA/Q35pZMBztyz/ydSG2MdoR2JND7ki8H8k1K6l4c1AiPNX X-Received: by 2002:a17:906:2dd9:: with SMTP id h25mr352046eji.6.1618439861889; Wed, 14 Apr 2021 15:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618439861; cv=none; d=google.com; s=arc-20160816; b=ukr0BfdII1PwlFsIIH6370pDgQqOwYsgvjX73N75nCcq6m3cR1JxWZp6ijmCCF1+Oe ii8RR6nhFInMjAxWIDLLfyBc7k5X1j7uijddpepX5f/KWsj+8NXsXr89U6dlRn1py0wx oyliqlz+QnFGn9e/LbKu7QK3k01suFWBG4hPNYBAGZ0yScxqMSSLeF0gEuaNJps6Lxwd JRwfdI0s21Qgvq/kVvM4bErRyIGvoDQya2Y3LjWXHZxZ9pYr3FyySamzRw+tv5tk9hlT qQiJmAzd+ZIP3hXf9k8TiBGefdyp/TtZ/OViLfXIMDjt7F09td6rZa8gSAAHgRCIzbAY gaaw== 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=xIV9mSCMhWgVCV1DmyiKJTiT4x6BbNMzGFIKxnc5TRc=; b=b2V6NBdYg5vM0nasd2UgkrigVnRdlFvDk+8gKiXBxyQWuGXEslU1zXi5sc2/yQsBK/ 777g9GvksSO6QFPCRYZvXInB+1cFi3e8Bi8QlqSTPiGiINkA167oyVnBcqdG8qS4ameO QOe3NpxUbzVf09BFe6G+ERHMCdduhcfGbN6UVZ83lwvZ6/nYF4/eG2E8VtSGf0wAzM4X ZQuCN4gUMssFX2Jbubli1JrEZBb550P8ZeJrvdyZXS1pevn3VvJQHBzVnfEthuBBokPC b38QjX0gKaSeXQpOfCdJc8BeqgkanEJpeoSP9mfFodnEs+UMAJ19PUoRQAkFv4CIUVTL fnag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ROVOiiFh; 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 i26si537861ejc.496.2021.04.14.15.37.18; Wed, 14 Apr 2021 15:37:41 -0700 (PDT) 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=ROVOiiFh; 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 S235497AbhDNJof (ORCPT + 99 others); Wed, 14 Apr 2021 05:44:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:58550 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233066AbhDNJoe (ORCPT ); Wed, 14 Apr 2021 05:44:34 -0400 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=1618393452; 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=xIV9mSCMhWgVCV1DmyiKJTiT4x6BbNMzGFIKxnc5TRc=; b=ROVOiiFhsfcHUWBrInqbls1h5UVNQHQtTNGJNSZoinLAyv7YpkJK9dELFHhc9+i+6KVYfa vO8zjR1poOPzh4wuqz5iXNPjaU5ea4FSEkNnY++4ojcTJSlMwbCXL8rBBzLj4zky+mWaN/ IIiTY0SGMaT0Fr9mXc78+AOEmVmYCnQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 10307ABB3; Wed, 14 Apr 2021 09:44:12 +0000 (UTC) Date: Wed, 14 Apr 2021 11:44:10 +0200 From: Michal Hocko To: Muchun Song Cc: guro@fb.com, hannes@cmpxchg.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com Subject: Re: [PATCH 4/7] mm: memcontrol: simplify lruvec_holds_page_lru_lock Message-ID: References: <20210413065153.63431-1-songmuchun@bytedance.com> <20210413065153.63431-5-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210413065153.63431-5-songmuchun@bytedance.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 13-04-21 14:51:50, Muchun Song wrote: > We already have a helper lruvec_memcg() to get the memcg from lruvec, we > do not need to do it ourselves in the lruvec_holds_page_lru_lock(). So use > lruvec_memcg() instead. And if mem_cgroup_disabled() returns false, the > page_memcg(page) (the LRU pages) cannot be NULL. So remove the odd logic > of "memcg = page_memcg(page) ? : root_mem_cgroup". And use lruvec_pgdat > to simplify the code. We can have a single definition for this function > that works for !CONFIG_MEMCG, CONFIG_MEMCG + mem_cgroup_disabled() and > CONFIG_MEMCG. Neat. While you are at it wouldn't it make sesne to rename the function as well. I do not want to bikeshed but this is really a misnomer. it doesn't check anything about locking. page_belongs_lruvec? > Signed-off-by: Muchun Song > Acked-by: Johannes Weiner Acked-by: Michal Hocko > --- > include/linux/memcontrol.h | 31 +++++++------------------------ > 1 file changed, 7 insertions(+), 24 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 4f49865c9958..38b8d3fb24ff 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -755,22 +755,6 @@ static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page) > return mem_cgroup_lruvec(memcg, pgdat); > } > > -static inline bool lruvec_holds_page_lru_lock(struct page *page, > - struct lruvec *lruvec) > -{ > - pg_data_t *pgdat = page_pgdat(page); > - const struct mem_cgroup *memcg; > - struct mem_cgroup_per_node *mz; > - > - if (mem_cgroup_disabled()) > - return lruvec == &pgdat->__lruvec; > - > - mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec); > - memcg = page_memcg(page) ? : root_mem_cgroup; > - > - return lruvec->pgdat == pgdat && mz->memcg == memcg; > -} > - > struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); > > struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm); > @@ -1229,14 +1213,6 @@ static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page) > return &pgdat->__lruvec; > } > > -static inline bool lruvec_holds_page_lru_lock(struct page *page, > - struct lruvec *lruvec) > -{ > - pg_data_t *pgdat = page_pgdat(page); > - > - return lruvec == &pgdat->__lruvec; > -} > - > static inline void lruvec_memcg_debug(struct lruvec *lruvec, struct page *page) > { > } > @@ -1518,6 +1494,13 @@ static inline void unlock_page_lruvec_irqrestore(struct lruvec *lruvec, > spin_unlock_irqrestore(&lruvec->lru_lock, flags); > } > > +static inline bool lruvec_holds_page_lru_lock(struct page *page, > + struct lruvec *lruvec) > +{ > + return lruvec_pgdat(lruvec) == page_pgdat(page) && > + lruvec_memcg(lruvec) == page_memcg(page); > +} > + > /* Don't lock again iff page's lruvec locked */ > static inline struct lruvec *relock_page_lruvec_irq(struct page *page, > struct lruvec *locked_lruvec) > -- > 2.11.0 -- Michal Hocko SUSE Labs