linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sidhartha Kumar <sidhartha.kumar@oracle.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, songmuchun@bytedance.com,
	mike.kravetz@oracle.com, willy@infradead.org,
	Sidhartha Kumar <sidhartha.kumar@oracle.com>
Subject: [RFC PATCH 4/4] mm/hugetlb: add hpage_shift to alloc_hugetlb_folio
Date: Thu, 13 Apr 2023 16:14:52 -0700	[thread overview]
Message-ID: <20230413231452.84529-5-sidhartha.kumar@oracle.com> (raw)
In-Reply-To: <20230413231452.84529-1-sidhartha.kumar@oracle.com>

adjust the return value of hugepage_subpool_{put,get}_pages() by
hpage_shift to be consistent with previous values.

Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
 mm/hugetlb.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index a28fbdff886ff..258c211020c3a 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2992,6 +2992,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
 {
 	struct hugepage_subpool *spool = subpool_vma(vma);
 	struct hstate *h = hstate_vma(vma);
+	unsigned long hpage_shift = huge_page_shift(h);
 	struct folio *folio;
 	long map_chg, map_commit;
 	long gbl_chg;
@@ -3017,7 +3018,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
 	 * checked against any subpool limit.
 	 */
 	if (map_chg || avoid_reserve) {
-		gbl_chg = hugepage_subpool_get_pages(spool, 1);
+		gbl_chg = hugepage_subpool_get_pages(spool, 1) >> hpage_shift;
 		if (gbl_chg < 0) {
 			vma_end_reservation(h, vma, addr);
 			return ERR_PTR(-ENOSPC);
@@ -4778,6 +4779,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
 {
 	struct hstate *h = hstate_vma(vma);
 	unsigned int order = huge_page_order(h);
+	unsigned long hpage_shift = huge_page_shift(h);
 	struct resv_map *resv;
 	struct hugepage_subpool *spool = subpool_vma(vma);
 	unsigned long reserve, start, end;
@@ -4799,7 +4801,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
 		 * Decrement reserve counts.  The global reserve count may be
 		 * adjusted if the subpool has a minimum size.
 		 */
-		gbl_reserve = hugepage_subpool_put_pages(spool, reserve);
+		gbl_reserve = hugepage_subpool_put_pages(spool, reserve) >> hpage_shift;
 		hugetlb_acct_memory(h, -gbl_reserve);
 	}
 
@@ -6871,7 +6873,7 @@ bool hugetlb_reserve_pages(struct inode *inode,
 				(chg - add) * pages_per_huge_page(h), h_cg);
 
 			rsv_adjust = hugepage_subpool_put_pages(spool,
-								chg - add);
+								chg - add) >> hpage_shift;
 			hugetlb_acct_memory(h, -rsv_adjust);
 		} else if (h_cg) {
 			/*
@@ -6908,6 +6910,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
 								long freed)
 {
 	struct hstate *h = hstate_inode(inode);
+	unsigned long hpage_shift = huge_page_shift(h);
 	struct resv_map *resv_map = inode_resv_map(inode);
 	long chg = 0;
 	struct hugepage_subpool *spool = subpool_inode(inode);
@@ -6939,7 +6942,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
 	 * Note that !resv_map implies freed == 0. So (chg - freed)
 	 * won't go negative.
 	 */
-	gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed));
+	gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed)) >> hpage_shift;
 	hugetlb_acct_memory(h, -gbl_reserve);
 
 	return 0;
-- 
2.39.2



  parent reply	other threads:[~2023-04-13 23:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 23:14 [RFC PATCH 0/4] change ->index to PAGE_SIZE for hugetlb pages Sidhartha Kumar
2023-04-13 23:14 ` [RFC PATCH 1/4] mm/filemap: remove hugetlb special casing in filemap.c Sidhartha Kumar
2023-04-13 23:14 ` [RFC PATCH 2/4] mm/hugetlb: remove hugetlb_basepage_index() Sidhartha Kumar
2023-04-13 23:14 ` [RFC PATCH 3/4] mm/hugetlbfs: remove huge_page_shift in hugetlbfs_file_mmap Sidhartha Kumar
2023-04-13 23:14 ` Sidhartha Kumar [this message]
2023-04-25  1:27 ` [RFC PATCH 0/4] change ->index to PAGE_SIZE for hugetlb pages Mike Kravetz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230413231452.84529-5-sidhartha.kumar@oracle.com \
    --to=sidhartha.kumar@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=songmuchun@bytedance.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox