@@ -2002,13 +2002,14 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
{
struct mm_struct *mm = current->mm;
struct vm_area_struct *vma;
- unsigned long length, low_limit, high_limit, gap_start, gap_end;
+ unsigned long length, low_limit, high_limit, gap_start, gap_end, gap_end_tmp;
/* Adjust search length to account for worst case alignment overhead */
length = info->length + info->align_mask;
if (length < info->length)
return -ENOMEM;
+ length = info->length;
/*
* Adjust search limits by the desired length.
* See implementation comment at top of unmapped_area().
@@ -2024,8 +2025,12 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
/* Check highest gap, which does not precede any rbtree node */
gap_start = mm->highest_vm_end;
- if (gap_start <= high_limit)
- goto found_highest;
+ if (gap_start <= high_limit) {
+ gap_end_tmp = gap_end - info->length;
+ gap_end_tmp -= (gap_end_tmp - info->align_offset) & info->align_mask;
+ if (gap_end_tmp >= gap_start)
+ goto found_highest;
+ }
/* Check if rbtree root looks promising */
if (RB_EMPTY_ROOT(&mm->mm_rb))
@@ -2053,8 +2058,13 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
if (gap_end < low_limit)
return -ENOMEM;
if (gap_start <= high_limit &&
- gap_end > gap_start && gap_end - gap_start >= length)
- goto found;
+ gap_end > gap_start && gap_end - gap_start >= length) {
+ gap_end_tmp = gap_end - info->length;
+ gap_end_tmp -= (gap_end_tmp - info->align_offset) & info->align_mask;
+ if (gap_end_tmp >= gap_start)
+ goto found;
+
+ }
/* Visit left subtree if it looks promising */
if (vma->vm_rb.rb_left) {