diff options
Diffstat (limited to 'mm/mempolicy.c')
-rw-r--r-- | mm/mempolicy.c | 138 |
1 files changed, 109 insertions, 29 deletions
diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 67af4cea1e23..2a8206009422 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c | |||
@@ -197,7 +197,7 @@ static struct mempolicy *mpol_new(int mode, nodemask_t *nodes) | |||
197 | return policy; | 197 | return policy; |
198 | } | 198 | } |
199 | 199 | ||
200 | static void gather_stats(struct page *, void *); | 200 | static void gather_stats(struct page *, void *, int pte_dirty); |
201 | static void migrate_page_add(struct page *page, struct list_head *pagelist, | 201 | static void migrate_page_add(struct page *page, struct list_head *pagelist, |
202 | unsigned long flags); | 202 | unsigned long flags); |
203 | 203 | ||
@@ -239,7 +239,7 @@ static int check_pte_range(struct vm_area_struct *vma, pmd_t *pmd, | |||
239 | continue; | 239 | continue; |
240 | 240 | ||
241 | if (flags & MPOL_MF_STATS) | 241 | if (flags & MPOL_MF_STATS) |
242 | gather_stats(page, private); | 242 | gather_stats(page, private, pte_dirty(*pte)); |
243 | else if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) | 243 | else if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) |
244 | migrate_page_add(page, private, flags); | 244 | migrate_page_add(page, private, flags); |
245 | else | 245 | else |
@@ -748,7 +748,7 @@ long do_mbind(unsigned long start, unsigned long len, | |||
748 | MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) | 748 | MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) |
749 | || mode > MPOL_MAX) | 749 | || mode > MPOL_MAX) |
750 | return -EINVAL; | 750 | return -EINVAL; |
751 | if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_RESOURCE)) | 751 | if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE)) |
752 | return -EPERM; | 752 | return -EPERM; |
753 | 753 | ||
754 | if (start & ~PAGE_MASK) | 754 | if (start & ~PAGE_MASK) |
@@ -942,19 +942,20 @@ asmlinkage long sys_migrate_pages(pid_t pid, unsigned long maxnode, | |||
942 | */ | 942 | */ |
943 | if ((current->euid != task->suid) && (current->euid != task->uid) && | 943 | if ((current->euid != task->suid) && (current->euid != task->uid) && |
944 | (current->uid != task->suid) && (current->uid != task->uid) && | 944 | (current->uid != task->suid) && (current->uid != task->uid) && |
945 | !capable(CAP_SYS_ADMIN)) { | 945 | !capable(CAP_SYS_NICE)) { |
946 | err = -EPERM; | 946 | err = -EPERM; |
947 | goto out; | 947 | goto out; |
948 | } | 948 | } |
949 | 949 | ||
950 | task_nodes = cpuset_mems_allowed(task); | 950 | task_nodes = cpuset_mems_allowed(task); |
951 | /* Is the user allowed to access the target nodes? */ | 951 | /* Is the user allowed to access the target nodes? */ |
952 | if (!nodes_subset(new, task_nodes) && !capable(CAP_SYS_ADMIN)) { | 952 | if (!nodes_subset(new, task_nodes) && !capable(CAP_SYS_NICE)) { |
953 | err = -EPERM; | 953 | err = -EPERM; |
954 | goto out; | 954 | goto out; |
955 | } | 955 | } |
956 | 956 | ||
957 | err = do_migrate_pages(mm, &old, &new, MPOL_MF_MOVE); | 957 | err = do_migrate_pages(mm, &old, &new, |
958 | capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE); | ||
958 | out: | 959 | out: |
959 | mmput(mm); | 960 | mmput(mm); |
960 | return err; | 961 | return err; |
@@ -1752,66 +1753,145 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) | |||
1752 | struct numa_maps { | 1753 | struct numa_maps { |
1753 | unsigned long pages; | 1754 | unsigned long pages; |
1754 | unsigned long anon; | 1755 | unsigned long anon; |
1755 | unsigned long mapped; | 1756 | unsigned long active; |
1757 | unsigned long writeback; | ||
1756 | unsigned long mapcount_max; | 1758 | unsigned long mapcount_max; |
1759 | unsigned long dirty; | ||
1760 | unsigned long swapcache; | ||
1757 | unsigned long node[MAX_NUMNODES]; | 1761 | unsigned long node[MAX_NUMNODES]; |
1758 | }; | 1762 | }; |
1759 | 1763 | ||
1760 | static void gather_stats(struct page *page, void *private) | 1764 | static void gather_stats(struct page *page, void *private, int pte_dirty) |
1761 | { | 1765 | { |
1762 | struct numa_maps *md = private; | 1766 | struct numa_maps *md = private; |
1763 | int count = page_mapcount(page); | 1767 | int count = page_mapcount(page); |
1764 | 1768 | ||
1765 | if (count) | 1769 | md->pages++; |
1766 | md->mapped++; | 1770 | if (pte_dirty || PageDirty(page)) |
1771 | md->dirty++; | ||
1767 | 1772 | ||
1768 | if (count > md->mapcount_max) | 1773 | if (PageSwapCache(page)) |
1769 | md->mapcount_max = count; | 1774 | md->swapcache++; |
1770 | 1775 | ||
1771 | md->pages++; | 1776 | if (PageActive(page)) |
1777 | md->active++; | ||
1778 | |||
1779 | if (PageWriteback(page)) | ||
1780 | md->writeback++; | ||
1772 | 1781 | ||
1773 | if (PageAnon(page)) | 1782 | if (PageAnon(page)) |
1774 | md->anon++; | 1783 | md->anon++; |
1775 | 1784 | ||
1785 | if (count > md->mapcount_max) | ||
1786 | md->mapcount_max = count; | ||
1787 | |||
1776 | md->node[page_to_nid(page)]++; | 1788 | md->node[page_to_nid(page)]++; |
1777 | cond_resched(); | 1789 | cond_resched(); |
1778 | } | 1790 | } |
1779 | 1791 | ||
1792 | #ifdef CONFIG_HUGETLB_PAGE | ||
1793 | static void check_huge_range(struct vm_area_struct *vma, | ||
1794 | unsigned long start, unsigned long end, | ||
1795 | struct numa_maps *md) | ||
1796 | { | ||
1797 | unsigned long addr; | ||
1798 | struct page *page; | ||
1799 | |||
1800 | for (addr = start; addr < end; addr += HPAGE_SIZE) { | ||
1801 | pte_t *ptep = huge_pte_offset(vma->vm_mm, addr & HPAGE_MASK); | ||
1802 | pte_t pte; | ||
1803 | |||
1804 | if (!ptep) | ||
1805 | continue; | ||
1806 | |||
1807 | pte = *ptep; | ||
1808 | if (pte_none(pte)) | ||
1809 | continue; | ||
1810 | |||
1811 | page = pte_page(pte); | ||
1812 | if (!page) | ||
1813 | continue; | ||
1814 | |||
1815 | gather_stats(page, md, pte_dirty(*ptep)); | ||
1816 | } | ||
1817 | } | ||
1818 | #else | ||
1819 | static inline void check_huge_range(struct vm_area_struct *vma, | ||
1820 | unsigned long start, unsigned long end, | ||
1821 | struct numa_maps *md) | ||
1822 | { | ||
1823 | } | ||
1824 | #endif | ||
1825 | |||
1780 | int show_numa_map(struct seq_file *m, void *v) | 1826 | int show_numa_map(struct seq_file *m, void *v) |
1781 | { | 1827 | { |
1782 | struct task_struct *task = m->private; | 1828 | struct task_struct *task = m->private; |
1783 | struct vm_area_struct *vma = v; | 1829 | struct vm_area_struct *vma = v; |
1784 | struct numa_maps *md; | 1830 | struct numa_maps *md; |
1831 | struct file *file = vma->vm_file; | ||
1832 | struct mm_struct *mm = vma->vm_mm; | ||
1785 | int n; | 1833 | int n; |
1786 | char buffer[50]; | 1834 | char buffer[50]; |
1787 | 1835 | ||
1788 | if (!vma->vm_mm) | 1836 | if (!mm) |
1789 | return 0; | 1837 | return 0; |
1790 | 1838 | ||
1791 | md = kzalloc(sizeof(struct numa_maps), GFP_KERNEL); | 1839 | md = kzalloc(sizeof(struct numa_maps), GFP_KERNEL); |
1792 | if (!md) | 1840 | if (!md) |
1793 | return 0; | 1841 | return 0; |
1794 | 1842 | ||
1795 | check_pgd_range(vma, vma->vm_start, vma->vm_end, | 1843 | mpol_to_str(buffer, sizeof(buffer), |
1796 | &node_online_map, MPOL_MF_STATS, md); | 1844 | get_vma_policy(task, vma, vma->vm_start)); |
1797 | 1845 | ||
1798 | if (md->pages) { | 1846 | seq_printf(m, "%08lx %s", vma->vm_start, buffer); |
1799 | mpol_to_str(buffer, sizeof(buffer), | ||
1800 | get_vma_policy(task, vma, vma->vm_start)); | ||
1801 | 1847 | ||
1802 | seq_printf(m, "%08lx %s pages=%lu mapped=%lu maxref=%lu", | 1848 | if (file) { |
1803 | vma->vm_start, buffer, md->pages, | 1849 | seq_printf(m, " file="); |
1804 | md->mapped, md->mapcount_max); | 1850 | seq_path(m, file->f_vfsmnt, file->f_dentry, "\n\t= "); |
1851 | } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { | ||
1852 | seq_printf(m, " heap"); | ||
1853 | } else if (vma->vm_start <= mm->start_stack && | ||
1854 | vma->vm_end >= mm->start_stack) { | ||
1855 | seq_printf(m, " stack"); | ||
1856 | } | ||
1805 | 1857 | ||
1806 | if (md->anon) | 1858 | if (is_vm_hugetlb_page(vma)) { |
1807 | seq_printf(m," anon=%lu",md->anon); | 1859 | check_huge_range(vma, vma->vm_start, vma->vm_end, md); |
1860 | seq_printf(m, " huge"); | ||
1861 | } else { | ||
1862 | check_pgd_range(vma, vma->vm_start, vma->vm_end, | ||
1863 | &node_online_map, MPOL_MF_STATS, md); | ||
1864 | } | ||
1808 | 1865 | ||
1809 | for_each_online_node(n) | 1866 | if (!md->pages) |
1810 | if (md->node[n]) | 1867 | goto out; |
1811 | seq_printf(m, " N%d=%lu", n, md->node[n]); | ||
1812 | 1868 | ||
1813 | seq_putc(m, '\n'); | 1869 | if (md->anon) |
1814 | } | 1870 | seq_printf(m," anon=%lu",md->anon); |
1871 | |||
1872 | if (md->dirty) | ||
1873 | seq_printf(m," dirty=%lu",md->dirty); | ||
1874 | |||
1875 | if (md->pages != md->anon && md->pages != md->dirty) | ||
1876 | seq_printf(m, " mapped=%lu", md->pages); | ||
1877 | |||
1878 | if (md->mapcount_max > 1) | ||
1879 | seq_printf(m, " mapmax=%lu", md->mapcount_max); | ||
1880 | |||
1881 | if (md->swapcache) | ||
1882 | seq_printf(m," swapcache=%lu", md->swapcache); | ||
1883 | |||
1884 | if (md->active < md->pages && !is_vm_hugetlb_page(vma)) | ||
1885 | seq_printf(m," active=%lu", md->active); | ||
1886 | |||
1887 | if (md->writeback) | ||
1888 | seq_printf(m," writeback=%lu", md->writeback); | ||
1889 | |||
1890 | for_each_online_node(n) | ||
1891 | if (md->node[n]) | ||
1892 | seq_printf(m, " N%d=%lu", n, md->node[n]); | ||
1893 | out: | ||
1894 | seq_putc(m, '\n'); | ||
1815 | kfree(md); | 1895 | kfree(md); |
1816 | 1896 | ||
1817 | if (m->count < m->size) | 1897 | if (m->count < m->size) |