linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] Enable fully functional truncate for hugetlbfs
@ 2007-02-12 14:28 Dave McCracken
  2007-02-12 22:14 ` Ken Chen
  0 siblings, 1 reply; 2+ messages in thread
From: Dave McCracken @ 2007-02-12 14:28 UTC (permalink / raw)
  To: linux-mm, linux-kernel, Andrew Morton; +Cc: Adam Litke, Dave McCracken

This patch enables the full functionality of truncate for hugetlbfs
files.  Truncate was originally limited to reducing the file size
because page faults were not supported for hugetlbfs.  Now that page
faults have been implemented it is now possible to fully support
truncate.

Signed-off-by: Dave McCracken <dave.mccracken@oracle.com>

---
 inode.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

--- 2.6.20/./fs/hugetlbfs/inode.c	2007-02-04 12:44:54.000000000 -0600
+++ 2.6.20-htrunc/./fs/hugetlbfs/inode.c	2007-02-05 13:02:00.000000000 -0600
@@ -298,9 +298,10 @@ static int hugetlb_vmtruncate(struct ino
 {
 	pgoff_t pgoff;
 	struct address_space *mapping = inode->i_mapping;
+	unsigned long limit;
 
 	if (offset > inode->i_size)
-		return -EINVAL;
+		goto do_expand;
 
 	BUG_ON(offset & ~HPAGE_MASK);
 	pgoff = offset >> PAGE_SHIFT;
@@ -312,6 +313,24 @@ static int hugetlb_vmtruncate(struct ino
 	spin_unlock(&mapping->i_mmap_lock);
 	truncate_hugepages(inode, offset);
 	return 0;
+
+do_expand:
+	limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
+	if (limit != RLIM_INFINITY && offset > limit)
+		goto out_sig;
+	if (offset > inode->i_sb->s_maxbytes)
+		goto out_big;
+	if (hugetlb_reserve_pages(inode, inode->i_size >> HPAGE_SHIFT,
+				  offset >> HPAGE_SHIFT))
+		goto out_mem;
+	i_size_write(inode, offset);
+	return 0;
+out_sig:
+	send_sig(SIGXFSZ, current, 0);
+out_big:
+	return -EFBIG;
+out_mem:
+	return -ENOMEM;
 }
 
 static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] Enable fully functional truncate for hugetlbfs
  2007-02-12 14:28 [PATCH 1/1] Enable fully functional truncate for hugetlbfs Dave McCracken
@ 2007-02-12 22:14 ` Ken Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Ken Chen @ 2007-02-12 22:14 UTC (permalink / raw)
  To: Dave McCracken; +Cc: linux-mm, linux-kernel, Andrew Morton, Adam Litke

On 2/12/07, Dave McCracken <dave.mccracken@oracle.com> wrote:
> This patch enables the full functionality of truncate for hugetlbfs
> files.  Truncate was originally limited to reducing the file size
> because page faults were not supported for hugetlbfs.  Now that page
> faults have been implemented it is now possible to fully support
> truncate.

ye!

> --- 2.6.20/./fs/hugetlbfs/inode.c       2007-02-04 12:44:54.000000000 -0600
> +++ 2.6.20-htrunc/./fs/hugetlbfs/inode.c        2007-02-05 13:02:00.000000000 -0600
> +       if (hugetlb_reserve_pages(inode, inode->i_size >> HPAGE_SHIFT,
> +                                 offset >> HPAGE_SHIFT))
> +               goto out_mem;
> +       i_size_write(inode, offset);

hugetlb_reserve_pages() is used to reserve pages for shared mapping
and is used only for the size of mapping at the time of mmap().  We
shouldn't call this function when expanding hugetlb file.

- Ken

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-12 22:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-12 14:28 [PATCH 1/1] Enable fully functional truncate for hugetlbfs Dave McCracken
2007-02-12 22:14 ` Ken Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).