Re: [PATCH] ftruncate on huge page couldn't extend hugetlb file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2006-03-08 at 14:21, Andrew Morton wrote:
> "Zhang, Yanmin" <[email protected]> wrote:
> >
> > -	if (!prio_tree_empty(&mapping->i_mmap))
> >  -		hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
> >  -	spin_unlock(&mapping->i_mmap_lock);
> >  -	truncate_hugepages(inode, offset);
> >  +        if (offset > inode->i_size) {
> 
> whitespace is broken here.
Sorry for the stupid problem.


> 	} else {
> 
> >  +
> >  +		inode->i_size = offset;
> 
> i_size_write(), unless i_sem is held.   I guess it is, so OK.
Yes.

> 
> >  +		spin_lock(&mapping->i_mmap_lock);
> >  +		if (!prio_tree_empty(&mapping->i_mmap))
> >  +			hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
> >  +		spin_unlock(&mapping->i_mmap_lock);
> >  +		truncate_hugepages(inode, offset);
> >  +	}
> >   	return 0;

Here is the new patch.

From: Zhang Yanmin <[email protected]>

Currently, ftruncate on hugetlb files couldn't extend them. My patch enables it.

This patch is against 2.6.16-rc5-mm3 and on the top of the patch which
implements mmap on zero-length hugetlb files with PROT_NONE.

Thanks for Ken's good idea.

Signed-off-by: Zhang Yanmin <[email protected]>

---

diff -Nraup linux-2.6.16-rc5-mm3_huge_check/fs/hugetlbfs/inode.c linux-2.6.16-rc5-mm3_truncate/fs/hugetlbfs/inode.c
--- linux-2.6.16-rc5-mm3_huge_check/fs/hugetlbfs/inode.c	2006-03-08 18:17:15.000000000 +0800
+++ linux-2.6.16-rc5-mm3_truncate/fs/hugetlbfs/inode.c	2006-03-08 22:43:54.000000000 +0800
@@ -308,18 +308,20 @@ static int hugetlb_vmtruncate(struct ino
 	unsigned long pgoff;
 	struct address_space *mapping = inode->i_mapping;
 
-	if (offset > inode->i_size)
-		return -EINVAL;
-
 	BUG_ON(offset & ~HPAGE_MASK);
 	pgoff = offset >> HPAGE_SHIFT;
-
-	inode->i_size = offset;
-	spin_lock(&mapping->i_mmap_lock);
-	if (!prio_tree_empty(&mapping->i_mmap))
-		hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
-	spin_unlock(&mapping->i_mmap_lock);
-	truncate_hugepages(inode, offset);
+	if (offset > inode->i_size) {
+		if (hugetlb_extend_reservation(HUGETLBFS_I(inode), pgoff) != 0)
+			return -ENOMEM;
+		inode->i_size = offset;
+	} else {
+		inode->i_size = offset;
+		spin_lock(&mapping->i_mmap_lock);
+		if (!prio_tree_empty(&mapping->i_mmap))
+			hugetlb_vmtruncate_list(&mapping->i_mmap, pgoff);
+		spin_unlock(&mapping->i_mmap_lock);
+		truncate_hugepages(inode, offset);
+	}
 	return 0;
 }
 


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux