mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* different conditions in arch_get_unmapped_area_topdown
@ 2008-06-05 12:43 Vitaly Mayatskikh
  0 siblings, 0 replies; only message in thread
From: Vitaly Mayatskikh @ 2008-06-05 12:43 UTC (permalink / raw)
  To: linux-kernel

Hi!

Here's do-while loop from generic arch_get_unmapped_area_topdown() from mm/mmap.c:

        do {
                /*
                 * Lookup failure means no vma is above this address,
                 * else if new region fits below vma->vm_start,
                 * return with success:
                 */
                vma = find_vma(mm, addr);
                if (!vma || addr+len <= vma->vm_start)
                        /* remember the address as a hint for next time */
                        return (mm->free_area_cache = addr);
                
                /* remember the largest hole we saw so far */
                if (addr + mm->cached_hole_size < vma->vm_start)
                        mm->cached_hole_size = vma->vm_start - addr;
                       
                /* try just below the current vma->vm_start */
                addr = vma->vm_start-len;
        } while (len < vma->vm_start);

And here's from arch/x86/mm/hugetlbpage.c:

        do {
                /*
                 * Lookup failure means no vma is above this address,
                 * i.e. return with success:
                 */
                if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
                        return addr;
       
                /*
                 * new region fits between prev_vma->vm_end and
                 * vma->vm_start, use it:
                 */
                if (addr + len <= vma->vm_start &&
                            (!prev_vma || (addr >= prev_vma->vm_end))) {
                        /* remember the address as a hint for next time */
                        mm->cached_hole_size = largest_hole;
                        return (mm->free_area_cache = addr);
                } else {
                        /* pull free_area_cache down to the first hole */
                        if (mm->free_area_cache == vma->vm_end) {
                                mm->free_area_cache = vma->vm_start;
                                mm->cached_hole_size = largest_hole;
                        }
                }
           
                /* remember the largest hole we saw so far */
                if (addr + largest_hole < vma->vm_start)
                        largest_hole = vma->vm_start - addr;

                /* try just below the current vma->vm_start */
                addr = (vma->vm_start - len) & HPAGE_MASK;
        } while (len <= vma->vm_start);

Why conditions in "while" differ from each other? Can the second case lead to infinite loop?

Thanks!
-- 
wbr, Vitaly

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-05 12:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-05 12:43 different conditions in arch_get_unmapped_area_topdown Vitaly Mayatskikh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®