lkml.org 
[lkml]   [2020]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH rfc 3/5] mm: memcontrol/slab: use helpers to access slab page's memcg_data
On Thu, Sep 10, 2020 at 1:27 PM Roman Gushchin <guro@fb.com> wrote:
>
> To gather all direct accesses to struct page's memcg_data field
> in one place, let's introduce 4 new helper functions to use in
> the slab accounting code:
> struct obj_cgroup **page_obj_cgroups(struct page *page);
> struct obj_cgroup **page_obj_cgroups_check(struct page *page);
> bool set_page_obj_cgroups(struct page *page, struct obj_cgroup **objcgs);
> void clear_page_obj_cgroups(struct page *page);
>
> They are similar to the corresponding API for generic pages, except
> that the setter can return false, indicating that the value has been
> already set from a different thread.
>
> Signed-off-by: Roman Gushchin <guro@fb.com>

Nit below.

Reviewed-by: Shakeel Butt <shakeelb@google.com>

> ---
> include/linux/memcontrol.h | 48 ++++++++++++++++++++++++++++++++++++++
> mm/memcontrol.c | 4 ++--
> mm/slab.h | 27 +++------------------
> 3 files changed, 53 insertions(+), 26 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 0997220c84ce..48d4c2c1ce81 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -375,6 +375,54 @@ static inline void clear_page_mem_cgroup(struct page *page)
> page->memcg_data = 0;
> }
>

I think adding comments on these functions would be helpful.

> +#ifdef CONFIG_MEMCG_KMEM
> +static inline struct obj_cgroup **page_obj_cgroups(struct page *page)
> +{
> + return (struct obj_cgroup **)(page->memcg_data & ~0x1UL);
> +}
> +
> +static inline struct obj_cgroup **page_obj_cgroups_check(struct page *page)
> +{
> + unsigned long memcg_data = page->memcg_data;
> +
> + if (memcg_data && (memcg_data & 0x1UL))
> + return (struct obj_cgroup **)memcg_data;
> +
> + return NULL;
> +}
> +
> +static inline bool set_page_obj_cgroups(struct page *page,
> + struct obj_cgroup **objcgs)
> +{
> + return !cmpxchg(&page->memcg_data, 0, (unsigned long)objcgs | 0x1UL);
> +}
> +
> +static inline void clear_page_obj_cgroups(struct page *page)
> +{
> + page->memcg_data = 0;
> +}

\
 
 \ /
  Last update: 2020-09-17 03:14    [W:0.742 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site