History

mm: thp: make transhuge_vma_suitable available for anonymous THP

transhuge_vma_suitable() was only available for shmem THP, but anonymous THP has the same check except pgoff check. And, it will be used for THP eligible check in the later patch, so make it available for all kind of THPs. This also helps reduce code duplication slightly. Since anonymous THP doesn't have to check pgoff, so make pgoff check shmem vma only. And regroup some functions in include/linux/mm.h to solve compile issue since transhuge_vma_suitable() needs call vma_is_anonymous() which was defined after huge_mm.h is included. [akpm@linux-foundation.org: fix typo] [yang.shi@linux.alibaba.com: v4] Link: http://lkml.kernel.org/r/1563400758-124759-2-git-send-email-yang.shi@linux.alibaba.com Link: http://lkml.kernel.org/r/1560401041-32207-2-git-send-email-yang.shi@linux.alibaba.com Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com> Acked-by: Hugh Dickins <hughd@google.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: David Rientjes <rientjes@google.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Yang Shi committed 7 years ago

Commit 43675e61 parent 26f26be4 files · +41 −31Browse files

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/huge_mm.h +23 −0
  2. include/linux/mm.h +17 −17
include/linux/huge_mm.h+23−0
@@ -121,6 +121,23 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) · 120 unmodified lines
121121
122122 bool transparent_hugepage_enabled(struct vm_area_struct *vma);
123123
124+#define HPAGE_CACHE_INDEX_MASK (HPAGE_PMD_NR - 1)
125+
126+static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
127+ unsigned long haddr)
128+{
129+ /* Don't have to check pgoff for anonymous vma */
130+ if (!vma_is_anonymous(vma)) {
131+ if (((vma->vm_start >> PAGE_SHIFT) & HPAGE_CACHE_INDEX_MASK) !=
132+ (vma->vm_pgoff & HPAGE_CACHE_INDEX_MASK))
133+ return false;
134+ }
135+
136+ if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end)
137+ return false;
138+ return true;
139+}
140+
124141 #define transparent_hugepage_use_zero_page() \
125142 (transparent_hugepage_flags & \
126143 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
@@ -271,6 +288,12 @@ static inline bool transparent_hugepage_enabled(struct vm_area_struct *vma) · 144 unmodified lines
271288 return false;
272289 }
273290
291+static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
292+ unsigned long haddr)
293+{
294+ return false;
295+}
296+
274297 static inline void prep_transhuge_page(struct page *page) {}
275298
276299 #define transparent_hugepage_flags 0UL
include/linux/mm.h+17−17
@@ -541,6 +541,23 @@ static inline void vma_set_anonymous(struct vm_area_struct *vma) · 540 unmodified lines
541541 vma->vm_ops = NULL;
542542 }
543543
544+static inline bool vma_is_anonymous(struct vm_area_struct *vma)
545+{
546+ return !vma->vm_ops;
547+}
548+
549+#ifdef CONFIG_SHMEM
550+/*
551+ * The vma_is_shmem is not inline because it is used only by slow
552+ * paths in userfault.
553+ */
554+bool vma_is_shmem(struct vm_area_struct *vma);
555+#else
556+static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; }
557+#endif
558+
559+int vma_is_stack_for_current(struct vm_area_struct *vma);
560+
544561 /* flush_tlb_range() takes a vma, not a mm, and can care about flags */
545562 #define TLB_FLUSH_VMA(mm,flags) { .vm_mm = (mm), .vm_flags = (flags) }
546563
@@ -1620,23 +1637,6 @@ int clear_page_dirty_for_io(struct page *page); · 1073 unmodified lines
16201637
16211638 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
16221639
1623−static inline bool vma_is_anonymous(struct vm_area_struct *vma)
1624−{
1625− return !vma->vm_ops;
1626−}
1627−
1628−#ifdef CONFIG_SHMEM
1629−/*
1630− * The vma_is_shmem is not inline because it is used only by slow
1631− * paths in userfault.
1632− */
1633−bool vma_is_shmem(struct vm_area_struct *vma);
1634−#else
1635−static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; }
1636−#endif
1637−
1638−int vma_is_stack_for_current(struct vm_area_struct *vma);
1639−
16401640 extern unsigned long move_page_tables(struct vm_area_struct *vma,
16411641 unsigned long old_addr, struct vm_area_struct *new_vma,
16421642 unsigned long new_addr, unsigned long len,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t