[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-mm
Subject:    mincore_vma function
From:       Amol Kumar Lad <amolk () ishoni ! com>
Date:       2002-11-18 8:01:55
[Download RAW message or body]

Hi,
  I'm bit confused while reading this function

static long mincore_vma(struct vm_area_struct * vma,
        unsigned long start, unsigned long end, unsigned char * vec)
{
        long error, i, remaining;
        unsigned char * tmp;

        error = -ENOMEM;
        if (!vma->vm_file)
                return error;

        start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
        if (end > vma->vm_end)
                end = vma->vm_end;
        end = ((end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;

        error = -EAGAIN;
        tmp = (unsigned char *) __get_free_page(GFP_KERNEL);
        if (!tmp)
                return error;

        /* (end - start) is # of pages, and also # of bytes in "vec */
        remaining = (end - start),

        error = 0;
        for (i = 0; remaining > 0; remaining -= PAGE_SIZE, i++) {
                int j = 0;
                long thispiece = (remaining < PAGE_SIZE) ?
                                                remaining : PAGE_SIZE;
>>>> Why this check ? Is it possible the remaining is not a multiple of
page (remaining = end - start)

                while (j < thispiece)
                        tmp[j++] = mincore_page(vma, start++);
>>>> why this loop ?? Don't we only need to call mincore_page _once_
with second arg start += PAGE_SIZE; 

                if (copy_to_user(vec + PAGE_SIZE * i, tmp, thispiece)) {
                        error = -EFAULT;
                        break;
                }
>>>> Again, accroding to man page of mincore, each byte of vec tells
whether page is resident or not... What is above copy_to_user doing
        }

        free_page((unsigned long) tmp);
        return error;
}

I am using 2.4.57-mm2

-- Amol


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic