[patch] fix hugetlbfs quota leak

Ken Chen
2008-01-11T06:24:12Z

In the error path of both shared and private hugetlb page allocation,
the file system quota is never undone, leading to fs quota leak.
Patch to fix them up.

Signed-off-by: Ken Chen <kenchen@google.com>

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 7224a4f..b2863f3 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -420,6 +420,8 @@ static struct page *alloc_huge_page_private(struct
vm_area_struct *vma,
spin_unlock(&hugetlb_lock);
if (!page)
page = alloc_buddy_huge_page(vma, addr);
+ if (!page)
+ hugetlb_put_quota(vma->vm_file->f_mapping, 1);
return page ? page : ERR_PTR(-VM_FAULT_OOM);
}

@@ -1206,8 +1208,10 @@ int hugetlb_reserve_pages(struct inode *inode,
long from, long to)
if (hugetlb_get_quota(inode->i_mapping, chg))
return -ENOSPC;
ret = hugetlb_acct_memory(chg);
- if (ret < 0)
+ if (ret < 0) {
+ hugetlb_put_quota(inode->i_mapping, chg);
return ret;
+ }
region_add(&inode->i_mapping->private_list, from, to);
return 0;
}