lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YGdEnN6WkKbNp1QJ@cmpxchg.org>
Date:   Fri, 2 Apr 2021 12:21:48 -0400
From:   Johannes Weiner <hannes@...xchg.org>
To:     Muchun Song <songmuchun@...edance.com>
Cc:     guro@...com, mhocko@...nel.org, akpm@...ux-foundation.org,
        shakeelb@...gle.com, vdavydov.dev@...il.com,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        duanxiongchun@...edance.com, Hugh Dickins <hughd@...gle.com>
Subject: Re: [RFC PATCH 04/15] mm: memcontrol: use lruvec_memcg in
 lruvec_holds_page_lru_lock

On Tue, Mar 30, 2021 at 06:15:20PM +0800, 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.
> 
> Signed-off-by: Muchun Song <songmuchun@...edance.com>
> ---
>  include/linux/memcontrol.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index a35a22994cf7..6e3283828391 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -744,20 +744,20 @@ static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page)
>  	return mem_cgroup_lruvec(memcg, pgdat);
>  }
>  
> +static inline struct mem_cgroup *lruvec_memcg(struct lruvec *lruvec);

Please reorder the functions instead to avoid forward decls.

>  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;
> +	return lruvec->pgdat == pgdat && lruvec_memcg(lruvec) == memcg;

Looks reasonable to me, but I wonder if there is more we can do.

lruvec_memcg() already handles CONFIG_MEMCG and mem_cgroup_disabled()
combinations, and there is also a lruvec_pgdat() which does.

One thing that is odd is page_memcg(page) ? : root_mem_cgroup. How can
lruvec pages not have a page_memcg()? mem_cgroup_page_lruvec() has:

	memcg = page_memcg(page);
	VM_WARN_ON_ONCE_PAGE(!memcg && !mem_cgroup_disabled(), page);

Unless I'm missing something, we should be able to have a single
definition for this function that works for !CONFIG_MEMCG,
CONFIG_MEMCG + mem_cgroup_disabled() and CONFIG_MEMCG:

lruvec_holds_page_lru_lock()
{
	return lruvec_pgdat(lruvec) == page_pgdat(page) &&
		lruvec_memcg(lruvec) == page_memcg(page);
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ