hugetlb: fix i_blocks accounting

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 <[email protected]>
Acked-by: Adam Litke <[email protected]>
Cc: Badari Pulavarty <[email protected]>
Cc: David Gibson <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
Ken Chen 2007-11-14 16:59:44 -08:00 • committed by Linus Torvalds
commit 45c682a68a
2 changed files with 12 additions and 0 deletions

View 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));
}