Skip to content

Commit

Permalink
mm/vmalloc.c: halve the number of comparisons performed in pcpu_get_v…
Browse files Browse the repository at this point in the history
…m_areas()

In pcpu_get_vm_areas(), it checks each range is not overlapped.  To make
sure it is, only (N^2)/2 comparison is necessary, while current code
does N^2 times.  By starting from the next range, it achieves the goal
and the continue could be removed.

Also,

 - the overlap check of two ranges could be done with one clause

 - one typo in comment is fixed.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Wei Yang <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Cc: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
RichardWeiYang authored and torvalds committed Sep 7, 2017
1 parent 88d6ac4 commit c568da2
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2482,7 +2482,7 @@ static unsigned long pvm_determine_end(struct vmap_area **pnext,
* matching slot. While scanning, if any of the areas overlaps with
* existing vmap_area, the base address is pulled down to fit the
* area. Scanning is repeated till all the areas fit and then all
* necessary data structres are inserted and the result is returned.
* necessary data structures are inserted and the result is returned.
*/
struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
const size_t *sizes, int nr_vms,
Expand Down Expand Up @@ -2510,15 +2510,11 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
if (start > offsets[last_area])
last_area = area;

for (area2 = 0; area2 < nr_vms; area2++) {
for (area2 = area + 1; area2 < nr_vms; area2++) {
unsigned long start2 = offsets[area2];
unsigned long end2 = start2 + sizes[area2];

if (area2 == area)
continue;

BUG_ON(start2 >= start && start2 < end);
BUG_ON(end2 <= end && end2 > start);
BUG_ON(start2 < end && start < end2);
}
}
last_end = offsets[last_area] + sizes[last_area];
Expand Down

0 comments on commit c568da2

Please sign in to comment.