From: Ruan Jinjie <ruanjinjie@huawei.com>
To: <linux-mm@kvack.org>, Mike Kravetz <mike.kravetz@oracle.com>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH -next] mm: use helper function put_resv_map()
Date: Thu, 3 Aug 2023 20:03:12 +0800 [thread overview]
Message-ID: <20230803120312.945774-1-ruanjinjie@huawei.com> (raw)
This code is already duplicated 3 times, use helper function
put_resv_map() to release reserved and allocated regions instead of
open code it to help improve code readability a bit.
No functional change involved.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
mm/hugetlb.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e327a5a7602c..bf1c900b753b 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1100,6 +1100,11 @@ void resv_map_release(struct kref *ref)
kfree(resv_map);
}
+static inline int put_resv_map(struct resv_map *resv)
+{
+ return kref_put(&resv->refs, resv_map_release);
+}
+
static inline struct resv_map *inode_resv_map(struct inode *inode)
{
/*
@@ -1201,7 +1206,7 @@ void clear_vma_resv_huge_pages(struct vm_area_struct *vma)
if (reservations && is_vma_resv_set(vma, HPAGE_RESV_OWNER)) {
resv_map_put_hugetlb_cgroup_uncharge_info(reservations);
- kref_put(&reservations->refs, resv_map_release);
+ put_resv_map(reservations);
}
hugetlb_dup_vma_private(vma);
@@ -4905,7 +4910,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
hugetlb_acct_memory(h, -gbl_reserve);
}
- kref_put(&resv->refs, resv_map_release);
+ put_resv_map(resv);
}
static int hugetlb_vm_op_split(struct vm_area_struct *vma, unsigned long addr)
@@ -6850,7 +6855,7 @@ bool hugetlb_reserve_pages(struct inode *inode,
if (chg >= 0 && add < 0)
region_abort(resv_map, from, to, regions_needed);
if (vma && is_vma_resv_set(vma, HPAGE_RESV_OWNER))
- kref_put(&resv_map->refs, resv_map_release);
+ put_resv_map(resv_map);
return false;
}
--
2.34.1
next reply other threads:[~2023-08-03 12:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 12:03 Ruan Jinjie [this message]
2023-08-03 12:31 ` Matthew Wilcox
2023-08-03 13:06 ` David Hildenbrand
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=20230803120312.945774-1-ruanjinjie@huawei.com \
--to=ruanjinjie@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
/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