memcg: page_alloc: skip bulk allocator for __GFP_ACCOUNT
Subsystems (3)
PATCH 1/1 memcg: page_alloc: skip bulk allocator for __GFP_ACCOUNT
The commit 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()") switched to bulk page allocator for order 0 allocation backing vmalloc. However bulk page allocator does not support __GFP_ACCOUNT allocations and there are several users of kvmalloc(__GFP_ACCOUNT).
For now make __GFP_ACCOUNT allocations bypass bulk page allocator. In future if there is workload that can be significantly improved with the bulk page allocator with __GFP_ACCCOUNT support, we can revisit the decision.
--- mm/page_alloc.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/page_alloc.c +4 -0
@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out; +/* * Skip populated array elements to determine if any pages need * to be allocated before disabling IRQs.
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Quoted 22 lines · Shakeel Butt
The commit
5c1f4e690eec("mm/vmalloc: switch to bulk allocator in__vmalloc_area_node()") switched to bulk page allocator for order 0 allocation backing vmalloc. However bulk page allocator does not support__GFP_ACCOUNTallocations and there are several users ofkvmalloc(__GFP_ACCOUNT).For now make
__GFP_ACCOUNTallocations bypass bulk page allocator. In future if there is workload that can be significantly improved with the bulk page allocator with__GFP_ACCCOUNTsupport, we can revisit the decision.Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")Signed-off-by Shakeel Butt <[email protected]>--- mm/page_alloc.c | 4 ++++ 1 file changed, 4 insertions(+)mm/page_alloc.c +0
-0
mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5221
Quoted 7 lines
mm/page_alloc.c +4
-0@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out; +
Isn't it a bit too aggressive?
How about
if (WARN_ON_ONCE(gfp & __GFP_ACCOUNT))
gfp &= ~__GFP_ACCOUNT;And maybe with some explanatory message?
Thanks!
Quoted 34 lines · Roman Gushchin
Quoted 22 lines · Shakeel Butt
The commit
5c1f4e690eec("mm/vmalloc: switch to bulk allocator in__vmalloc_area_node()") switched to bulk page allocator for order 0 allocation backing vmalloc. However bulk page allocator does not support__GFP_ACCOUNTallocations and there are several users ofkvmalloc(__GFP_ACCOUNT).For now make
__GFP_ACCOUNTallocations bypass bulk page allocator. In future if there is workload that can be significantly improved with the bulk page allocator with__GFP_ACCCOUNTsupport, we can revisit the decision.Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")Signed-off-by Shakeel Butt <[email protected]>--- mm/page_alloc.c | 4 ++++ 1 file changed, 4 insertions(+)mm/page_alloc.c +0
-0mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5221
Quoted 7 lines
mm/page_alloc.c +4
-0@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out; +Isn't it a bit too aggressive?
Quoted 2 lines
How about
if (WARN_ON_ONCE(gfp & __GFP_ACCOUNT))
We actually know that kvmalloc(__GFP_ACCOUNT) users exist and can trigger bulk page allocator through vmalloc, so I don't think the warning would be any helpful.
Quoted 1 line
gfp &= ~__GFP_ACCOUNT;
Bulk allocator is best effort, so callers have adequate fallbacks. Transparently disabling accounting would be unexpected.
Quoted 38 lines · Shakeel Butt
Quoted 34 lines · Roman Gushchin
Quoted 22 lines · Shakeel Butt
The commit
5c1f4e690eec("mm/vmalloc: switch to bulk allocator in__vmalloc_area_node()") switched to bulk page allocator for order 0 allocation backing vmalloc. However bulk page allocator does not support__GFP_ACCOUNTallocations and there are several users ofkvmalloc(__GFP_ACCOUNT).For now make
__GFP_ACCOUNTallocations bypass bulk page allocator. In future if there is workload that can be significantly improved with the bulk page allocator with__GFP_ACCCOUNTsupport, we can revisit the decision.Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")Signed-off-by Shakeel Butt <[email protected]>--- mm/page_alloc.c | 4 ++++ 1 file changed, 4 insertions(+)mm/page_alloc.c +0
-0mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5221
Quoted 7 lines
mm/page_alloc.c +4
-0@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out; +Isn't it a bit too aggressive?
Quoted 2 lines
How about
if (WARN_ON_ONCE(gfp & __GFP_ACCOUNT))
Quoted 8 lines
We actually know that
kvmalloc(__GFP_ACCOUNT)users exist and can trigger bulk page allocator through vmalloc, so I don't think the warning would be any helpful.Quoted 1 line
gfp &= ~__GFP_ACCOUNT;Bulk allocator is best effort, so callers have adequate fallbacks. Transparently disabling accounting would be unexpected.
I see...
Shouldn't we then move this check to an upper level?
E.g.:
if (!(gfp & __GFP_ACCOUNT))
call_into_bulk_allocator();
else
call_into_per_page_allocator();
Not a big deal, I'm just worried about potential silent memory allocation failures.
Thanks!
Quoted 1 line · Roman Gushchin
[...]
Quoted 17 lines
Quoted 6 lines
Quoted 5 lines
Isn't it a bit too aggressive?
How about
if (WARN_ON_ONCE(gfp & __GFP_ACCOUNT))Quoted 8 lines
We actually know that
kvmalloc(__GFP_ACCOUNT)users exist and can trigger bulk page allocator through vmalloc, so I don't think the warning would be any helpful.Quoted 1 line
gfp &= ~__GFP_ACCOUNT;Bulk allocator is best effort, so callers have adequate fallbacks. Transparently disabling accounting would be unexpected.
I see...
Quoted 9 lines
Shouldn't we then move this check to an upper level?
E.g.:
if (!(gfp &
__GFP_ACCOUNT))
call_into_bulk_allocator();
else
call_into_per_page_allocator();
If we add this check in the upper level (e.g. in vm_area_alloc_pages() ) then I think we would need WARN_ON_ONCE(gfp & __GFP_ACCOUNT) in the bulk allocator to detect future users.
At the moment I am more inclined towards this patch's approach. Let's say in future we find there is a __GFP_ACCOUNT allocation which can benefit from bulk allocator and we decide to add such support in bulk allocator then we would not need to change the bulk allocator callers at that time just the bulk allocator.
Quoted 34 lines · Shakeel Butt
Quoted 1 line · Roman Gushchin
[...]
Quoted 17 lines
Quoted 6 lines
Quoted 5 lines
Isn't it a bit too aggressive?
How about
if (WARN_ON_ONCE(gfp & __GFP_ACCOUNT))Quoted 8 lines
We actually know that
kvmalloc(__GFP_ACCOUNT)users exist and can trigger bulk page allocator through vmalloc, so I don't think the warning would be any helpful.Quoted 1 line
gfp &= ~__GFP_ACCOUNT;Bulk allocator is best effort, so callers have adequate fallbacks. Transparently disabling accounting would be unexpected.
I see...
Quoted 9 lines
Shouldn't we then move this check to an upper level?
E.g.:
if (!(gfp &
__GFP_ACCOUNT))
call_into_bulk_allocator();
else
call_into_per_page_allocator();If we add this check in the upper level (e.g. in
vm_area_alloc_pages()) then I think we would needWARN_ON_ONCE(gfp & __GFP_ACCOUNT)in the bulk allocator to detect future users.
Quoted 5 lines
At the moment I am more inclined towards this patch's approach. Let's say in future we find there is a
__GFP_ACCOUNTallocation which can benefit from bulk allocator and we decide to add such support in bulk allocator then we would not need to change the bulk allocator callers at that time just the bulk allocator.
Ok, no objections from me.
Thanks!
Quoted 34 lines · Shakeel Butt
Quoted 1 line · Roman Gushchin
[...]
Quoted 17 lines
Quoted 6 lines
Quoted 5 lines
Isn't it a bit too aggressive?
How about
if (WARN_ON_ONCE(gfp & __GFP_ACCOUNT))Quoted 8 lines
We actually know that
kvmalloc(__GFP_ACCOUNT)users exist and can trigger bulk page allocator through vmalloc, so I don't think the warning would be any helpful.Quoted 1 line
gfp &= ~__GFP_ACCOUNT;Bulk allocator is best effort, so callers have adequate fallbacks. Transparently disabling accounting would be unexpected.
I see...
Quoted 9 lines
Shouldn't we then move this check to an upper level?
E.g.:
if (!(gfp &
__GFP_ACCOUNT))
call_into_bulk_allocator();
else
call_into_per_page_allocator();If we add this check in the upper level (e.g. in
vm_area_alloc_pages()) then I think we would needWARN_ON_ONCE(gfp & __GFP_ACCOUNT)in the bulk allocator to detect future users.
Quoted 5 lines
At the moment I am more inclined towards this patch's approach. Let's say in future we find there is a
__GFP_ACCOUNTallocation which can benefit from bulk allocator and we decide to add such support in bulk allocator then we would not need to change the bulk allocator callers at that time just the bulk allocator.
I agree with you. Let's apply the patch as-is.
Quoted 22 lines · Shakeel Butt
The commit
5c1f4e690eec("mm/vmalloc: switch to bulk allocator in__vmalloc_area_node()") switched to bulk page allocator for order 0 allocation backing vmalloc. However bulk page allocator does not support__GFP_ACCOUNTallocations and there are several users ofkvmalloc(__GFP_ACCOUNT).For now make
__GFP_ACCOUNTallocations bypass bulk page allocator. In future if there is workload that can be significantly improved with the bulk page allocator with__GFP_ACCCOUNTsupport, we can revisit the decision.Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")Signed-off-by Shakeel Butt <[email protected]>--- mm/page_alloc.c | 4 ++++ 1 file changed, 4 insertions(+)mm/page_alloc.c +0
-0
mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5221
Quoted 7 lines
mm/page_alloc.c +4
-0@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out; +
May be (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT)) check is better here?
Quoted 4 lines
mm/page_alloc.c +0
-0/* * Skip populated array elements to determine if any pages need * to be allocated before disabling IRQs.
Michal Hocko
reviewerOn Thu 14-10-21 10:05:21, Vasily Averin wrote:
[...]
Quoted 6 lines
mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5221
Quoted 4 lines
mm/page_alloc.c +4
-0+/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out; +May be (
memcg_kmem_enabled()&& (gfp &__GFP_ACCOUNT)) check is better here?
Yes please
Signature · 2 lines
Michal Hocko SUSE Labs
Michal Hocko
reviewerOn Wed 13-10-21 12:43:38, Shakeel Butt wrote:
[...]
mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5220
Quoted 11 lines
mm/page_alloc.c +3
-0@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out;
Did you mean goto failed here? This would break some which do not have any fallback. E.g. xfs_buf_alloc_pages but likely more.
Sorry I could have been more specific when talking about bypassing the bulk allocator. It is quite confusing because the bulk allocator interface consists of the bulk allocator and the fallback to the normal page allocator.
Quoted 6 lines
mm/page_alloc.c +1
-0+/* * Skip populated array elements to determine if any pages need * to be allocated before disabling IRQs. Signature · 1 line
2.33.0.882.g93a45727a2-goog
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 18 lines · Michal Hocko
On Wed 13-10-21 12:43:38, Shakeel Butt wrote:
[...]mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5220
Quoted 11 lines
mm/page_alloc.c +3
-0@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out;Did you mean goto failed here? This would break some which do not have any fallback. E.g.
xfs_buf_alloc_pagesbut likely more.
Quoted 5 lines
Sorry I could have been more specific when talking about bypassing the bulk allocator. It is quite confusing because the bulk allocator interface consists of the bulk allocator and the fallback to the normal page allocator.
I did consider 'goto failed' here but for that I have to move __GFP_ACCOUNT check after the "Already populated array" check in the function. Basically what's the point of doing other operations (incrementing nr_populated) if we are gonna skip bulk anyways.
Regarding xfs_buf_alloc_pages(), it is not using __GFP_ACCOUNT and vmalloc() is the only __GFP_ACCOUNT user at this point. So, not an issue for now but I suppose it is better to be future-proof and do the 'goto failed'.
Let me know what you think.
Michal Hocko
reviewerQuoted 25 lines · Shakeel Butt
Quoted 18 lines · Michal Hocko
On Wed 13-10-21 12:43:38, Shakeel Butt wrote:
[...]mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5220
Quoted 11 lines
mm/page_alloc.c +3
-0@@ -5215,6 +5215,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,unsigned int alloc_flags =ALLOC_WMARK_LOW ;int nr_populated =0 , nr_account =0 ; +/* Bulk allocator does not support memcg accounting. */ +if (unlikely (gfp & __GFP_ACCOUNT)) + goto out;Did you mean goto failed here? This would break some which do not have any fallback. E.g.
xfs_buf_alloc_pagesbut likely more.Quoted 5 lines
Sorry I could have been more specific when talking about bypassing the bulk allocator. It is quite confusing because the bulk allocator interface consists of the bulk allocator and the fallback to the normal page allocator.
Quoted 4 lines
I did consider 'goto failed' here but for that I have to move
__GFP_ACCOUNTcheck after the "Already populated array" check in the function. Basically what's the point of doing other operations (incrementingnr_populated) if we are gonna skip bulk anyways.
I have to say I do not follow why that is a problem.
Quoted 4 lines
Regarding
xfs_buf_alloc_pages(), it is not using__GFP_ACCOUNTandvmalloc()is the only__GFP_ACCOUNTuser at this point. So, not an issue for now but I suppose it is better to be future-proof and do the 'goto failed'.
Why do we want to have that silent trap?
Signature · 2 lines
Michal Hocko SUSE Labs
Johannes Weiner
maintainerQuoted 1 line · Shakeel Butt
Regarding
xfs_buf_alloc_pages(), it is not using__GFP_ACCOUNT
It probably should, actually. Sorry, somewhat off-topic, but we've seen this consume quite large amounts of memory. __GFP_ACCOUNT and vmstat tracking seems overdue for this one.
Quoted 6 lines · Johannes Weiner
Quoted 1 line · Shakeel Butt
Regarding
xfs_buf_alloc_pages(), it is not using__GFP_ACCOUNTIt probably should, actually. Sorry, somewhat off-topic, but we've seen this consume quite large amounts of memory.
__GFP_ACCOUNTand vmstat tracking seems overdue for this one.
If this will be required, you can use
[PATCH mm v5] memcg: enable memory accounting in __alloc_pages_bulk
https://lkml.org/lkml/2021/10/14/197
As far as I understand it will not be used right now, however I decided to submit it anyway, perhaps it may be needed later.
Thank you,
Vasily Averin