On Mon, Jun 13, 2022 at 07:30:22PM +0100”, Matthew Wilcox wrote: > On Mon, Jun 13, 2022 at 11:08:58AM -0700, Mike Kravetz wrote: > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > > index eca1d0fabd7e..b0d0947a7e9b 100644 > > --- a/fs/hugetlbfs/inode.c > > +++ b/fs/hugetlbfs/inode.c > > @@ -584,41 +584,79 @@ 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, > > + unsigned long start, > > This should be loff_t. Otherwise we can truncate on 32-bit machines. > Thanks! I missed that. > > + unsigned long end) > > +{ > > + pgoff_t idx = start >> huge_page_shift(h); > > + struct page *page; > > + > > + page = find_lock_page(mapping, idx); > > + if (!page) > > + return; > > + > > + start = start & ~huge_page_mask(h); > > + end = end & ~huge_page_mask(h); > > + if (!end) > > + end = huge_page_size(h); > > + > > + zero_user_segment(page, (unsigned int)start, (unsigned int)end); > > + > > + unlock_page(page); > > + put_page(page); > > We haven't started converting hugetlbfs to folios yet, but here's how > that would look (which will save us converting it later): > > folio = filemap_lock_folio(mapping, idx); > if (!folio) > return; > ... > folio_zero_segment(folio, start, end); > folio_unlock(folio); > folio_put(folio); > > Pretty much a 1-for-1 replacement. > Great. The folio conversion is on my todo list, but I would not be offended if someone beat me to it. -- Mike Kravetz