X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=mm%2Fmincore.c;h=f77433c20279d95c2a87ce7117888e63580c8922;hb=01bf0b64579ead8a82e7cfc32ae44bc667e7ad0f;hp=95c5f49f0a1ada33c90e292010149ab8f3e404b9;hpb=42da9cbd3eedde33a42acc2cb06f454814cf5de0;p=safe%2Fjmp%2Flinux-2.6 diff --git a/mm/mincore.c b/mm/mincore.c index 95c5f49..f77433c 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -7,13 +7,14 @@ /* * The mincore() system call. */ -#include #include +#include #include #include #include #include #include +#include #include #include @@ -33,7 +34,7 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t pgoff) * When tmpfs swaps out a page from a file, any process mapping that * file will not get a swp_entry_t in its pte, but rather it is like * any other file mapping (ie. marked !present and faulted in with - * tmpfs's .nopage). So swapped out tmpfs mappings are tested here. + * tmpfs's .fault). So swapped out tmpfs mappings are tested here. * * However when tmpfs moves the page from pagecache and into swapcache, * it is still in core, but the find_get_page below won't find it. @@ -72,13 +73,57 @@ static long do_mincore(unsigned long addr, unsigned char *vec, unsigned long pag if (!vma || addr < vma->vm_start) return -ENOMEM; +#ifdef CONFIG_HUGETLB_PAGE + if (is_vm_hugetlb_page(vma)) { + struct hstate *h; + unsigned long nr_huge; + unsigned char present; + + i = 0; + nr = min(pages, (vma->vm_end - addr) >> PAGE_SHIFT); + h = hstate_vma(vma); + nr_huge = ((addr + pages * PAGE_SIZE - 1) >> huge_page_shift(h)) + - (addr >> huge_page_shift(h)) + 1; + nr_huge = min(nr_huge, + (vma->vm_end - addr) >> huge_page_shift(h)); + while (1) { + /* hugepage always in RAM for now, + * but generally it needs to be check */ + ptep = huge_pte_offset(current->mm, + addr & huge_page_mask(h)); + present = !!(ptep && + !huge_pte_none(huge_ptep_get(ptep))); + while (1) { + vec[i++] = present; + addr += PAGE_SIZE; + /* reach buffer limit */ + if (i == nr) + return nr; + /* check hugepage border */ + if (!((addr & ~huge_page_mask(h)) + >> PAGE_SHIFT)) + break; + } + } + return nr; + } +#endif + /* * Calculate how many pages there are left in the last level of the * PTE array for our address. */ nr = PTRS_PER_PTE - ((addr >> PAGE_SHIFT) & (PTRS_PER_PTE-1)); - if (nr > pages) - nr = pages; + + /* + * Don't overrun this vma + */ + nr = min(nr, (vma->vm_end - addr) >> PAGE_SHIFT); + + /* + * Don't return more than the caller asked for + */ + nr = min(nr, pages); pgd = pgd_offset(vma->vm_mm, addr); if (pgd_none_or_clear_bad(pgd)) @@ -116,10 +161,17 @@ static long do_mincore(unsigned long addr, unsigned char *vec, unsigned long pag /* migration entries are always uptodate */ present = 1; } else { +#ifdef CONFIG_SWAP pgoff = entry.val; present = mincore_page(&swapper_space, pgoff); +#else + WARN_ON(1); + present = 1; +#endif } } + + vec[i] = present; } pte_unmap_unlock(ptep-1, ptl); @@ -130,6 +182,9 @@ none_mapped: pgoff = linear_page_index(vma, addr); for (i = 0; i < nr; i++, pgoff++) vec[i] = mincore_page(vma->vm_file->f_mapping, pgoff); + } else { + for (i = 0; i < nr; i++) + vec[i] = 0; } return nr; @@ -159,8 +214,8 @@ none_mapped: * mapped * -EAGAIN - A kernel resource was temporarily unavailable. */ -asmlinkage long sys_mincore(unsigned long start, size_t len, - unsigned char __user * vec) +SYSCALL_DEFINE3(mincore, unsigned long, start, size_t, len, + unsigned char __user *, vec) { long retval; unsigned long pages;