Skip to contentSkip to conversation

memcg: page_alloc: skip bulk allocator for __GFP_ACCOUNT

PATCH Applied Shakeel Butt 6 participants 6 messages Oct 14, 2021 – Oct 15, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")

---
Changes since v1:
- do fallback allocation instead of failure, suggested by Michal Hocko.
- Added memcg_kmem_enabled() check, corrected by Vasily Averin

 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/page_alloc.c +4 -0
index 668edb16446a..9ca871dc8602 100644
@@ -5230,6 +5230,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	if (unlikely(page_array && nr_pages - nr_populated == 0))
 		goto out;
 
+	/* Bulk allocator does not support memcg accounting. */
+	if (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT))
+		goto failed;
+
 	/* Use the single page allocator for one page. */
 	if (nr_pages - nr_populated == 1)
 		goto failed;
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Acked-by on v2 1/1
#1 lore raw
Quoted 27 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_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.

Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")

---
Changes since v1:
- do fallback allocation instead of failure, suggested by Michal Hocko.
- Added memcg_kmem_enabled() check, corrected by Vasily Averin

 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/page_alloc.c +0 -0
index 668edb16446a..9ca871dc8602 100644

mm/page_alloc.c unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, · line 5239

Quoted 10 lines
mm/page_alloc.c +4 -0
@@ -5230,6 +5230,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	if (unlikely(page_array && nr_pages - nr_populated == 0))
 		goto out;
 
+	/* Bulk allocator does not support memcg accounting. */
+	if (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT))
+		goto failed;
+
 	/* Use the single page allocator for one page. */
 	if (nr_pages - nr_populated == 1)
 		goto failed;

LGTM

Signature · 3 lines
Thanks,

David / dhildenb
reviewer Acked-by on v2 1/1
#2 lore raw
In reply to Shakeel Butt
Quoted 7 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_ACCOUNT allocations and there are several users of kvmalloc(__GFP_ACCOUNT).

For now make __GFP_ACCOUNT allocations bypass bulk page allocator. In

I would go with
For now make __GFP_ACCOUNT allocations bypass the fast path of the bulk allocator and make it fallback to the regular page allocator as if the former failed.

Quoted 6 lines

future if there is workload that can be significantly improved with the bulk page allocator with __GFP_ACCCOUNT support, we can revisit the decision.

Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")

Thanks!

Quoted 25 lines

---
Changes since v1:
- do fallback allocation instead of failure, suggested by Michal Hocko.
- Added memcg_kmem_enabled() check, corrected by Vasily Averin

 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/page_alloc.c +4 -0
index 668edb16446a..9ca871dc8602 100644
@@ -5230,6 +5230,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	if (unlikely(page_array && nr_pages - nr_populated == 0))
 		goto out;
 
+	/* Bulk allocator does not support memcg accounting. */
+	if (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT))
+		goto failed;
+
 	/* Use the single page allocator for one page. */
 	if (nr_pages - nr_populated == 1)
 		goto failed;
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Signature · 2 lines
Michal Hocko
SUSE Labs
Acked-by on v2 1/1
#3 lore raw
In reply to Shakeel Butt
Quoted 11 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_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.

Quoted 5 lines
Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")

---
Changes since v1:
- do fallback allocation instead of failure, suggested by Michal Hocko.

This looks indeed better! Thanks!

Quoted 22 lines
 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/page_alloc.c +4 -0
index 668edb16446a..9ca871dc8602 100644
@@ -5230,6 +5230,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	if (unlikely(page_array && nr_pages - nr_populated == 0))
 		goto out;
 
+	/* Bulk allocator does not support memcg accounting. */
+	if (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT))
+		goto failed;
+
 	/* Use the single page allocator for one page. */
 	if (nr_pages - nr_populated == 1)
 		goto failed;
Signature · 1 line
2.33.0.882.g93a45727a2-goog
maintainer Acked-by on v2 1/1
#4 lore raw
In reply to Shakeel Butt
Quoted 6 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_ACCOUNT allocations and there are several users of kvmalloc(__GFP_ACCOUNT).

Quoted 7 lines

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.

Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")
#5 lore raw
In reply to Shakeel Butt
Quoted 6 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_ACCOUNT allocations and there are several users of kvmalloc(__GFP_ACCOUNT).

Quoted 7 lines

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.

Fixes 5c1f4e690eec ("mm/vmalloc: switch to bulk allocator in __vmalloc_area_node()")
Reported-and-tested-by Vasily Averin <[email protected]>
Quoted 24 lines

---
Changes since v1:
- do fallback allocation instead of failure, suggested by Michal Hocko.
- Added memcg_kmem_enabled() check, corrected by Vasily Averin

 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/page_alloc.c +4 -0
index 668edb16446a..9ca871dc8602 100644
@@ -5230,6 +5230,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	if (unlikely(page_array && nr_pages - nr_populated == 0))
 		goto out;
 
+	/* Bulk allocator does not support memcg accounting. */
+	if (memcg_kmem_enabled() && (gfp & __GFP_ACCOUNT))
+		goto failed;
+
 	/* Use the single page allocator for one page. */
 	if (nr_pages - nr_populated == 1)
 		goto failed;