Commit 45c682a6 authored by Ken Chen's avatar Ken Chen Committed by Linus Torvalds
Browse files

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: default avatarKen Chen <>
Acked-by: default avatarAdam Litke <>
Cc: Badari Pulavarty <>
Cc: David Gibson <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 8cde045c
......@@ -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);
static inline int is_file_hugepages(struct file *file)
if (file->f_op == &hugetlbfs_file_operations)
......@@ -801,6 +801,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
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 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
goto retry;
goto out;
inode->i_blocks += BLOCKS_PER_HUGEPAGE;
} else
......@@ -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);
inode->i_blocks -= BLOCKS_PER_HUGEPAGE * freed;
hugetlb_put_quota(inode->i_mapping, (chg - freed));
hugetlb_acct_memory(-(chg - freed));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment