2021-06-30 11:23:13

by Hui Su

[permalink] [raw]
Subject: [PATCH] mm/vmpressure: replace vmpressure_to_css() with vmpressure_to_memcg()

We can get memcg directly form vmpr instead of vmpr->memcg->css->memcg,
so add a new func helper vmpressure_to_memcg().
And no code will use vmpressure_to_css(), so delete it.

Signed-off-by: Hui Su <[email protected]>
---
include/linux/vmpressure.h | 2 +-
mm/memcontrol.c | 4 ++--
mm/vmpressure.c | 3 +--
3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h
index 6d28bc433c1c..6a2f51ebbfd3 100644
--- a/include/linux/vmpressure.h
+++ b/include/linux/vmpressure.h
@@ -37,7 +37,7 @@ extern void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio);
extern void vmpressure_init(struct vmpressure *vmpr);
extern void vmpressure_cleanup(struct vmpressure *vmpr);
extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg);
-extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr);
+extern struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr);
extern int vmpressure_register_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd,
const char *args);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 64ada9e650a5..62163a9cee63 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -247,9 +247,9 @@ struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg)
return &memcg->vmpressure;
}

-struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr)
+struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr)
{
- return &container_of(vmpr, struct mem_cgroup, vmpressure)->css;
+ return container_of(vmpr, struct mem_cgroup, vmpressure);
}

#ifdef CONFIG_MEMCG_KMEM
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index d69019fc3789..04e81ac6d5d8 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -74,8 +74,7 @@ static struct vmpressure *work_to_vmpressure(struct work_struct *work)

static struct vmpressure *vmpressure_parent(struct vmpressure *vmpr)
{
- struct cgroup_subsys_state *css = vmpressure_to_css(vmpr);
- struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+ struct mem_cgroup *memcg = vmpressure_to_memcg(vmpr);

memcg = parent_mem_cgroup(memcg);
if (!memcg)
--
2.25.1


2021-06-30 12:24:18

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH] mm/vmpressure: replace vmpressure_to_css() with vmpressure_to_memcg()

On Wed 30-06-21 19:21:46, Hui Su wrote:
> We can get memcg directly form vmpr instead of vmpr->memcg->css->memcg,
> so add a new func helper vmpressure_to_memcg().
> And no code will use vmpressure_to_css(), so delete it.

Nice cleanup.

> Signed-off-by: Hui Su <[email protected]>

Acked-by: Michal Hocko <[email protected]>

Thanks!
> ---
> include/linux/vmpressure.h | 2 +-
> mm/memcontrol.c | 4 ++--
> mm/vmpressure.c | 3 +--
> 3 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h
> index 6d28bc433c1c..6a2f51ebbfd3 100644
> --- a/include/linux/vmpressure.h
> +++ b/include/linux/vmpressure.h
> @@ -37,7 +37,7 @@ extern void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio);
> extern void vmpressure_init(struct vmpressure *vmpr);
> extern void vmpressure_cleanup(struct vmpressure *vmpr);
> extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg);
> -extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr);
> +extern struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr);
> extern int vmpressure_register_event(struct mem_cgroup *memcg,
> struct eventfd_ctx *eventfd,
> const char *args);
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 64ada9e650a5..62163a9cee63 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -247,9 +247,9 @@ struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg)
> return &memcg->vmpressure;
> }
>
> -struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr)
> +struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr)
> {
> - return &container_of(vmpr, struct mem_cgroup, vmpressure)->css;
> + return container_of(vmpr, struct mem_cgroup, vmpressure);
> }
>
> #ifdef CONFIG_MEMCG_KMEM
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index d69019fc3789..04e81ac6d5d8 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -74,8 +74,7 @@ static struct vmpressure *work_to_vmpressure(struct work_struct *work)
>
> static struct vmpressure *vmpressure_parent(struct vmpressure *vmpr)
> {
> - struct cgroup_subsys_state *css = vmpressure_to_css(vmpr);
> - struct mem_cgroup *memcg = mem_cgroup_from_css(css);
> + struct mem_cgroup *memcg = vmpressure_to_memcg(vmpr);
>
> memcg = parent_mem_cgroup(memcg);
> if (!memcg)
> --
> 2.25.1

--
Michal Hocko
SUSE Labs

2021-06-30 12:34:48

by Chris Down

[permalink] [raw]
Subject: Re: [PATCH] mm/vmpressure: replace vmpressure_to_css() with vmpressure_to_memcg()

Thanks! This looks like a reasonable cleanup.

Hui Su writes:
>We can get memcg directly form vmpr instead of vmpr->memcg->css->memcg,
>so add a new func helper vmpressure_to_memcg().
>And no code will use vmpressure_to_css(), so delete it.
>
>Signed-off-by: Hui Su <[email protected]>

Acked-by: Chris Down <[email protected]>

>---
> include/linux/vmpressure.h | 2 +-
> mm/memcontrol.c | 4 ++--
> mm/vmpressure.c | 3 +--
> 3 files changed, 4 insertions(+), 5 deletions(-)
>
>diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h
>index 6d28bc433c1c..6a2f51ebbfd3 100644
>--- a/include/linux/vmpressure.h
>+++ b/include/linux/vmpressure.h
>@@ -37,7 +37,7 @@ extern void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio);
> extern void vmpressure_init(struct vmpressure *vmpr);
> extern void vmpressure_cleanup(struct vmpressure *vmpr);
> extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg);
>-extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr);
>+extern struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr);
> extern int vmpressure_register_event(struct mem_cgroup *memcg,
> struct eventfd_ctx *eventfd,
> const char *args);
>diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>index 64ada9e650a5..62163a9cee63 100644
>--- a/mm/memcontrol.c
>+++ b/mm/memcontrol.c
>@@ -247,9 +247,9 @@ struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg)
> return &memcg->vmpressure;
> }
>
>-struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr)
>+struct mem_cgroup *vmpressure_to_memcg(struct vmpressure *vmpr)
> {
>- return &container_of(vmpr, struct mem_cgroup, vmpressure)->css;
>+ return container_of(vmpr, struct mem_cgroup, vmpressure);
> }
>
> #ifdef CONFIG_MEMCG_KMEM
>diff --git a/mm/vmpressure.c b/mm/vmpressure.c
>index d69019fc3789..04e81ac6d5d8 100644
>--- a/mm/vmpressure.c
>+++ b/mm/vmpressure.c
>@@ -74,8 +74,7 @@ static struct vmpressure *work_to_vmpressure(struct work_struct *work)
>
> static struct vmpressure *vmpressure_parent(struct vmpressure *vmpr)
> {
>- struct cgroup_subsys_state *css = vmpressure_to_css(vmpr);
>- struct mem_cgroup *memcg = mem_cgroup_from_css(css);
>+ struct mem_cgroup *memcg = vmpressure_to_memcg(vmpr);
>
> memcg = parent_mem_cgroup(memcg);
> if (!memcg)
>--
>2.25.1
>
>