linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting
  2015-02-27 22:58 [RFC 0/3] hugetlbfs: optionally reserve all fs pages at mount time Mike Kravetz
@ 2015-02-27 22:58 ` Mike Kravetz
  2015-03-02 23:10   ` Andrew Morton
  2015-02-27 22:58 ` Mike Kravetz
  1 sibling, 1 reply; 6+ messages in thread
From: Mike Kravetz @ 2015-02-27 22:58 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Nadia Yvette Chambers, Andrew Morton, Davidlohr Bueso,
	Aneesh Kumar, Joonsoo Kim, Mike Kravetz

If the pages for a subpool are reserved, then the reservations have
already been accounted for in the global pool.  Therefore, when
requesting a new reservation (such as for a mapping) for the subpool
do not count again in global pool.  However, when actually allocating
a page for the subpool decrement global reserve count to correspond to
with decrement in global free pages.

Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/hugetlb.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index c6adf65..4ef8379 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -879,7 +879,7 @@ void free_huge_page(struct page *page)
 	spin_lock(&hugetlb_lock);
 	hugetlb_cgroup_uncharge_page(hstate_index(h),
 				     pages_per_huge_page(h), page);
-	if (restore_reserve)
+	if (restore_reserve || subpool_reserved(spool))
 		h->resv_huge_pages++;
 
 	if (h->surplus_huge_pages_node[nid]) {
@@ -2466,7 +2466,8 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
 	kref_put(&resv->refs, resv_map_release);
 
 	if (reserve) {
-		hugetlb_acct_memory(h, -reserve);
+		if (!subpool_reserved(spool))
+			hugetlb_acct_memory(h, -reserve);
 		hugepage_subpool_put_pages(spool, reserve);
 	}
 }
@@ -3444,10 +3445,14 @@ int hugetlb_reserve_pages(struct inode *inode,
 	 * Check enough hugepages are available for the reservation.
 	 * Hand the pages back to the subpool if there are not
 	 */
-	ret = hugetlb_acct_memory(h, chg);
-	if (ret < 0) {
-		hugepage_subpool_put_pages(spool, chg);
-		goto out_err;
+	if (subpool_reserved(spool))
+		ret = 0;
+	else {
+		ret = hugetlb_acct_memory(h, chg);
+		if (ret < 0) {
+			hugepage_subpool_put_pages(spool, chg);
+			goto out_err;
+		}
 	}
 
 	/*
@@ -3483,7 +3488,8 @@ void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
 	inode->i_blocks -= (blocks_per_huge_page(h) * freed);
 	spin_unlock(&inode->i_lock);
 
-	hugepage_subpool_put_pages(spool, (chg - freed));
+	if (!subpool_reserved(spool))
+		hugepage_subpool_put_pages(spool, (chg - freed));
 	hugetlb_acct_memory(h, -(chg - freed));
 }
 
-- 
2.1.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 related	[flat|nested] 6+ messages in thread

* [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting
  2015-02-27 22:58 [RFC 0/3] hugetlbfs: optionally reserve all fs pages at mount time Mike Kravetz
  2015-02-27 22:58 ` [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting Mike Kravetz
@ 2015-02-27 22:58 ` Mike Kravetz
  1 sibling, 0 replies; 6+ messages in thread
From: Mike Kravetz @ 2015-02-27 22:58 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Nadia Yvette Chambers, Andrew Morton, Davidlohr Bueso,
	Aneesh Kumar, Joonsoo Kim, Mike Kravetz

If the pages for a subpool are reserved, then the reservations have
already been accounted for in the global pool.  Therefore, when
requesting a new reservation (such as for a mapping) for the subpool
do not count again in global pool.  However, when actually allocating
a page for the subpool decrement gobal reserve count to correspond to
with decrement in global free pages.

Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/hugetlb.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index c6adf65..4ef8379 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -879,7 +879,7 @@ void free_huge_page(struct page *page)
 	spin_lock(&hugetlb_lock);
 	hugetlb_cgroup_uncharge_page(hstate_index(h),
 				     pages_per_huge_page(h), page);
-	if (restore_reserve)
+	if (restore_reserve || subpool_reserved(spool))
 		h->resv_huge_pages++;
 
 	if (h->surplus_huge_pages_node[nid]) {
@@ -2466,7 +2466,8 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
 	kref_put(&resv->refs, resv_map_release);
 
 	if (reserve) {
-		hugetlb_acct_memory(h, -reserve);
+		if (!subpool_reserved(spool))
+			hugetlb_acct_memory(h, -reserve);
 		hugepage_subpool_put_pages(spool, reserve);
 	}
 }
@@ -3444,10 +3445,14 @@ int hugetlb_reserve_pages(struct inode *inode,
 	 * Check enough hugepages are available for the reservation.
 	 * Hand the pages back to the subpool if there are not
 	 */
-	ret = hugetlb_acct_memory(h, chg);
-	if (ret < 0) {
-		hugepage_subpool_put_pages(spool, chg);
-		goto out_err;
+	if (subpool_reserved(spool))
+		ret = 0;
+	else {
+		ret = hugetlb_acct_memory(h, chg);
+		if (ret < 0) {
+			hugepage_subpool_put_pages(spool, chg);
+			goto out_err;
+		}
 	}
 
 	/*
@@ -3483,7 +3488,8 @@ void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
 	inode->i_blocks -= (blocks_per_huge_page(h) * freed);
 	spin_unlock(&inode->i_lock);
 
-	hugepage_subpool_put_pages(spool, (chg - freed));
+	if (!subpool_reserved(spool))
+		hugepage_subpool_put_pages(spool, (chg - freed));
 	hugetlb_acct_memory(h, -(chg - freed));
 }
 
-- 
2.1.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 related	[flat|nested] 6+ messages in thread

* Re: [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting
@ 2015-02-28  3:25 Hillf Danton
  2015-02-28 17:25 ` Mike Kravetz
  0 siblings, 1 reply; 6+ messages in thread
From: Hillf Danton @ 2015-02-28  3:25 UTC (permalink / raw)
  To: 'Mike Kravetz'
  Cc: linux-kernel, linux-mm, Andrew Morton, davidlohr,
	'Aneesh Kumar', 'Joonsoo Kim'

> @@ -3444,10 +3445,14 @@ int hugetlb_reserve_pages(struct inode *inode,
>  	 * Check enough hugepages are available for the reservation.
>  	 * Hand the pages back to the subpool if there are not
>  	 */

Better if comment is updated correspondingly.
Hillf
> -	ret = hugetlb_acct_memory(h, chg);
> -	if (ret < 0) {
> -		hugepage_subpool_put_pages(spool, chg);
> -		goto out_err;
> +	if (subpool_reserved(spool))
> +		ret = 0;
> +	else {
> +		ret = hugetlb_acct_memory(h, chg);
> +		if (ret < 0) {
> +			hugepage_subpool_put_pages(spool, chg);
> +			goto out_err;
> +		}
>  	}
> 

--
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] 6+ messages in thread

* Re: [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting
  2015-02-28  3:25 [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting Hillf Danton
@ 2015-02-28 17:25 ` Mike Kravetz
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Kravetz @ 2015-02-28 17:25 UTC (permalink / raw)
  To: Hillf Danton
  Cc: linux-kernel, linux-mm, Andrew Morton, davidlohr,
	'Aneesh Kumar', 'Joonsoo Kim'

On 02/27/2015 07:25 PM, Hillf Danton wrote:
>> @@ -3444,10 +3445,14 @@ int hugetlb_reserve_pages(struct inode *inode,
>>   	 * Check enough hugepages are available for the reservation.
>>   	 * Hand the pages back to the subpool if there are not
>>   	 */
>
> Better if comment is updated correspondingly.
> Hillf

Thanks Hillf.  I'll also take a look at other comments in the area
of 'accounting'.  As I discovered, it is only a matter of adjusting
the accounting to support reservation of pages for the entire filesystem.
-- 
Mike Kravetz

>> -	ret = hugetlb_acct_memory(h, chg);
>> -	if (ret < 0) {
>> -		hugepage_subpool_put_pages(spool, chg);
>> -		goto out_err;
>> +	if (subpool_reserved(spool))
>> +		ret = 0;
>> +	else {
>> +		ret = hugetlb_acct_memory(h, chg);
>> +		if (ret < 0) {
>> +			hugepage_subpool_put_pages(spool, chg);
>> +			goto out_err;
>> +		}
>>   	}
>>

--
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] 6+ messages in thread

* Re: [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting
  2015-02-27 22:58 ` [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting Mike Kravetz
@ 2015-03-02 23:10   ` Andrew Morton
  2015-03-03  1:30     ` Mike Kravetz
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2015-03-02 23:10 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Nadia Yvette Chambers, Davidlohr Bueso,
	Aneesh Kumar, Joonsoo Kim

On Fri, 27 Feb 2015 14:58:11 -0800 Mike Kravetz <mike.kravetz@oracle.com> wrote:

> If the pages for a subpool are reserved, then the reservations have
> already been accounted for in the global pool.  Therefore, when
> requesting a new reservation (such as for a mapping) for the subpool
> do not count again in global pool.  However, when actually allocating
> a page for the subpool decrement global reserve count to correspond to
> with decrement in global free pages.

The last sentence made my brain hurt.

--
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] 6+ messages in thread

* Re: [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting
  2015-03-02 23:10   ` Andrew Morton
@ 2015-03-03  1:30     ` Mike Kravetz
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Kravetz @ 2015-03-03  1:30 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, Nadia Yvette Chambers, Aneesh Kumar,
	Joonsoo Kim

On 03/02/2015 03:10 PM, Andrew Morton wrote:
> On Fri, 27 Feb 2015 14:58:11 -0800 Mike Kravetz <mike.kravetz@oracle.com> wrote:
>
>> If the pages for a subpool are reserved, then the reservations have
>> already been accounted for in the global pool.  Therefore, when
>> requesting a new reservation (such as for a mapping) for the subpool
>> do not count again in global pool.  However, when actually allocating
>> a page for the subpool decrement global reserve count to correspond to
>> with decrement in global free pages.
>
> The last sentence made my brain hurt.
>

Sorry.  I was trying to point out that the global free and reserve
accounting is still the same when doing a page allocation, even
though the entire size of the subpool was reserved.  For example,
when allocating a page the global free and reserve counts are both
decremented.

-- 
Mike Kravetz

--
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] 6+ messages in thread

end of thread, other threads:[~2015-03-03  1:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-28  3:25 [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting Hillf Danton
2015-02-28 17:25 ` Mike Kravetz
  -- strict thread matches above, loose matches on Subject: below --
2015-02-27 22:58 [RFC 0/3] hugetlbfs: optionally reserve all fs pages at mount time Mike Kravetz
2015-02-27 22:58 ` [RFC 2/3] hugetlbfs: coordinate global and subpool reserve accounting Mike Kravetz
2015-03-02 23:10   ` Andrew Morton
2015-03-03  1:30     ` Mike Kravetz
2015-02-27 22:58 ` Mike Kravetz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).