Skip to content

Commit e4c6f8b

Browse files
sandeentorvalds
authored andcommitted
hugetlbfs: fix i_blocks accounting
As reported in Red Hat bz #509671, i_blocks for files on hugetlbfs get accounting wrong when doing something like: $ > foo $ date > foo date: write error: Invalid argument $ /usr/bin/stat foo File: `foo' Size: 0 Blocks: 18446744073709547520 IO Block: 2097152 regular ... This is because hugetlb_unreserve_pages() is unconditionally removing blocks_per_huge_page(h) on each call rather than using the freed amount. If there were 0 blocks, it goes negative, resulting in the above. This is a regression from commit a551643 ("hugetlb: modular state for hugetlb page size") which did: - inode->i_blocks -= BLOCKS_PER_HUGEPAGE * freed; + inode->i_blocks -= blocks_per_huge_page(h); so just put back the freed multiplier, and it's all happy again. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Acked-by: Andi Kleen <andi@firstfloor.org> Cc: William Lee Irwin III <wli@holomorphy.com> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6590981 commit e4c6f8b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/hugetlb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,7 @@ void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
23702370
long chg = region_truncate(&inode->i_mapping->private_list, offset);
23712371

23722372
spin_lock(&inode->i_lock);
2373-
inode->i_blocks -= blocks_per_huge_page(h);
2373+
inode->i_blocks -= (blocks_per_huge_page(h) * freed);
23742374
spin_unlock(&inode->i_lock);
23752375

23762376
hugetlb_put_quota(inode->i_mapping, (chg - freed));

0 commit comments

Comments
 (0)