lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220922021929.98961-1-xhao@linux.alibaba.com>
Date:   Thu, 22 Sep 2022 10:19:29 +0800
From:   Xin Hao <xhao@...ux.alibaba.com>
To:     mike.kravetz@...cle.com
Cc:     akpm@...ux-foundation.org, songmuchun@...edance.com,
        linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: [PATCH v5] mm/hugetlb: add available_huge_pages() func

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 <xhao@...ux.alibaba.com>
Reviewed-by: Mike Kravetz <mike.kravetz@...cle.com>
Reviewed-by: Muchun Song <songmuchun@...edance.com>
Reviewed-by: David Hildenbrand <david@...hat.com>
Reviewed-by: Oscar Salvador <osalvador@...e.de>
---
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 <mike.kravetz@...cle.com>

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 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);
--
2.31.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ