From patchwork Fri Sep 16 06:35:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12978185 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 5153CC54EE9 for ; Fri, 16 Sep 2022 06:36:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 538F78D0002; Fri, 16 Sep 2022 02:36:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E8E58D0001; Fri, 16 Sep 2022 02:36:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E59E8D0002; Fri, 16 Sep 2022 02:36:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2D6D48D0001 for ; Fri, 16 Sep 2022 02:36:00 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 094DCA483F for ; Fri, 16 Sep 2022 06:36:00 +0000 (UTC) X-FDA: 79916988480.28.ED91707 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf05.hostedemail.com (Postfix) with ESMTP id 92CF01000B1 for ; Fri, 16 Sep 2022 06:35:58 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VPvv1h1_1663310153; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPvv1h1_1663310153) by smtp.aliyun-inc.com; Fri, 16 Sep 2022 14:35:54 +0800 From: Xin Hao To: mike.kravetz@oracle.com Cc: songmuchun@bytedance.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xhao@linux.alibaba.com Subject: [PATCH] mm/hugetlb: add mis_resv_equal_free() func Date: Fri, 16 Sep 2022 14:35:50 +0800 Message-Id: <20220916063550.1650-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663310159; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=qhPD+wruNRWCHhQaHsTC3YqhL5C4RQhTRYqj+tz0MdU=; b=Xv7jUl9ycI+jmfGOVLKRyxMoQMT2Ml1rkYFDnCr4A8OTpF5My/mw9OiWxDTcBarcJZyiED tLCTkxWQZquCQztO0zXpmTwjYoqeqVBM29JYiBdyfGg8XiT/bIOz2IEL0KVu+gPXIywXGJ MExEX2hZG0Gz3gMbP0dBW6JK9YEA/0A= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663310159; a=rsa-sha256; cv=none; b=gpmBIcwsnnSjZ2G1PbpjjhZPdV+LgSkVQUflTtlAGKwmuCIwGYAX+e6g2oXdkH1Owkwzwl kxlSL0M9VsBBKIbxUi+09FKcOfX75A2pYvBRRvi5qguP8M+ju6p8GPDlgsUfdnw59KwzBZ 0qpYyjj+GtRnA63arVwbAq1HOXQgrpY= X-Stat-Signature: w9aszf1ajdo8ue59pinq63duntoigfeh X-Rspamd-Queue-Id: 92CF01000B1 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspamd-Server: rspam06 X-HE-Tag: 1663310158-918797 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: In hugetlb.c file, there are several places to compare the values of 'h->free_huge_pages' and 'h->resv_huge_pages', it looks a bit messy, so there add a new mis_resv_equal_free() func to do these. Signed-off-by: Xin Hao --- mm/hugetlb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 66496fc424f4..db6f63fb083f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1191,6 +1191,11 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, return NULL; } +static inline bool is_resv_equal_free(struct hstate *h) +{ + return (h->free_huge_pages - h->resv_huge_pages == 0) ? true : false; +} + static struct page *dequeue_huge_page_vma(struct hstate *h, struct vm_area_struct *vma, unsigned long address, int avoid_reserve, @@ -1207,12 +1212,11 @@ static struct page *dequeue_huge_page_vma(struct hstate *h, * have no page reserves. This check ensures that reservations are * not "stolen". The child may still get SIGKILLed */ - if (!vma_has_reserves(vma, chg) && - h->free_huge_pages - h->resv_huge_pages == 0) + if (!vma_has_reserves(vma, chg) && is_resv_equal_free(h)) goto err; /* If reserves cannot be used, ensure enough pages are in the pool */ - if (avoid_reserve && h->free_huge_pages - h->resv_huge_pages == 0) + if (avoid_reserve && is_resv_equal_free(h)) goto err; gfp_mask = htlb_alloc_mask(h); @@ -2105,7 +2109,7 @@ int dissolve_free_huge_page(struct page *page) if (!page_count(page)) { struct page *head = compound_head(page); struct hstate *h = page_hstate(head); - if (h->free_huge_pages - h->resv_huge_pages == 0) + if (is_resv_equal_free(h)) goto out; /* @@ -2315,7 +2319,7 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask) { spin_lock_irq(&hugetlb_lock); - if (h->free_huge_pages - h->resv_huge_pages > 0) { + if (!is_resv_equal_free(h)) { struct page *page; page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask);