Message ID | 20200807091251.12129-5-richard.weiyang@linux.alibaba.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mm/hugetlb: code refine and simplification | expand |
On 08/07/20 at 05:12pm, Wei Yang wrote: > There are only two cases of function add_reservation_in_range() > > * count file_region and return the number in regions_needed > * do the real list operation without counting > > This means it is not necessary to have two parameters to classify these > two cases. > > Just use regions_needed to separate them. > > Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com> Nice clean up. Reviewed-by: Baoquan He <bhe@redhat.com> > --- > mm/hugetlb.c | 33 +++++++++++++++++---------------- > 1 file changed, 17 insertions(+), 16 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 929256c130f9..d775e514eb2e 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -321,16 +321,17 @@ static void coalesce_file_region(struct resv_map *resv, struct file_region *rg) > } > } > > -/* Must be called with resv->lock held. Calling this with count_only == true > - * will count the number of pages to be added but will not modify the linked > - * list. If regions_needed != NULL and count_only == true, then regions_needed > - * will indicate the number of file_regions needed in the cache to carry out to > - * add the regions for this range. > +/* > + * Must be called with resv->lock held. > + * > + * Calling this with regions_needed != NULL will count the number of pages > + * to be added but will not modify the linked list. And regions_needed will > + * indicate the number of file_regions needed in the cache to carry out to add > + * the regions for this range. > */ > static long add_reservation_in_range(struct resv_map *resv, long f, long t, > struct hugetlb_cgroup *h_cg, > - struct hstate *h, long *regions_needed, > - bool count_only) > + struct hstate *h, long *regions_needed) > { > long add = 0; > struct list_head *head = &resv->regions; > @@ -366,14 +367,14 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, > */ > if (rg->from > last_accounted_offset) { > add += rg->from - last_accounted_offset; > - if (!count_only) { > + if (!regions_needed) { > nrg = get_file_region_entry_from_cache( > resv, last_accounted_offset, rg->from); > record_hugetlb_cgroup_uncharge_info(h_cg, h, > resv, nrg); > list_add(&nrg->link, rg->link.prev); > coalesce_file_region(resv, nrg); > - } else if (regions_needed) > + } else > *regions_needed += 1; > } > > @@ -385,13 +386,13 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, > */ > if (last_accounted_offset < t) { > add += t - last_accounted_offset; > - if (!count_only) { > + if (!regions_needed) { > nrg = get_file_region_entry_from_cache( > resv, last_accounted_offset, t); > record_hugetlb_cgroup_uncharge_info(h_cg, h, resv, nrg); > list_add(&nrg->link, rg->link.prev); > coalesce_file_region(resv, nrg); > - } else if (regions_needed) > + } else > *regions_needed += 1; > } > > @@ -484,8 +485,8 @@ static long region_add(struct resv_map *resv, long f, long t, > retry: > > /* Count how many regions are actually needed to execute this add. */ > - add_reservation_in_range(resv, f, t, NULL, NULL, &actual_regions_needed, > - true); > + add_reservation_in_range(resv, f, t, NULL, NULL, > + &actual_regions_needed); > > /* > * Check for sufficient descriptors in the cache to accommodate > @@ -513,7 +514,7 @@ static long region_add(struct resv_map *resv, long f, long t, > goto retry; > } > > - add = add_reservation_in_range(resv, f, t, h_cg, h, NULL, false); > + add = add_reservation_in_range(resv, f, t, h_cg, h, NULL); > > resv->adds_in_progress -= in_regions_needed; > > @@ -549,9 +550,9 @@ static long region_chg(struct resv_map *resv, long f, long t, > > spin_lock(&resv->lock); > > - /* Count how many hugepages in this range are NOT respresented. */ > + /* Count how many hugepages in this range are NOT represented. */ > chg = add_reservation_in_range(resv, f, t, NULL, NULL, > - out_regions_needed, true); > + out_regions_needed); > > if (*out_regions_needed == 0) > *out_regions_needed = 1; > -- > 2.20.1 (Apple Git-117) > >
On 8/7/20 2:12 AM, Wei Yang wrote: > There are only two cases of function add_reservation_in_range() > > * count file_region and return the number in regions_needed > * do the real list operation without counting > > This means it is not necessary to have two parameters to classify these > two cases. > > Just use regions_needed to separate them. > > Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com> Thanks! I really like removal of the 'count_only' parameter. However, within the routine 'count_only' made the code just a little easier to understand. I might have: - Removed the function parameter. - Added local variable bool count_only = regions_needed != NULL; - Left remaining code as it. I'm OK with the proposed change. Any change to readability is VERY minimal. Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 929256c130f9..d775e514eb2e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -321,16 +321,17 @@ static void coalesce_file_region(struct resv_map *resv, struct file_region *rg) } } -/* Must be called with resv->lock held. Calling this with count_only == true - * will count the number of pages to be added but will not modify the linked - * list. If regions_needed != NULL and count_only == true, then regions_needed - * will indicate the number of file_regions needed in the cache to carry out to - * add the regions for this range. +/* + * Must be called with resv->lock held. + * + * Calling this with regions_needed != NULL will count the number of pages + * to be added but will not modify the linked list. And regions_needed will + * indicate the number of file_regions needed in the cache to carry out to add + * the regions for this range. */ static long add_reservation_in_range(struct resv_map *resv, long f, long t, struct hugetlb_cgroup *h_cg, - struct hstate *h, long *regions_needed, - bool count_only) + struct hstate *h, long *regions_needed) { long add = 0; struct list_head *head = &resv->regions; @@ -366,14 +367,14 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, */ if (rg->from > last_accounted_offset) { add += rg->from - last_accounted_offset; - if (!count_only) { + if (!regions_needed) { nrg = get_file_region_entry_from_cache( resv, last_accounted_offset, rg->from); record_hugetlb_cgroup_uncharge_info(h_cg, h, resv, nrg); list_add(&nrg->link, rg->link.prev); coalesce_file_region(resv, nrg); - } else if (regions_needed) + } else *regions_needed += 1; } @@ -385,13 +386,13 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, */ if (last_accounted_offset < t) { add += t - last_accounted_offset; - if (!count_only) { + if (!regions_needed) { nrg = get_file_region_entry_from_cache( resv, last_accounted_offset, t); record_hugetlb_cgroup_uncharge_info(h_cg, h, resv, nrg); list_add(&nrg->link, rg->link.prev); coalesce_file_region(resv, nrg); - } else if (regions_needed) + } else *regions_needed += 1; } @@ -484,8 +485,8 @@ static long region_add(struct resv_map *resv, long f, long t, retry: /* Count how many regions are actually needed to execute this add. */ - add_reservation_in_range(resv, f, t, NULL, NULL, &actual_regions_needed, - true); + add_reservation_in_range(resv, f, t, NULL, NULL, + &actual_regions_needed); /* * Check for sufficient descriptors in the cache to accommodate @@ -513,7 +514,7 @@ static long region_add(struct resv_map *resv, long f, long t, goto retry; } - add = add_reservation_in_range(resv, f, t, h_cg, h, NULL, false); + add = add_reservation_in_range(resv, f, t, h_cg, h, NULL); resv->adds_in_progress -= in_regions_needed; @@ -549,9 +550,9 @@ static long region_chg(struct resv_map *resv, long f, long t, spin_lock(&resv->lock); - /* Count how many hugepages in this range are NOT respresented. */ + /* Count how many hugepages in this range are NOT represented. */ chg = add_reservation_in_range(resv, f, t, NULL, NULL, - out_regions_needed, true); + out_regions_needed); if (*out_regions_needed == 0) *out_regions_needed = 1;
There are only two cases of function add_reservation_in_range() * count file_region and return the number in regions_needed * do the real list operation without counting This means it is not necessary to have two parameters to classify these two cases. Just use regions_needed to separate them. Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com> --- mm/hugetlb.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)