From patchwork Thu Sep 22 02:19:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12984372 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 EA24DECAAD8 for ; Thu, 22 Sep 2022 02:19:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EF9E6B0073; Wed, 21 Sep 2022 22:19:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 19EEC940007; Wed, 21 Sep 2022 22:19:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08F2E6B0075; Wed, 21 Sep 2022 22:19:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EEF516B0073 for ; Wed, 21 Sep 2022 22:19:38 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CA8671A131D for ; Thu, 22 Sep 2022 02:19:38 +0000 (UTC) X-FDA: 79938115236.24.AFFFCA9 Received: from out199-13.us.a.mail.aliyun.com (out199-13.us.a.mail.aliyun.com [47.90.199.13]) by imf05.hostedemail.com (Postfix) with ESMTP id 1239C100005 for ; Thu, 22 Sep 2022 02:19:36 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R481e4;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=5;SR=0;TI=SMTPD_---0VQQFgdF_1663813171; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VQQFgdF_1663813171) by smtp.aliyun-inc.com; Thu, 22 Sep 2022 10:19:32 +0800 From: Xin Hao To: mike.kravetz@oracle.com Cc: akpm@linux-foundation.org, songmuchun@bytedance.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5] mm/hugetlb: add available_huge_pages() func Date: Thu, 22 Sep 2022 10:19:29 +0800 Message-Id: <20220922021929.98961-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663813178; a=rsa-sha256; cv=none; b=7IRLwFhLO6rp0adNj8fiFM3/u2SkkOlHFBLxzM3SM/IPgSNsiXn2tIllszcWN5LTSgjmDs G6fqBrr0CxZwHNaQjDlnyny+5a99lzRb1hgx3BXaLumwi+wSG1XqNYZjdv+uLH8AJ2qA8D WMUBY+58XElxk/QKsLHe0H3/Yde+fkU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of xhao@linux.alibaba.com designates 47.90.199.13 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663813178; 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=mvuhgGygu4UB69P5O3+/pr/Ns6x0pXkCqnNIVd0h+c8=; b=moFfyzVgvLyjAtLr12sr4SqpG0iRkF/PbW/6Ffw7pEGFG0n8bEGZvDAI+IYyV7OxIHGfp6 ZNx4ebq+thk84uBfLnWtE/4gt6vKfENXUQR6RSVfMmvPH/k1cSl5hYPFqPR2hd4uhmJF3b CIwwffNhIErjCXK2qkCAlxUcb/pokpc= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1239C100005 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of xhao@linux.alibaba.com designates 47.90.199.13 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Stat-Signature: 5oabo1oibk46p13uo4a517tooyhssuin X-HE-Tag: 1663813176-980145 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 available_huge_pages() func to do these. Signed-off-by: Xin Hao Reviewed-by: Mike Kravetz Reviewed-by: Muchun Song Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador --- Changes from v4 (https://lore.kernel.org/lkml/20220920015122.68064-1-xhao@linux.alibaba.com/) - Add Reviewed-by other reviewers. Changes from v3 (https://lore.kernel.org/lkml/20220917011528.11331-1-xhao@linux.alibaba.com/) - add Reviewed-by Mike Kravetz 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(-) -- 2.31.0 diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9b8526d27c29..99dc961d131a 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); @@ -2124,7 +2128,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; /* @@ -2311,7 +2315,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);