From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 556E7C433ED for ; Fri, 9 Apr 2021 03:17:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EA04A610FC for ; Fri, 9 Apr 2021 03:17:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA04A610FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 63CE66B006C; Thu, 8 Apr 2021 23:17:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 625106B006E; Thu, 8 Apr 2021 23:17:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5006B6B0070; Thu, 8 Apr 2021 23:17:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 371256B006C for ; Thu, 8 Apr 2021 23:17:58 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E54E281F6 for ; Fri, 9 Apr 2021 03:17:57 +0000 (UTC) X-FDA: 78011369394.39.22BB46C Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf04.hostedemail.com (Postfix) with ESMTP id 902DF132 for ; Fri, 9 Apr 2021 03:17:55 +0000 (UTC) Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FGjtK2qtvznZ6Q; Fri, 9 Apr 2021 11:15:05 +0800 (CST) Received: from [10.174.179.9] (10.174.179.9) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Fri, 9 Apr 2021 11:17:49 +0800 Subject: Re: [PATCH 4/4] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() To: Mike Kravetz , CC: , , , References: <20210402093249.25137-1-linmiaohe@huawei.com> <20210402093249.25137-5-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: Date: Fri, 9 Apr 2021 11:17:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.9] X-CFilter-Loop: Reflected X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 902DF132 X-Stat-Signature: tmgom3prrw3d4x95hinn7efjyc845553 Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=szxga04-in.huawei.com; client-ip=45.249.212.190 X-HE-DKIM-Result: none/none X-HE-Tag: 1617938275-319453 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2021/4/9 7:25, Mike Kravetz wrote: > On 4/2/21 2:32 AM, Miaohe Lin wrote: >> 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. > > Yes, this is a potential issue. > > The 'good news' is that hugetlb_fix_reserve_counts() is unlikely to ever > be called. To do so would imply we could not allocate a region entry > which is only 6 words in size. We also keep a 'cache' of entries so we > may not even need to allocate. > > But, as mentioned it is a potential issue. Yes, a potential *theoretical* issue. > >> Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages") > > This is likely going to make this get picked by by stable releases. > That is unfortunate as mentioned above this is mostly theoretical. > I will drop this. This does not worth backport. >> Signed-off-by: Miaohe Lin >> --- >> mm/hugetlb.c | 11 +++++++++-- >> 1 file changed, 9 insertions(+), 2 deletions(-) >> >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index bdff8d23803f..ca5464ed04b7 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: fix reserve count failed\n"); > > We should expand this warning message a bit to indicate what this may > mean to the user. Add something like" > "Huge Page Reserved count may go negative". > Will add it in v2. Many thanks for review and nice suggestion ! :)