Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp245695rwn; Fri, 16 Sep 2022 19:35:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7mnx4zMhdw8suYxlGWUwK084yHSg3g84Qx5nCpsUTkVlZ+7oJM9SXlULpQKwhfbbynfEmh X-Received: by 2002:a17:907:70b:b0:740:ef93:2ffb with SMTP id xb11-20020a170907070b00b00740ef932ffbmr5330455ejb.93.1663382118884; Fri, 16 Sep 2022 19:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663382118; cv=none; d=google.com; s=arc-20160816; b=WK6OrxqSxik/NWHJmqwDHRElcXftkVDvO1L4WYgdMiJg4Ru7S1UcSesf3X4Uwr71U/ BjaJrpE4UJU/I7Jn3ZakT6rSyKR8i2I9T7f6CxdUSHNuf8hCu5rYcFFISNYC8JbKJ3+N uuIiYJLxNm3ZI4QXs4TZFHXRaIcKYa5CoCWKVh0o64bni24g04ySaSJ1faHQNSesKfG/ 8LfWhtyiCaxXZW73PZ5/UZ0XJVC8SEDeF1wcrkRjDeXZdgLtdOnSAC3+DJ/tDRJhD9Dl My/w9frmCI2/cxFFfWCRgjtM9VH9mg9mtnapvuyKxA3fothKDKjhuxQgP8u7dvQ/lnYQ GbRA== 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=TRz/Gof7wIDQP18dvNu4dhTdoA38cxv9jmefyMnnc8w=; b=dhB9SdC7r6Ep6UWaVE/2K6dZaoHaX54esE5KDCkyCjKDZmbkFN1zG/Qr2XlJpCB2OO TZNSStj867VflDCcLl1d41U/irWaz26TLLemrqsxKZehjZx/LTsu59rR71SshvwrlVLh Ynd+OhXNElfS9Aa0yUb+xNgJTgGe77AkwbKm8ZMiZeSZdxjoGLcxm7aSgh9hH3zhwtDW WIkil6akPzhB43QgR57+cbZcQm2gJuxws5sMwqb2m5TAHo5A1IGKpUfHJSuTXur8AZmp KpTqsN7bvnLGAfaTSZVEGu+wBwGL1aB98V9puiwl0l6K5DjhCrF5P9nVe80tjw0uhWWE 6jCA== 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 p23-20020aa7cc97000000b0045380a5973fsi1408246edt.157.2022.09.16.19.34.53; Fri, 16 Sep 2022 19:35:18 -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 S229458AbiIQBPn (ORCPT + 99 others); Fri, 16 Sep 2022 21:15:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbiIQBPk (ORCPT ); Fri, 16 Sep 2022 21:15:40 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE8521901A for ; Fri, 16 Sep 2022 18:15:34 -0700 (PDT) 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=ay29a033018046059;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VPz2Krd_1663377330; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPz2Krd_1663377330) by smtp.aliyun-inc.com; Sat, 17 Sep 2022 09:15:32 +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 V3] mm/hugetlb: add available_huge_pages() func Date: Sat, 17 Sep 2022 09:15:28 +0800 Message-Id: <20220917011528.11331-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 available_huge_pages() func to do these. Signed-off-by: Xin Hao Changes from v2 https://lore.kernel.org/linux-mm/20220916064127.1904-1-xhao@linux.alibaba.com/ - Convert is_resv_equal_free() to available_huge_pages() --- mm/hugetlb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5ea0b1b0d1ab..21d7f2361696 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 unsigned long available_huge_pages(struct hstate *h) +{ + return h->free_huge_pages - h->resv_huge_pages; +} + 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) && !available_huge_pages(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 && !available_huge_pages(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 (!available_huge_pages(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 (available_huge_pages(h)) { struct page *page; page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask); -- 2.31.0