linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Roman Gushchin <guro@fb.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Shakeel Butt <shakeelb@google.com>,
	Michal Hocko <mhocko@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	kernel-team@fb.com
Subject: Re: [PATCH v1 2/4] mm: memcontrol/slab: use helpers to access slab page's memcg_data
Date: Thu, 24 Sep 2020 15:53:56 -0400	[thread overview]
Message-ID: <20200924195356.GB329853@cmpxchg.org> (raw)
In-Reply-To: <20200922203700.2879671-3-guro@fb.com>

On Tue, Sep 22, 2020 at 01:36:58PM -0700, Roman Gushchin 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>
> Reviewed-by: Shakeel Butt <shakeelb@google.com>
> ---
>  include/linux/memcontrol.h | 80 ++++++++++++++++++++++++++++++++++++++
>  mm/memcontrol.c            |  4 +-
>  mm/slab.h                  | 27 ++-----------
>  3 files changed, 85 insertions(+), 26 deletions(-)
> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 3313e7c21534..ab3ea3e90583 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -409,6 +409,86 @@ static inline void clear_page_mem_cgroup(struct page *page)
>  	page->memcg_data = 0;
>  }
>  
> +#ifdef CONFIG_MEMCG_KMEM
> +/*
> + * page_obj_cgroups - get the object cgroups vector associated with a page
> + * @page: a pointer to the page struct
> + *
> + * Returns a pointer to the object cgroups vector associated with the page,
> + * or NULL. This function assumes that the page is known to have an
> + * associated object cgroups vector. It's not safe to call this function
> + * against pages, which might have an associated memory cgroup: e.g.
> + * kernel stack pages.
> + */
> +static inline struct obj_cgroup **page_obj_cgroups(struct page *page)
> +{
> +	return (struct obj_cgroup **)(page->memcg_data & ~0x1UL);

page_mem_cgroup() has a VM_BUG_ON() if the page is in fact a slab
type. Should this also check that if memcg_data is set, it MUST have
the lower bit set?

In line with page_memcg(), I think page_objcgs() would be nicer.

As in 'memcg_reparent_objcgs()' :-) :-) :-)

> @@ -2923,7 +2923,7 @@ struct mem_cgroup *mem_cgroup_from_obj(void *p)
>  	 * Memcg membership data for each individual object is saved in
>  	 * the page->obj_cgroups.
>  	 */
> -	if (page_has_obj_cgroups(page)) {
> +	if (page_obj_cgroups_check(page)) {
>  		struct obj_cgroup *objcg;
>  		unsigned int off;

Similar to the previous patch: do we have anybody passing in objects
that aren't actual objects in the obj_cgroup sense?

  reply	other threads:[~2020-09-24 19:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 20:36 [PATCH v1 0/4] mm: allow mapping accounted kernel pages to userspace Roman Gushchin
2020-09-22 20:36 ` [PATCH v1 1/4] mm: memcontrol: use helpers to access page's memcg data Roman Gushchin
2020-09-24 19:45   ` Johannes Weiner
2020-09-24 20:27     ` Roman Gushchin
2020-09-25 17:39       ` Johannes Weiner
2020-09-22 20:36 ` [PATCH v1 2/4] mm: memcontrol/slab: use helpers to access slab page's memcg_data Roman Gushchin
2020-09-24 19:53   ` Johannes Weiner [this message]
2020-09-24 20:29     ` Roman Gushchin
2020-09-22 20:36 ` [PATCH v1 3/4] mm: introduce page memcg flags Roman Gushchin
2020-09-24  7:03   ` Shakeel Butt
2020-09-24 17:05     ` Roman Gushchin
2020-09-24 20:01   ` Johannes Weiner
2020-09-24 20:39     ` Roman Gushchin
2020-09-25 18:07       ` Johannes Weiner
2020-09-24 20:05   ` Johannes Weiner
2020-09-22 20:37 ` [PATCH v1 4/4] mm: convert page kmemcg type to a page memcg flag Roman Gushchin
2020-09-24  7:06   ` Shakeel Butt
2020-09-24 20:14   ` Johannes Weiner
2020-09-24 20:42     ` Roman Gushchin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200924195356.GB329853@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=guro@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=shakeelb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).