linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] fix hugetlbfs quota leak
@ 2008-01-11  6:24 Ken Chen
  2008-01-11  9:44 ` Andrew Morton
  2008-01-11 19:03 ` Adam Litke
  0 siblings, 2 replies; 3+ messages in thread
From: Ken Chen @ 2008-01-11  6:24 UTC (permalink / raw)
  To: Andrew Morton, Adam Litke; +Cc: linux-mm

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] fix hugetlbfs quota leak
  2008-01-11  6:24 [patch] fix hugetlbfs quota leak Ken Chen
@ 2008-01-11  9:44 ` Andrew Morton
  2008-01-11 19:03 ` Adam Litke
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2008-01-11  9:44 UTC (permalink / raw)
  To: Ken Chen; +Cc: Adam Litke, linux-mm

On Thu, 10 Jan 2008 22:24:12 -0800 "Ken Chen" <kenchen@google.com> wrote:

> 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.
> 

Thanks.

> 
> 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,

Your client is wordwrapping patches.


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

The code was already fairly ugly and inefficient.  Let's improve that
rather than worsening it?

> @@ -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;
>  }


--- a/mm/hugetlb.c~hugetlbfs-fix-quota-leak
+++ a/mm/hugetlb.c
@@ -418,9 +418,14 @@ static struct page *alloc_huge_page_priv
 	if (free_huge_pages > resv_huge_pages)
 		page = dequeue_huge_page(vma, addr);
 	spin_unlock(&hugetlb_lock);
-	if (!page)
+	if (!page) {
 		page = alloc_buddy_huge_page(vma, addr);
-	return page ? page : ERR_PTR(-VM_FAULT_OOM);
+		if (!page) {
+			hugetlb_put_quota(vma->vm_file->f_mapping, 1);
+			return ERR_PTR(-VM_FAULT_OOM);
+		}
+	}
+	return page;
 }
 
 static struct page *alloc_huge_page(struct vm_area_struct *vma,
@@ -1206,8 +1211,10 @@ int hugetlb_reserve_pages(struct inode *
 	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;
 }
_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] fix hugetlbfs quota leak
  2008-01-11  6:24 [patch] fix hugetlbfs quota leak Ken Chen
  2008-01-11  9:44 ` Andrew Morton
@ 2008-01-11 19:03 ` Adam Litke
  1 sibling, 0 replies; 3+ messages in thread
From: Adam Litke @ 2008-01-11 19:03 UTC (permalink / raw)
  To: Ken Chen; +Cc: Andrew Morton, linux-mm

On Thu, 2008-01-10 at 22:24 -0800, Ken Chen wrote:
> 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>

Thanks Ken.

Acked-by: Adam Litke <agl@us.ibm.com>

-- 
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-11 18:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-11  6:24 [patch] fix hugetlbfs quota leak Ken Chen
2008-01-11  9:44 ` Andrew Morton
2008-01-11 19:03 ` Adam Litke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox