Skip to contentSkip to conversation

mm,thp: add read-only THP support for (non-shmem)FS

PATCH Hillf Danton 2 participants 2 messages Jun 24, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello

Quoted 43 lines · On Mon, 24 Jun 2019 12:28:32 +0800 Song Liu wrote:

Hi Hillf,

Quoted 40 lines · Hillf Danton

Hello

Quoted 34 lines · On Sun, 23 Jun 2019 13:48:47 +0800 Song Liu wrote:

This patch is (hopefully) the first step to enable THP for non-shmem filesystems.

This patch enables an application to put part of its text sections to THP via madvise, for example:

   madvise((void *)0x600000, 0x200000, MADV_HUGEPAGE);

We tried to reuse the logic for THP on tmpfs.

Currently, write is not supported for non-shmem THP. khugepaged will only process vma with VM_DENYWRITE. The next patch will handle writes, which would only happen when the vma with VM_DENYWRITE is unmapped.

An EXPERIMENTAL config, READ_ONLY_THP_FOR_FS, is added to gate this feature.

---

mm/Kconfig      | 11 ++++++
mm/filemap.c    |  4 +--
mm/khugepaged.c | 90 ++++++++++++++++++++++++++++++++++++++++---------
mm/rmap.c       | 12 ++++---
4 files changed, 96 insertions(+), 21 deletions(-)
mm/Kconfig +0 -0
index f0c76ba47695..0a8fd589406d 100644
@@ -762,6 +762,17 @@ config GUP_BENCHMARK
 
 	  See tools/testing/selftests/vm/gup_benchmark.c
 
Quoted 9 lines
Quoted 6 lines

mm/Kconfig config GUP_BENCHMARK · line 768

Quoted 4 lines
mm/Kconfig +4 -0
+config READ_ONLY_THP_FOR_FS
+	bool "Read-only THP for filesystems (EXPERIMENTAL)"
+	depends on TRANSPARENT_HUGE_PAGECACHE && SHMEM
+

The ext4 mentioned in the cover letter, along with the subject line of this patch, suggests the scissoring of SHMEM.

We reuse khugepaged code for SHMEM, so the dependency does exist.

On the other hand I see collapse_file() and khugepaged_scan_file(), and wonder if ext4 files can be handled by the new functions. If yes, we can drop that dependency in the game of RO thp to make ext4 be ext4, and shmem be shmem, as they are.

Hillf

#1 lore raw
Quoted 58 lines · Hillf Danton

Hello

Quoted 50 lines · On Mon, 24 Jun 2019 12:28:32 +0800 Song Liu wrote:

Hi Hillf,

Quoted 46 lines · Hillf Danton

Hello

Quoted 31 lines · On Sun, 23 Jun 2019 13:48:47 +0800 Song Liu wrote:

This patch is (hopefully) the first step to enable THP for non-shmem filesystems.

This patch enables an application to put part of its text sections to THP via madvise, for example:

  madvise((void *)0x600000, 0x200000, MADV_HUGEPAGE);

We tried to reuse the logic for THP on tmpfs.

Currently, write is not supported for non-shmem THP. khugepaged will only process vma with VM_DENYWRITE. The next patch will handle writes, which would only happen when the vma with VM_DENYWRITE is unmapped.

An EXPERIMENTAL config, READ_ONLY_THP_FOR_FS, is added to gate this feature.

---

mm/Kconfig      | 11 ++++++
mm/filemap.c    |  4 +--
mm/khugepaged.c | 90 ++++++++++++++++++++++++++++++++++++++++---------
mm/rmap.c       | 12 ++++---
4 files changed, 96 insertions(+), 21 deletions(-)
mm/Kconfig +0 -0
index f0c76ba47695..0a8fd589406d 100644

mm/Kconfig config GUP_BENCHMARK · line 768

Quoted 7 lines
mm/Kconfig +4 -0
@@ -762,6 +762,17 @@ config GUP_BENCHMARK
 
 	  See tools/testing/selftests/vm/gup_benchmark.c
 
+config READ_ONLY_THP_FOR_FS
+	bool "Read-only THP for filesystems (EXPERIMENTAL)"
+	depends on TRANSPARENT_HUGE_PAGECACHE && SHMEM
+

The ext4 mentioned in the cover letter, along with the subject line of this patch, suggests the scissoring of SHMEM.

Quoted 6 lines
Quoted 2 lines

We reuse khugepaged code for SHMEM, so the dependency does exist.

On the other hand I see collapse_file() and khugepaged_scan_file(), and wonder if ext4 files can be handled by the new functions. If yes, we can drop that dependency in the game of RO thp to make ext4 be ext4, and shmem be shmem, as they are.

Ext4 files can be handled by these functions. We will need fs specific code for writable THPs (in the future).

In longer term, once the code (with write support) become more stable, we will drop this config. As of now, I think it is OK to depend on SHMEM.

Thanks,
Song