From: Andrew Morton <akpm@linux-foundation.org>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: David Rientjes <rientjes@google.com>,
Jing Xiangfeng <jingxiangfeng@huawei.com>,
mhocko@kernel.org, hughd@google.com, linux-mm@kvack.org,
n-horiguchi@ah.jp.nec.com, Andrea Arcangeli <aarcange@redhat.com>,
kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] mm/hugetlb: Fix unsigned overflow in __nr_hugepages_store_common()
Date: Tue, 26 Feb 2019 14:36:20 -0800 [thread overview]
Message-ID: <20190226143620.c6af15c7c897d3362b191e36@linux-foundation.org> (raw)
In-Reply-To: <e2bded2f-40ca-c308-5525-0a21777ed221@oracle.com>
>
> The number of node specific huge pages can be set via a file such as:
> /sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages
> When a node specific value is specified, the global number of huge
> pages must also be adjusted. This adjustment is calculated as the
> specified node specific value + (global value - current node value).
> If the node specific value provided by the user is large enough, this
> calculation could overflow an unsigned long leading to a smaller
> than expected number of huge pages.
>
> To fix, check the calculation for overflow. If overflow is detected,
> use ULONG_MAX as the requested value. This is inline with the user
> request to allocate as many huge pages as possible.
>
> It was also noticed that the above calculation was done outside the
> hugetlb_lock. Therefore, the values could be inconsistent and result
> in underflow. To fix, the calculation is moved to within the routine
> set_max_huge_pages() where the lock is held.
>
> ...
>
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2274,7 +2274,7 @@ static int adjust_pool_surplus(struct hstate *h,
> nodemask_t *nodes_allowed,
Please tweak that email client to prevent the wordwraps.
> + /*
> + * Check for a node specific request. Adjust global count, but
> + * restrict alloc/free to the specified node.
> + */
> + if (nid != NUMA_NO_NODE) {
> + unsigned long old_count = count;
> + count += h->nr_huge_pages - h->nr_huge_pages_node[nid];
> + /*
> + * If user specified count causes overflow, set to
> + * largest possible value.
> + */
> + if (count < old_count)
> + count = ULONG_MAX;
> + }
The above two comments explain the code, but do not reveal the
reasoning behind the policy decisions which that code implements.
> ...
>
> + } else {
> /*
> - * per node hstate attribute: adjust count to global,
> - * but restrict alloc/free to the specified node.
> + * Node specific request, but we could not allocate
> + * node mask. Pass in ALL nodes, and clear nid.
> */
Ditto here, somewhat.
The old mantra: comments should explain "why", not "what". Reading the
code tells us the "what".
Thanks.
next prev parent reply other threads:[~2019-02-26 22:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-23 1:32 Jing Xiangfeng
2019-02-25 0:45 ` Mike Kravetz
2019-02-25 3:17 ` David Rientjes
2019-02-25 16:49 ` Mike Kravetz
2019-02-25 18:19 ` Mike Kravetz
2019-02-25 19:17 ` David Rientjes
2019-02-26 2:22 ` Jing Xiangfeng
2019-02-26 6:21 ` David Rientjes
2019-02-26 19:32 ` Mike Kravetz
2019-02-26 22:36 ` Andrew Morton [this message]
2019-02-27 0:03 ` Mike Kravetz
2019-03-04 13:48 ` Oscar Salvador
2019-03-05 0:03 ` Naoya Horiguchi
2019-03-05 4:15 ` Mike Kravetz
2019-03-05 21:16 ` Andrew Morton
2019-03-05 21:35 ` Mike Kravetz
2019-03-05 21:41 ` Alex Ghiti
2019-03-06 9:41 ` Oscar Salvador
2019-03-07 0:17 ` Mike Kravetz
2019-03-04 6:00 ` Naoya Horiguchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190226143620.c6af15c7c897d3362b191e36@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aarcange@redhat.com \
--cc=hughd@google.com \
--cc=jingxiangfeng@huawei.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mike.kravetz@oracle.com \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox