mm/zsmalloc.c: convert to use kmem_cache_zalloc in cache_alloc_zspage()
[linux-2.6-microblaze.git] / mm / khugepaged.c
index fb0fdae..a7d6cb9 100644 (file)
@@ -442,18 +442,28 @@ static inline int khugepaged_test_exit(struct mm_struct *mm)
 static bool hugepage_vma_check(struct vm_area_struct *vma,
                               unsigned long vm_flags)
 {
-       if ((!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) ||
-           (vm_flags & VM_NOHUGEPAGE) ||
+       /* Explicitly disabled through madvise. */
+       if ((vm_flags & VM_NOHUGEPAGE) ||
            test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))
                return false;
 
-       if (shmem_file(vma->vm_file) ||
-           (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
-            vma->vm_file &&
-            (vm_flags & VM_DENYWRITE))) {
+       /* Enabled via shmem mount options or sysfs settings. */
+       if (shmem_file(vma->vm_file) && shmem_huge_enabled(vma)) {
                return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff,
                                HPAGE_PMD_NR);
        }
+
+       /* THP settings require madvise. */
+       if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always())
+               return false;
+
+       /* Read-only file mappings need to be aligned for THP to work. */
+       if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file &&
+           (vm_flags & VM_DENYWRITE)) {
+               return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff,
+                               HPAGE_PMD_NR);
+       }
+
        if (!vma->anon_vma || vma->vm_ops)
                return false;
        if (vma_is_temporary_stack(vma))
@@ -1643,6 +1653,7 @@ static void collapse_file(struct mm_struct *mm,
        XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER);
        int nr_none = 0, result = SCAN_SUCCEED;
        bool is_shmem = shmem_file(file);
+       int nr;
 
        VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
        VM_BUG_ON(start & (HPAGE_PMD_NR - 1));
@@ -1854,11 +1865,12 @@ out_unlock:
                put_page(page);
                goto xa_unlocked;
        }
+       nr = thp_nr_pages(new_page);
 
        if (is_shmem)
-               __inc_lruvec_page_state(new_page, NR_SHMEM_THPS);
+               __mod_lruvec_page_state(new_page, NR_SHMEM_THPS, nr);
        else {
-               __inc_lruvec_page_state(new_page, NR_FILE_THPS);
+               __mod_lruvec_page_state(new_page, NR_FILE_THPS, nr);
                filemap_nr_thps_inc(mapping);
        }