diff mbox series

mm/memcg: fix 5.10 backport of splitting page memcg

Message ID alpine.LSU.2.11.2103281706200.4623@eggly.anvils
State New
Headers show
Series mm/memcg: fix 5.10 backport of splitting page memcg | expand

Commit Message

Hugh Dickins March 29, 2021, 12:13 a.m. UTC
The straight backport of 5.12's e1baddf8475b ("mm/memcg: set memcg when
splitting page") works fine in 5.11, but turned out to be wrong for 5.10:
because that relies on a separate flag, which must also be set for the
memcg to be recognized and uncharged and cleared when freeing. Fix that.

Signed-off-by: Hugh Dickins <hughd@google.com>
---

 mm/memcontrol.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Greg Kroah-Hartman March 29, 2021, 5:27 a.m. UTC | #1
On Sun, Mar 28, 2021 at 05:13:13PM -0700, Hugh Dickins wrote:
> The straight backport of 5.12's e1baddf8475b ("mm/memcg: set memcg when

> splitting page") works fine in 5.11, but turned out to be wrong for 5.10:

> because that relies on a separate flag, which must also be set for the

> memcg to be recognized and uncharged and cleared when freeing. Fix that.

> 

> Signed-off-by: Hugh Dickins <hughd@google.com>

> ---

> 

>  mm/memcontrol.c |    6 +++++-

>  1 file changed, 5 insertions(+), 1 deletion(-)

> 

> --- a/mm/memcontrol.c

> +++ b/mm/memcontrol.c

> @@ -3274,13 +3274,17 @@ void obj_cgroup_uncharge(struct obj_cgro

>  void split_page_memcg(struct page *head, unsigned int nr)

>  {

>  	struct mem_cgroup *memcg = head->mem_cgroup;

> +	int kmemcg = PageKmemcg(head);

>  	int i;

>  

>  	if (mem_cgroup_disabled() || !memcg)

>  		return;

>  

> -	for (i = 1; i < nr; i++)

> +	for (i = 1; i < nr; i++) {

>  		head[i].mem_cgroup = memcg;

> +		if (kmemcg)

> +			__SetPageKmemcg(head + i);

> +	}

>  	css_get_many(&memcg->css, nr - 1);

>  }

>  


Thanks for the fix, now queued up.

greg k-h
diff mbox series

Patch

--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3274,13 +3274,17 @@  void obj_cgroup_uncharge(struct obj_cgro
 void split_page_memcg(struct page *head, unsigned int nr)
 {
 	struct mem_cgroup *memcg = head->mem_cgroup;
+	int kmemcg = PageKmemcg(head);
 	int i;
 
 	if (mem_cgroup_disabled() || !memcg)
 		return;
 
-	for (i = 1; i < nr; i++)
+	for (i = 1; i < nr; i++) {
 		head[i].mem_cgroup = memcg;
+		if (kmemcg)
+			__SetPageKmemcg(head + i);
+	}
 	css_get_many(&memcg->css, nr - 1);
 }