[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220113180308.15610-2-mike.kravetz@oracle.com>
Date: Thu, 13 Jan 2022 10:03:06 -0800
From: Mike Kravetz <mike.kravetz@...cle.com>
To: linux-kernel@...r.kernel.org, linux-mm@...ck.org
Cc: Michal Hocko <mhocko@...e.com>,
Naoya Horiguchi <naoya.horiguchi@...ux.dev>,
Axel Rasmussen <axelrasmussen@...gle.com>,
Peter Xu <peterx@...hat.com>,
Andrea Arcangeli <aarcange@...hat.com>,
Mina Almasry <almasrymina@...gle.com>,
Shuah Khan <shuah@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Mike Kravetz <mike.kravetz@...cle.com>
Subject: [RFC PATCH 1/3] mm: enable MADV_DONTNEED for hugetlb mappings
MADV_DONTNEED is currently disabled for hugetlb mappings. This
certainly makes sense in shared file mappings as the pagecache maintains
a reference to the page and it will never be freed. However, it could
be useful to unmap and free pages in private mappings.
The only thing preventing MADV_DONTNEED (and MADV_FREE) from working on
hugetlb mappings is a check in can_madv_lru_vma(). To allow support for
hugetlb mappings create and use a new routine madvise_dontneed_valid_vma()
that will allow hugetlb mappings.
Signed-off-by: Mike Kravetz <mike.kravetz@...cle.com>
---
mm/madvise.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/mm/madvise.c b/mm/madvise.c
index 8c927202bbe6..fc8992f4ae40 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -766,6 +766,11 @@ static long madvise_dontneed_single_vma(struct vm_area_struct *vma,
return 0;
}
+static bool madvise_dontneed_valid_vma(struct vm_area_struct *vma)
+{
+ return (vma->vm_flags & VM_HUGETLB) || can_madv_lru_vma(vma);
+}
+
static long madvise_dontneed_free(struct vm_area_struct *vma,
struct vm_area_struct **prev,
unsigned long start, unsigned long end,
@@ -774,7 +779,7 @@ static long madvise_dontneed_free(struct vm_area_struct *vma,
struct mm_struct *mm = vma->vm_mm;
*prev = vma;
- if (!can_madv_lru_vma(vma))
+ if (!madvise_dontneed_valid_vma(vma))
return -EINVAL;
if (!userfaultfd_remove(vma, start, end)) {
@@ -796,7 +801,7 @@ static long madvise_dontneed_free(struct vm_area_struct *vma,
*/
return -ENOMEM;
}
- if (!can_madv_lru_vma(vma))
+ if (!madvise_dontneed_valid_vma(vma))
return -EINVAL;
if (end > vma->vm_end) {
/*
--
2.34.1
Powered by blists - more mailing lists