[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220317234827.447799-9-shy828301@gmail.com>
Date: Thu, 17 Mar 2022 16:48:27 -0700
From: Yang Shi <shy828301@...il.com>
To: vbabka@...e.cz, kirill.shutemov@...ux.intel.com,
linmiaohe@...wei.com, songliubraving@...com, riel@...riel.com,
willy@...radead.org, ziy@...dia.com, akpm@...ux-foundation.org,
tytso@....edu, adilger.kernel@...ger.ca, darrick.wong@...cle.com
Cc: shy828301@...il.com, linux-mm@...ck.org,
linux-fsdevel@...r.kernel.org, linux-ext4@...r.kernel.org,
linux-xfs@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [v2 PATCH 8/8] fs: register suitable readonly vmas for khugepaged
The readonly FS THP relies on khugepaged to collapse THP for suitable
vmas. But it is kind of "random luck" for khugepaged to see the
readonly FS vmas (https://lore.kernel.org/linux-mm/00f195d4-d039-3cf2-d3a1-a2c88de397a0@suse.cz/)
since currently the vmas are registered to khugepaged when:
- Anon huge pmd page fault
- VMA merge
- MADV_HUGEPAGE
- Shmem mmap
If the above conditions are not met, even though khugepaged is enabled
it won't see readonly FS vmas at all. MADV_HUGEPAGE could be specified
explicitly to tell khugepaged to collapse this area, but when khugepaged
mode is "always" it should scan suitable vmas as long as VM_NOHUGEPAGE
is not set.
So make sure readonly FS vmas are registered to khugepaged to make the
behavior more consistent.
Registering the vmas in mmap path seems more preferred from performance
point of view since page fault path is definitely hot path.
Reported-by: Vlastimil Babka <vbabka@...e.cz>
Signed-off-by: Yang Shi <shy828301@...il.com>
---
fs/ext4/file.c | 4 ++++
fs/xfs/xfs_file.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 8cc11715518a..b894cd5aff44 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -30,6 +30,7 @@
#include <linux/uio.h>
#include <linux/mman.h>
#include <linux/backing-dev.h>
+#include <linux/khugepaged.h>
#include "ext4.h"
#include "ext4_jbd2.h"
#include "xattr.h"
@@ -782,6 +783,9 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
} else {
vma->vm_ops = &ext4_file_vm_ops;
}
+
+ khugepaged_enter_file(vma, vma->vm_flags);
+
return 0;
}
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 5bddb1e9e0b3..d94144b1fb0f 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -30,6 +30,7 @@
#include <linux/mman.h>
#include <linux/fadvise.h>
#include <linux/mount.h>
+#include <linux/khugepaged.h>
static const struct vm_operations_struct xfs_file_vm_ops;
@@ -1407,6 +1408,9 @@ xfs_file_mmap(
vma->vm_ops = &xfs_file_vm_ops;
if (IS_DAX(inode))
vma->vm_flags |= VM_HUGEPAGE;
+
+ khugepaged_enter_file(vma, vma->vm_flags);
+
return 0;
}
--
2.26.3
Powered by blists - more mailing lists