From: Mike Kravetz <mike.kravetz@oracle.com>
To: Miaohe Lin <linmiaohe@huawei.com>, akpm@linux-foundation.org
Cc: n-horiguchi@ah.jp.nec.com, hillf.zj@alibaba-inc.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory()
Date: Tue, 6 Apr 2021 19:49:58 -0700 [thread overview]
Message-ID: <20afccd5-2bc4-9db9-695e-dd6175b0b42b@oracle.com> (raw)
In-Reply-To: <20210402093249.25137-4-linmiaohe@huawei.com>
On 4/2/21 2:32 AM, Miaohe Lin wrote:
> The resv_map could be NULL since this routine can be called in the evict
> inode path for all hugetlbfs inodes. So we could have chg = 0 and this
> would result in a negative value when chg - freed. This is unexpected for
> hugepage_subpool_put_pages() and hugetlb_acct_memory().
I am not sure if this is possible.
It is true that resv_map could be NULL. However, I believe resv map
can only be NULL for inodes that are not regular or link inodes. This
is the inode creation code in hugetlbfs_get_inode().
/*
* Reserve maps are only needed for inodes that can have associated
* page allocations.
*/
if (S_ISREG(mode) || S_ISLNK(mode)) {
resv_map = resv_map_alloc();
if (!resv_map)
return NULL;
}
If resv_map is NULL, then no hugetlb pages can be allocated/associated
with the file. As a result, remove_inode_hugepages will never find any
huge pages associated with the inode and the passed value 'freed' will
always be zero.
Does that sound correct?
--
Mike Kravetz
>
> Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages")
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
> mm/hugetlb.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index b7864abded3d..bdff8d23803f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5413,6 +5413,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
> long chg = 0;
> struct hugepage_subpool *spool = subpool_inode(inode);
> long gbl_reserve;
> + long delta;
>
> /*
> * Since this routine can be called in the evict inode path for all
> @@ -5437,7 +5438,8 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
> * If the subpool has a minimum size, the number of global
> * reservations to be released may be adjusted.
> */
> - gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed));
> + delta = chg > 0 ? chg - freed : freed;
> + gbl_reserve = hugepage_subpool_put_pages(spool, delta);
> hugetlb_acct_memory(h, -gbl_reserve);
>
> return 0;
>
next prev parent reply other threads:[~2021-04-07 2:50 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-02 9:32 [PATCH 0/4] Cleanup and fixup for hugetlb Miaohe Lin
2021-04-02 9:32 ` [PATCH 1/4] mm/hugeltb: remove redundant VM_BUG_ON() in region_add() Miaohe Lin
2021-04-07 0:16 ` Mike Kravetz
2021-04-02 9:32 ` [PATCH 2/4] mm/hugeltb: simplify the return code of __vma_reservation_common() Miaohe Lin
2021-04-07 0:53 ` Mike Kravetz
2021-04-07 2:05 ` Miaohe Lin
2021-04-07 2:37 ` Mike Kravetz
2021-04-07 3:09 ` Miaohe Lin
2021-04-07 21:23 ` Mike Kravetz
2021-04-08 2:44 ` Miaohe Lin
2021-04-08 22:40 ` Mike Kravetz
2021-04-09 2:52 ` Miaohe Lin
2021-04-02 9:32 ` [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory() Miaohe Lin
2021-04-07 2:49 ` Mike Kravetz [this message]
2021-04-07 7:24 ` Miaohe Lin
2021-04-07 20:53 ` Mike Kravetz
2021-04-08 3:24 ` Miaohe Lin
2021-04-08 3:26 ` Miaohe Lin
2021-04-08 22:53 ` Mike Kravetz
2021-04-09 3:01 ` Miaohe Lin
2021-04-09 4:37 ` Mike Kravetz
2021-04-09 6:36 ` Miaohe Lin
2021-04-02 9:32 ` [PATCH 4/4] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Miaohe Lin
2021-04-08 23:25 ` Mike Kravetz
2021-04-09 3:17 ` Miaohe Lin
2021-04-09 5:04 ` Andrew Morton
2021-04-09 7:07 ` Miaohe Lin
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=20afccd5-2bc4-9db9-695e-dd6175b0b42b@oracle.com \
--to=mike.kravetz@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=hillf.zj@alibaba-inc.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=n-horiguchi@ah.jp.nec.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;
as well as URLs for NNTP newsgroup(s).