mm, thp: preventing hugepage creation for read-write file pages
[platform/kernel/linux-rpi.git] / arch / arm64 / mm / finegrained_thp.c
1 #include <linux/shmem_fs.h>
2 #include <asm/huge_mm.h>
3
4 bool arm64_hugepage_vma_shmem_check(struct vm_area_struct *vma,
5                                         unsigned long vm_flags, int nr_pages)
6 {
7         /* Enabled via shmem mount options or sysfs settings. */
8         if (shmem_file(vma->vm_file) && shmem_huge_enabled(vma)) {
9                 return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff,
10                                 nr_pages);
11         }
12         return false;
13 }
14
15 bool arm64_hugepage_vma_file_check(struct vm_area_struct *vma,
16                                         unsigned long vm_flags, int nr_pages)
17 {
18         /* Read-only file mappings need to be aligned for THP to work. */
19         if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file &&
20             (vm_flags & VM_DENYWRITE) && !(vm_flags & VM_WRITE)) {
21                 return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff,
22                                 nr_pages);
23         }
24         return false;
25 }
26