Skip to content

Commit ab615a5

Browse files
mjkravetztorvalds
authored andcommitted
fs/hugetlbfs/inode.c: fix hwpoison reserve accounting
Calling madvise(MADV_HWPOISON) on a hugetlbfs page will result in bad (negative) reserved huge page counts. This may not happen immediately, but may happen later when the underlying file is removed or filesystem unmounted. For example: AnonHugePages: 0 kB ShmemHugePages: 0 kB HugePages_Total: 1 HugePages_Free: 0 HugePages_Rsvd: 18446744073709551615 HugePages_Surp: 0 Hugepagesize: 2048 kB In routine hugetlbfs_error_remove_page(), hugetlb_fix_reserve_counts is called after remove_huge_page. hugetlb_fix_reserve_counts is designed to only be called/used only if a failure is returned from hugetlb_unreserve_pages. Therefore, call hugetlb_unreserve_pages as required and only call hugetlb_fix_reserve_counts in the unlikely event that hugetlb_unreserve_pages returns an error. Link: http://lkml.kernel.org/r/[email protected] Fixes: 78bb920 ("mm: hwpoison: dissolve in-use hugepage in unrecoverable memory error") Signed-off-by: Mike Kravetz <[email protected]> Acked-by: Naoya Horiguchi <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Aneesh Kumar <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 105ddc9 commit ab615a5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/hugetlbfs/inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,12 @@ static int hugetlbfs_error_remove_page(struct address_space *mapping,
842842
struct page *page)
843843
{
844844
struct inode *inode = mapping->host;
845+
pgoff_t index = page->index;
845846

846847
remove_huge_page(page);
847-
hugetlb_fix_reserve_counts(inode);
848+
if (unlikely(hugetlb_unreserve_pages(inode, index, index + 1, 1)))
849+
hugetlb_fix_reserve_counts(inode);
850+
848851
return 0;
849852
}
850853

0 commit comments

Comments
 (0)