Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1770527rwn; Thu, 15 Sep 2022 23:54:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7C9kKksf/gUn8/saPs76+y1EPdKNURzlG/idwIwdsUjbC/UClYZOCD0f1L/0mu9sS7xtPK X-Received: by 2002:a17:907:2721:b0:77c:29f9:2c84 with SMTP id d1-20020a170907272100b0077c29f92c84mr2503589ejl.721.1663311254591; Thu, 15 Sep 2022 23:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663311254; cv=none; d=google.com; s=arc-20160816; b=sEjbTingVH537x5nGvEN+/k83bZifP0D/tddEuKVkZ9ndqL6MSzocoUCpyINknPL6g BiXMdetetj0uHQ4K/OaRfPhf6C6Mlwt/VuDXFdwM3ptiQO2myaITS/PgEbARZC2ZjLFx 3LWtJdnE0CXHtENRMBcx5uPNYE3g8U5HEUKiMycCENYIzf2tAFNiRRrw83/4TG/+yPpq 2mFwHHR4b8E69OQTtps6mQk1Ydme594gPXd3Z+f45rIC/FaSuDHyxBrZgL6avCh48WA+ mzL/p6mMP4ryIa459lQxSBbyR85hZfWjspRGvYNAIKPi1sjQMSX2Tg4EgA+XV2ZH2F9h Cs1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6ys/52TMELaUDba43GN2RxE3SKBGv06Yhpeg8L+nh3E=; b=XLj4KGBsPrFC1WAKPyxDI4Y+7lPsGgUVFLHfdLqzBBn5HWGt64mTG2JAas0rMhJ5HH Z4GHRkMcCWQGLgKjrxj4YNQ1c+z9eLFQG1lpL32ERrjhPLMYOpvSBCXkdeT2KBJp8X6H ZPhBGjH5JwYUktHR6tvUurRHHKNBTUTY/IVMb9o8qFPa7B24918az4+kbZa7YqYX3uKR xU/Ix1SEOUSjYwy9UuVNJ9Cbqn8d6+Xu/EbCjM26iHHZgswJ8CZEJYuz90NQPD7P/+N0 lojQxve54sqqhKTez0wq/5Bzgu9nLT5aDO2QtTK2VH2PfGKOLdvv3YAt2u/D4/k89njf ILNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020a05640240c300b0044699451386si1805614edb.9.2022.09.15.23.53.48; Thu, 15 Sep 2022 23:54:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbiIPGlg (ORCPT + 99 others); Fri, 16 Sep 2022 02:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbiIPGle (ORCPT ); Fri, 16 Sep 2022 02:41:34 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1404A2AB9 for ; Thu, 15 Sep 2022 23:41:32 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R691e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VPw-i6g_1663310489; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPw-i6g_1663310489) by smtp.aliyun-inc.com; Fri, 16 Sep 2022 14:41:30 +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 V2] mm/hugetlb: add is_resv_equal_free() func Date: Fri, 16 Sep 2022 14:41:27 +0800 Message-Id: <20220916064127.1904-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 is_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); -- 2.31.0