I've been stress testing large folio splits using the new debugfs interface
with a new fstests test [0], to make the debugfs interface more useful it helps
to do bounds checks on input parameters so this fixes two issues found while
doing automatic stress testing of the debugfs interface with found files.
Provided there are no issues I think this should go in for v6.9-rc6.
Also, *should* we strive to support splits for large folios to min order
with say MADV_NOHUGEPAGE ?
[0] https://lkml.kernel.org/r/[email protected]
Luis Chamberlain (2):
mm/huge_memory: skip invalid debugfs file entry for folio split
mm/huge_memory: cap max length on debugfs file entry folio split
mm/huge_memory.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
--
2.43.0
Don't allow to query beyond a mapped file's length. Since this is just
a debugfs interface allow userspace to be lazy and use a large value so
we can just use the entire file.
Without this we can end up wasting cycles looking for folios which
just don't exist for no good reason.
Signed-off-by: Luis Chamberlain <[email protected]>
---
mm/huge_memory.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 8386d24a163e..86a8c7b3b8dc 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3535,7 +3535,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,
struct file *candidate;
struct address_space *mapping;
int ret = -EINVAL;
- pgoff_t index;
+ pgoff_t index, fsize;
int nr_pages = 1;
unsigned long total = 0, split = 0;
@@ -3547,11 +3547,14 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,
if (IS_ERR(candidate))
goto out;
+ mapping = candidate->f_mapping;
+ fsize = i_size_read(mapping->host);
+ if (off_end > fsize)
+ off_end = fsize;
+
pr_debug("split file-backed THPs in file: %s, page offset: [0x%lx - 0x%lx]\n",
file_path, off_start, off_end);
- mapping = candidate->f_mapping;
-
for (index = off_start; index < off_end; index += nr_pages) {
struct folio *folio = filemap_get_folio(mapping, index);
--
2.43.0
On 24 Apr 2024, at 18:54, Luis Chamberlain wrote:
> Don't allow to query beyond a mapped file's length. Since this is just
> a debugfs interface allow userspace to be lazy and use a large value so
> we can just use the entire file.
>
> Without this we can end up wasting cycles looking for folios which
> just don't exist for no good reason.
>
> Signed-off-by: Luis Chamberlain <[email protected]>
> ---
> mm/huge_memory.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 8386d24a163e..86a8c7b3b8dc 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -3535,7 +3535,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,
> struct file *candidate;
> struct address_space *mapping;
> int ret = -EINVAL;
> - pgoff_t index;
> + pgoff_t index, fsize;
> int nr_pages = 1;
> unsigned long total = 0, split = 0;
>
> @@ -3547,11 +3547,14 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,
> if (IS_ERR(candidate))
> goto out;
>
> + mapping = candidate->f_mapping;
> + fsize = i_size_read(mapping->host);
> + if (off_end > fsize)
> + off_end = fsize;
> +
> pr_debug("split file-backed THPs in file: %s, page offset: [0x%lx - 0x%lx]\n",
> file_path, off_start, off_end);
>
> - mapping = candidate->f_mapping;
> -
> for (index = off_start; index < off_end; index += nr_pages) {
> struct folio *folio = filemap_get_folio(mapping, index);
LGTM. Reviewed-by: Zi Yan <[email protected]>
--
Best Regards,
Yan, Zi
The subject hints at a cleanup but I decided to leave that for another
separate patch which I'll send next.
Luis