[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <97c312c8c0b56218454d546a540a3ea2e2a825e2.1686077275.git.ackerleytng@google.com>
Date: Tue, 6 Jun 2023 19:03:47 +0000
From: Ackerley Tng <ackerleytng@...gle.com>
To: akpm@...ux-foundation.org, mike.kravetz@...cle.com,
muchun.song@...ux.dev, pbonzini@...hat.com, seanjc@...gle.com,
shuah@...nel.org, willy@...radead.org
Cc: brauner@...nel.org, chao.p.peng@...ux.intel.com,
coltonlewis@...gle.com, david@...hat.com, dhildenb@...hat.com,
dmatlack@...gle.com, erdemaktas@...gle.com, hughd@...gle.com,
isaku.yamahata@...il.com, jarkko@...nel.org, jmattson@...gle.com,
joro@...tes.org, jthoughton@...gle.com, jun.nakajima@...el.com,
kirill.shutemov@...ux.intel.com, liam.merwick@...cle.com,
mail@...iej.szmigiero.name, mhocko@...e.com, michael.roth@....com,
qperret@...gle.com, rientjes@...gle.com, rppt@...nel.org,
steven.price@....com, tabba@...gle.com, vannapurve@...gle.com,
vbabka@...e.cz, vipinsh@...gle.com, vkuznets@...hat.com,
wei.w.wang@...el.com, yu.c.zhang@...ux.intel.com,
kvm@...r.kernel.org, linux-api@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-mm@...ck.org,
qemu-devel@...gnu.org, x86@...nel.org,
Ackerley Tng <ackerleytng@...gle.com>
Subject: [RFC PATCH 02/19] mm: hugetlb: Move and expose hugetlbfs_zero_partial_page
Zeroing of pages is generalizable to hugetlb and is not specific to
hugetlbfs.
Rename hugetlbfs_zero_partial_page => hugetlb_zero_partial_page, move
it to mm/hugetlb.c and expose it in linux/hugetlb.h.
Signed-off-by: Ackerley Tng <ackerleytng@...gle.com>
---
fs/hugetlbfs/inode.c | 27 ++-------------------------
include/linux/hugetlb.h | 6 ++++++
mm/hugetlb.c | 22 ++++++++++++++++++++++
3 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 406d7366cf3e..3dab50d3ed88 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -688,29 +688,6 @@ static void hugetlb_vmtruncate(struct inode *inode, loff_t offset)
remove_inode_hugepages(inode, offset, LLONG_MAX);
}
-static void hugetlbfs_zero_partial_page(struct hstate *h,
- struct address_space *mapping,
- loff_t start,
- loff_t end)
-{
- pgoff_t idx = start >> huge_page_shift(h);
- struct folio *folio;
-
- folio = filemap_lock_folio(mapping, idx);
- if (!folio)
- return;
-
- start = start & ~huge_page_mask(h);
- end = end & ~huge_page_mask(h);
- if (!end)
- end = huge_page_size(h);
-
- folio_zero_segment(folio, (size_t)start, (size_t)end);
-
- folio_unlock(folio);
- folio_put(folio);
-}
-
static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
{
struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
@@ -737,7 +714,7 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
/* If range starts before first full page, zero partial page. */
if (offset < hole_start)
- hugetlbfs_zero_partial_page(h, mapping,
+ hugetlb_zero_partial_page(h, mapping,
offset, min(offset + len, hole_start));
/* Unmap users of full pages in the hole. */
@@ -750,7 +727,7 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
/* If range extends beyond last full page, zero partial page. */
if ((offset + len) > hole_end && (offset + len) > hole_start)
- hugetlbfs_zero_partial_page(h, mapping,
+ hugetlb_zero_partial_page(h, mapping,
hole_end, offset + len);
i_mmap_unlock_write(mapping);
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 37c2edf7beea..023293ceec25 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -256,6 +256,9 @@ long hugetlb_change_protection(struct vm_area_struct *vma,
bool is_hugetlb_entry_migration(pte_t pte);
void hugetlb_unshare_all_pmds(struct vm_area_struct *vma);
+void hugetlb_zero_partial_page(struct hstate *h, struct address_space *mapping,
+ loff_t start, loff_t end);
+
#else /* !CONFIG_HUGETLB_PAGE */
static inline void hugetlb_dup_vma_private(struct vm_area_struct *vma)
@@ -464,6 +467,9 @@ static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,
static inline void hugetlb_unshare_all_pmds(struct vm_area_struct *vma) { }
+static inline void hugetlb_zero_partial_page(
+ struct hstate *h, struct address_space *mapping, loff_t start, loff_t end) {}
+
#endif /* !CONFIG_HUGETLB_PAGE */
/*
* hugepages at page global directory. If arch support
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 07abcb6eb203..9c9262833b4f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -7407,6 +7407,28 @@ void hugetlb_unshare_all_pmds(struct vm_area_struct *vma)
ALIGN_DOWN(vma->vm_end, PUD_SIZE));
}
+void hugetlb_zero_partial_page(struct hstate *h,
+ struct address_space *mapping,
+ loff_t start, loff_t end)
+{
+ pgoff_t idx = start >> huge_page_shift(h);
+ struct folio *folio;
+
+ folio = filemap_lock_folio(mapping, idx);
+ if (!folio)
+ return;
+
+ start = start & ~huge_page_mask(h);
+ end = end & ~huge_page_mask(h);
+ if (!end)
+ end = huge_page_size(h);
+
+ folio_zero_segment(folio, (size_t)start, (size_t)end);
+
+ folio_unlock(folio);
+ folio_put(folio);
+}
+
#ifdef CONFIG_CMA
static bool cma_reserve_called __initdata;
--
2.41.0.rc0.172.g3f132b7071-goog
Powered by blists - more mailing lists