diff mbox series

[-next] mm: use helper function put_resv_map()

Message ID 20230803120312.945774-1-ruanjinjie@huawei.com (mailing list archive)
State New
Headers show
Series [-next] mm: use helper function put_resv_map() | expand

Commit Message

Jinjie Ruan Aug. 3, 2023, 12:03 p.m. UTC
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(-)

Comments

Matthew Wilcox Aug. 3, 2023, 12:31 p.m. UTC | #1
On Thu, Aug 03, 2023 at 08:03:12PM +0800, Ruan Jinjie wrote:
> 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.

I do not think this is an improvement.
David Hildenbrand Aug. 3, 2023, 1:06 p.m. UTC | #2
On 03.08.23 14:31, Matthew Wilcox wrote:
> On Thu, Aug 03, 2023 at 08:03:12PM +0800, Ruan Jinjie wrote:
>> 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.
> 
> I do not think this is an improvement.

Agreed.
diff mbox series

Patch

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;
 }