@@ -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;
}
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(-)