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: <86d3ba7a-3706-d66c-cbf7-d2c39ad2cd4c@oracle.com>
Date:   Wed, 17 Nov 2021 16:12:49 -0800
From:   Mike Kravetz <mike.kravetz@...cle.com>
To:     Mina Almasry <almasrymina@...gle.com>, Tejun Heo <tj@...nel.org>,
        Zefan Li <lizefan.x@...edance.com>,
        Johannes Weiner <hannes@...xchg.org>,
        Jonathan Corbet <corbet@....net>,
        Andrew Morton <akpm@...ux-foundation.org>
Cc:     Shuah Khan <shuah@...nel.org>, Miaohe Lin <linmiaohe@...wei.com>,
        Oscar Salvador <osalvador@...e.de>,
        Michal Hocko <mhocko@...e.com>,
        Muchun Song <songmuchun@...edance.com>,
        David Rientjes <rientjes@...gle.com>,
        Shakeel Butt <shakeelb@...gle.com>, Jue Wang <juew@...gle.com>,
        Yang Yao <ygyao@...gle.com>, Joanna Li <joannali@...gle.com>,
        Cannon Matthews <cannonmatthews@...gle.com>,
        linux-mm@...ck.org, linux-kernel@...r.kernel.org,
        cgroups@...r.kernel.org, linux-doc@...r.kernel.org
Subject: Re: [PATCH v7] hugetlb: Add hugetlb.*.numa_stat file

On 11/17/21 12:18, Mina Almasry wrote:
...
> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
...
> @@ -288,11 +317,21 @@ static void __hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
>  					   struct hugetlb_cgroup *h_cg,
>  					   struct page *page, bool rsvd)
>  {
> +	unsigned long *usage;
> +

I assume the use of a pointer is just to make the following WRITE_ONCE
look better?  I prefer the suggestion by Muchun:

unsigned long usage = h_cg->nodeinfo[page_to_nid(page)]->usage[idx];

usage += nr_pages;
WRITE_ONCE(h_cg->nodeinfo[page_to_nid(page)]->usage[idx], usage);

I had to think for just a second 'why are we using/passing a pointer?'.
Not insisting we use Muchun's suggestion, it just caused me to think
a little more than necessary.

In any case, I would move the variable usage inside the
'if (!rsvd)' block.

>  	if (hugetlb_cgroup_disabled() || !h_cg)
>  		return;
> 
>  	__set_hugetlb_cgroup(page, h_cg, rsvd);
> -	return;
> +	if (!rsvd) {
> +		usage = &h_cg->nodeinfo[page_to_nid(page)]->usage[idx];
> +		/*
> +		 * This write is not atomic due to fetching *usage and writing
> +		 * to it, but that's fine because we call this with
> +		 * hugetlb_lock held anyway.
> +		 */
> +		WRITE_ONCE(*usage, *usage + nr_pages);
> +	}
>  }
> 
>  void hugetlb_cgroup_commit_charge(int idx, unsigned long nr_pages,
> @@ -316,6 +355,7 @@ static void __hugetlb_cgroup_uncharge_page(int idx, unsigned long nr_pages,
>  					   struct page *page, bool rsvd)
>  {
>  	struct hugetlb_cgroup *h_cg;
> +	unsigned long *usage;

Same here.

Otherwise, looks good to me.
-- 
Mike Kravetz

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ