From patchwork Sat Sep 17 01:15:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12978947 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 9261EECAAD8 for ; Sat, 17 Sep 2022 01:15:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88B318D0002; Fri, 16 Sep 2022 21:15:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83A7A8D0001; Fri, 16 Sep 2022 21:15:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 703C58D0002; Fri, 16 Sep 2022 21:15:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 615AD8D0001 for ; Fri, 16 Sep 2022 21:15:38 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 22DF01205C6 for ; Sat, 17 Sep 2022 01:15:38 +0000 (UTC) X-FDA: 79919809956.29.2F74FC6 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by imf23.hostedemail.com (Postfix) with ESMTP id 1B8401400C3 for ; Sat, 17 Sep 2022 01:15:35 +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=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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663377337; 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=TRz/Gof7wIDQP18dvNu4dhTdoA38cxv9jmefyMnnc8w=; b=7mhrTao9zhL/7kiCGBYJgthP4cx2fzFZpwbmzFHkN2abKh3REA4XM0r5ErY2gY1/lK+Cis favEUkDsttbDiX+aKGYoeN07ig3zjJT7P6vUtbMoPuPwXWPgY/bpOiaLgL/51slCuADP2P OL1RjOlMO1fEZsiJEPizrUwYpZJqb00= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf23.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.57 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663377337; a=rsa-sha256; cv=none; b=jr1xvW+8TMUyl7jNxsB8gOGfbMEEhzRBa0eOkPUYbkT/OjKEBXdWhgj0QvO9wnG2iA1EJU 0fQJmEhaIsUzweXfpBbcpD5DxcpbKkPDVqRpQk3aJqNPDJLlkTuq/Er/vMY9PrDkKpul2k Z63+ci3vZkEgU6nOVLBbQMMyxtcU2nE= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1B8401400C3 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf23.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.57 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-Stat-Signature: u4azy5yeap5g17o4w6ogykuphiyzofyj X-HE-Tag: 1663377335-83621 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 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() Reviewed-by: Mike Kravetz Reviewed-by: Oscar Salvador --- 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 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);