hugetlb: fix i_blocks accounting
authorKen Chen <kenchen@google.com>
Thu, 15 Nov 2007 00:59:44 +0000 (16:59 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Thu, 15 Nov 2007 02:45:40 +0000 (18:45 -0800)
For administrative purpose, we want to query actual block usage for
hugetlbfs file via fstat.  Currently, hugetlbfs always return 0.  Fix that
up since kernel already has all the information to track it properly.

Signed-off-by: Ken Chen <kenchen@google.com>
Acked-by: Adam Litke <agl@us.ibm.com>
Cc: Badari Pulavarty <pbadari@us.ibm.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/hugetlb.h
mm/hugetlb.c

index 8104e5af75abd28225c0c98869f7264eba44beb3..24968790bc3e3c451f178a1605e9eecb01acf918 100644 (file)
@@ -168,6 +168,8 @@ struct file *hugetlb_file_setup(const char *name, size_t);
 int hugetlb_get_quota(struct address_space *mapping, long delta);
 void hugetlb_put_quota(struct address_space *mapping, long delta);
 
+#define BLOCKS_PER_HUGEPAGE    (HPAGE_SIZE / 512)
+
 static inline int is_file_hugepages(struct file *file)
 {
        if (file->f_op == &hugetlbfs_file_operations)
index abe1e9f2a942281df9707530610dc0b3c349ac04..6121b57bbe966735a6c44ae1f77854f2cec7c74b 100644 (file)
@@ -801,6 +801,7 @@ retry:
 
                if (vma->vm_flags & VM_SHARED) {
                        int err;
+                       struct inode *inode = mapping->host;
 
                        err = add_to_page_cache(page, mapping, idx, GFP_KERNEL);
                        if (err) {
@@ -809,6 +810,10 @@ retry:
                                        goto retry;
                                goto out;
                        }
+
+                       spin_lock(&inode->i_lock);
+                       inode->i_blocks += BLOCKS_PER_HUGEPAGE;
+                       spin_unlock(&inode->i_lock);
                } else
                        lock_page(page);
        }
@@ -1160,6 +1165,11 @@ int hugetlb_reserve_pages(struct inode *inode, long from, long to)
 void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
 {
        long chg = region_truncate(&inode->i_mapping->private_list, offset);
+
+       spin_lock(&inode->i_lock);
+       inode->i_blocks -= BLOCKS_PER_HUGEPAGE * freed;
+       spin_unlock(&inode->i_lock);
+
        hugetlb_put_quota(inode->i_mapping, (chg - freed));
        hugetlb_acct_memory(-(chg - freed));
 }