From: Miaohe Lin <linmiaohe@huawei.com>
To: <akpm@linux-foundation.org>, <mike.kravetz@oracle.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<linmiaohe@huawei.com>, <linfeilong@huawei.com>
Subject: [PATCH v2 4/5] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts()
Date: Sat, 10 Apr 2021 03:23:47 -0400 [thread overview]
Message-ID: <20210410072348.20437-5-linmiaohe@huawei.com> (raw)
In-Reply-To: <20210410072348.20437-1-linmiaohe@huawei.com>
A rare out of memory error would prevent removal of the reserve map region
for a page. hugetlb_fix_reserve_counts() handles this rare case to avoid
dangling with incorrect counts. Unfortunately, hugepage_subpool_get_pages
and hugetlb_acct_memory could possibly fail too. We should correctly handle
these cases.
Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/hugetlb.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 387c9a62615e..a14bb1a03ee4 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -745,13 +745,20 @@ void hugetlb_fix_reserve_counts(struct inode *inode)
{
struct hugepage_subpool *spool = subpool_inode(inode);
long rsv_adjust;
+ bool reserved = false;
rsv_adjust = hugepage_subpool_get_pages(spool, 1);
- if (rsv_adjust) {
+ if (rsv_adjust > 0) {
struct hstate *h = hstate_inode(inode);
- hugetlb_acct_memory(h, 1);
+ if (!hugetlb_acct_memory(h, 1))
+ reserved = true;
+ } else if (!rsv_adjust) {
+ reserved = true;
}
+
+ if (!reserved)
+ pr_warn("hugetlb: Huge Page Reserved count may go negative.\n");
}
/*
--
2.19.1
next prev parent reply other threads:[~2021-04-10 7:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-10 7:23 [PATCH v2 0/5] Cleanup and fixup for hugetlb Miaohe Lin
2021-04-10 7:23 ` [PATCH v2 1/5] mm/hugeltb: remove redundant VM_BUG_ON() in region_add() Miaohe Lin
2021-04-10 7:23 ` [PATCH v2 2/5] mm/hugeltb: simplify the return code of __vma_reservation_common() Miaohe Lin
2021-04-12 18:26 ` Mike Kravetz
2021-04-10 7:23 ` [PATCH v2 3/5] mm/hugeltb: clarify (chg - freed) won't go negative in hugetlb_unreserve_pages() Miaohe Lin
2021-04-12 18:28 ` Mike Kravetz
2021-04-10 7:23 ` Miaohe Lin [this message]
2021-04-12 18:30 ` [PATCH v2 4/5] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Mike Kravetz
2021-04-10 7:23 ` [PATCH v2 5/5] mm/hugetlb: remove unused variable pseudo_vma in remove_inode_hugepages() Miaohe Lin
2021-04-12 18:51 ` Mike Kravetz
2021-04-13 2:22 ` 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=20210410072348.20437-5-linmiaohe@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=linfeilong@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.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
all inboxes | Powered by JetHome®