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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C943AC25B0E for ; Wed, 17 Aug 2022 02:00:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 501C16B0073; Tue, 16 Aug 2022 22:00:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B06A6B0074; Tue, 16 Aug 2022 22:00:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 378D88D0001; Tue, 16 Aug 2022 22:00:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 255356B0073 for ; Tue, 16 Aug 2022 22:00:03 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F37DC1A072C for ; Wed, 17 Aug 2022 02:00:02 +0000 (UTC) X-FDA: 79807429044.10.2F4D84B Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf24.hostedemail.com (Postfix) with ESMTP id 35CD618007F for ; Wed, 17 Aug 2022 02:00:02 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M6rjg0qlQzlW9P; Wed, 17 Aug 2022 09:56:55 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 17 Aug 2022 09:59:58 +0800 Subject: Re: [PATCH 3/6] mm/hugetlb: fix missing call to restore_reserve_on_error() To: Mike Kravetz CC: , , , References: <20220816130553.31406-1-linmiaohe@huawei.com> <20220816130553.31406-4-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: <14198f4d-f9ff-8e36-d985-3719e365f913@huawei.com> Date: Wed, 17 Aug 2022 09:59:57 +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.177.76] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660701602; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=laduJgfeMCWJqzLWu6RS9TcLX/9giG/ot97PBjrdfGo=; b=C75+/047DSJJ/CwlzLbfQTdpZ4brDfWgTu/JBPd5JmaGmO1kgbYUPDclU+xNI+UD9boHb1 gS/9KonKFRKpwN/aewSkLquum9shEK2Dc9yEKeA244ivmVfHOcREbVG2QB6N4JSV7FpEYo iHgzl4bGPmEBg50aXmhTxp0s44XKumk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660701602; a=rsa-sha256; cv=none; b=cIuaptnjkjRF2fu8IRBBjNtazlZZgPpFCCogTV16D5TuSKfYGc0L+cN04awFi8I3eb0D4I 2ccFwaRCA2wOfjcswOdbdZks9BK+Olo5WTzZ9udwmIxacQmoLpRea83BZUhumqQ3kei3ca jNP2oR2ywfFWzMPxFU2Dn+U9r7Eu3C0= Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-Stat-Signature: tbqqi756af8gyjggygoh74p617u4yxur X-Rspamd-Queue-Id: 35CD618007F X-Rspamd-Server: rspam11 X-HE-Tag: 1660701602-828085 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 2022/8/17 7:31, Mike Kravetz wrote: > On 08/16/22 21:05, Miaohe Lin wrote: >> When huge_add_to_page_cache() fails, the page is freed directly without >> calling restore_reserve_on_error() to restore reserve for newly allocated >> pages not in page cache. Fix this by calling restore_reserve_on_error() >> when huge_add_to_page_cache fails. >> >> Signed-off-by: Miaohe Lin >> --- >> mm/hugetlb.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index ff991e5bdf1f..b69d7808f457 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -5603,6 +5603,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, >> if (vma->vm_flags & VM_MAYSHARE) { >> int err = huge_add_to_page_cache(page, mapping, idx); >> if (err) { >> + restore_reserve_on_error(h, vma, haddr, page); > > Hmmmm. I was going to comment that restore_reserve_on_error would not handle > the situation where 'err == -EEXIST' below. This is because it implies we > raced with someone else that added the page to the cache. And, that other Thanks for pointing this out. > allocation, not this one, consumed the reservation. However, I am not sure > how that could be possible? The hugetlb fault mutex (which we hold) > must be held to add a page to the page cache. > > Searching git history I see that code was added (or at least existed) before > the hugetlb fault mutex was introduced. So, I believe that check for -EEXIST > and retry can go. Agree with you. All call sites of huge_add_to_page_cache is protected by hugetlb fault mutex. > > With that said, restore_reserve_on_error can be called here. But, let's > look into removing that err == -EEXIST check to avoid confusion. Will do it in next version. Many thanks for your review and comment. Thanks, Miaohe Lin