cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Glauber Costa <glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
	kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org,
	Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	Greg Thelen <gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Suleiman Souhlal
	<suleiman-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>,
	Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
	devel-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org,
	David Rientjes <rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Christoph Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>,
	Pekka Enberg <penberg-bbCR+/B0CizivPeTLB3BmA@public.gmane.org>
Subject: Re: [PATCH v3 16/28] memcg: kmem controller charge/uncharge infrastructure
Date: Wed, 30 May 2012 15:04:18 +0200	[thread overview]
Message-ID: <20120530130416.GD25094@somewhere.redhat.com> (raw)
In-Reply-To: <1337951028-3427-17-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>

On Fri, May 25, 2012 at 05:03:36PM +0400, Glauber Costa wrote:
> +struct kmem_cache *__mem_cgroup_get_kmem_cache(struct kmem_cache *cachep,
> +					     gfp_t gfp)
> +{
> +	struct mem_cgroup *memcg;
> +	int idx;
> +	struct task_struct *p;
> +
> +	gfp |=  cachep->allocflags;
> +
> +	if (cachep->memcg_params.memcg)
> +		return cachep;
> +
> +	idx = cachep->memcg_params.id;
> +	VM_BUG_ON(idx == -1);
> +
> +	p = rcu_dereference(current->mm->owner);
> +	memcg = mem_cgroup_from_task(p);
> +
> +	if (!mem_cgroup_kmem_enabled(memcg))
> +		return cachep;
> +
> +	if (memcg->slabs[idx] == NULL) {
> +		memcg_create_cache_enqueue(memcg, cachep);
> +		return cachep;
> +	}
> +
> +	return memcg->slabs[idx];
> +}
> +EXPORT_SYMBOL(__mem_cgroup_get_kmem_cache);
> +
> +bool __mem_cgroup_new_kmem_page(struct page *page, gfp_t gfp)
> +{
> +	struct mem_cgroup *memcg;
> +	struct page_cgroup *pc;
> +	bool ret = true;
> +	size_t size;
> +	struct task_struct *p;
> +
> +	if (!current->mm || in_interrupt())
> +		return true;
> +
> +	rcu_read_lock();
> +	p = rcu_dereference(current->mm->owner);
> +	memcg = mem_cgroup_from_task(p);
> +
> +	if (!mem_cgroup_kmem_enabled(memcg))
> +		goto out;

Do you think it's possible that this memcg can be destroyed (like ss->destroy())
concurrently?

Probably not because there is a synchronize_rcu() in cgroup_diput() so as long
as we are in rcu_read_lock() we are fine.

OTOH current->mm->owner can exit() right after we fetched its memcg and thus the css_set
can be freed concurrently? And then the cgroup itself after we call rcu_read_unlock()
due to cgroup_diput().
And yet we are doing the mem_cgroup_get() below unconditionally assuming it's
always fine to get a reference to it.

May be I'm missing something?


> +	mem_cgroup_get(memcg);
> +
> +	size = (1 << compound_order(page)) << PAGE_SHIFT;
> +
> +	ret = memcg_charge_kmem(memcg, gfp, size) == 0;
> +	if (!ret) {
> +		mem_cgroup_put(memcg);
> +		goto out;
> +	}
> +
> +	pc = lookup_page_cgroup(page);
> +	lock_page_cgroup(pc);
> +	pc->mem_cgroup = memcg;
> +	SetPageCgroupUsed(pc);
> +	unlock_page_cgroup(pc);
> +
> +out:
> +	rcu_read_unlock();
> +	return ret;
> +}
> +EXPORT_SYMBOL(__mem_cgroup_new_kmem_page);

  parent reply	other threads:[~2012-05-30 13:04 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25 13:03 [PATCH v3 00/28] kmem limitation for memcg Glauber Costa
     [not found] ` <1337951028-3427-1-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-25 13:03   ` [PATCH v3 01/28] slab: move FULL state transition to an initcall Glauber Costa
2012-05-25 13:03   ` [PATCH v3 02/28] memcg: Always free struct memcg through schedule_work() Glauber Costa
2012-05-25 13:03   ` [PATCH v3 03/28] slab: rename gfpflags to allocflags Glauber Costa
2012-05-25 13:03   ` [PATCH v3 04/28] memcg: Make it possible to use the stock for more than one page Glauber Costa
2012-05-25 13:03   ` [PATCH v3 05/28] memcg: Reclaim when more than one page needed Glauber Costa
2012-05-29 14:19     ` Christoph Lameter
2012-05-29 14:20       ` Christoph Lameter
     [not found]         ` <alpine.DEB.2.00.1205290919130.4666-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 15:45           ` Glauber Costa
2012-05-25 13:03   ` [PATCH v3 06/28] slab: use obj_size field of struct kmem_cache when not debugging Glauber Costa
2012-05-25 13:03   ` [PATCH v3 07/28] memcg: change defines to an enum Glauber Costa
2012-05-25 13:03   ` [PATCH v3 08/28] res_counter: don't force return value checking in res_counter_charge_nofail Glauber Costa
2012-05-25 13:03   ` [PATCH v3 09/28] kmem slab accounting basic infrastructure Glauber Costa
2012-05-25 13:03   ` [PATCH v3 10/28] slab/slub: struct memcg_params Glauber Costa
2012-05-25 13:03   ` [PATCH v3 11/28] slub: consider a memcg parameter in kmem_create_cache Glauber Costa
2012-05-25 13:03   ` [PATCH v3 12/28] slab: pass memcg parameter to kmem_cache_create Glauber Costa
     [not found]     ` <1337951028-3427-13-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 14:27       ` Christoph Lameter
     [not found]         ` <alpine.DEB.2.00.1205290922340.4666-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 15:50           ` Glauber Costa
2012-05-29 16:33             ` Christoph Lameter
     [not found]               ` <alpine.DEB.2.00.1205291131590.6723-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 16:36                 ` Glauber Costa
     [not found]                   ` <4FC4FAF6.8060900-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 16:52                     ` Christoph Lameter
     [not found]                       ` <alpine.DEB.2.00.1205291149280.8406-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 16:59                         ` Glauber Costa
2012-05-30 11:01                         ` Frederic Weisbecker
2012-05-25 13:03   ` [PATCH v3 13/28] slub: create duplicate cache Glauber Costa
     [not found]     ` <1337951028-3427-14-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 14:36       ` Christoph Lameter
2012-05-29 15:56         ` Glauber Costa
     [not found]           ` <4FC4F1A7.2010206-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 16:05             ` Christoph Lameter
2012-05-29 17:05               ` Glauber Costa
     [not found]                 ` <4FC501E9.60607-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 17:25                   ` Christoph Lameter
     [not found]                     ` <alpine.DEB.2.00.1205291222360.8495-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 17:27                       ` Glauber Costa
2012-05-29 19:26                         ` Christoph Lameter
     [not found]                           ` <alpine.DEB.2.00.1205291424130.8495-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 19:40                             ` Glauber Costa
     [not found]                               ` <4FC52612.5060006-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 19:55                                 ` Christoph Lameter
     [not found]                                   ` <alpine.DEB.2.00.1205291454030.2504-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 20:08                                     ` Glauber Costa
2012-05-29 20:21                                       ` Christoph Lameter
2012-05-29 20:25                                         ` Glauber Costa
     [not found]                                           ` <4FC530C0.30509-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-30  1:29                                             ` Tejun Heo
     [not found]                                               ` <20120530012955.GA4854-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-05-30  7:28                                                 ` [Devel] " James Bottomley
2012-05-30  7:54                                               ` Glauber Costa
     [not found]                                                 ` <4FC5D228.2070100-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-30  8:02                                                   ` Tejun Heo
2012-05-30 15:37                                                     ` Christoph Lameter
2012-05-29 20:57                                         ` Suleiman Souhlal
2012-05-25 13:03   ` [PATCH v3 14/28] slab: " Glauber Costa
2012-05-25 13:03   ` [PATCH v3 15/28] slub: always get the cache from its page in kfree Glauber Costa
     [not found]     ` <1337951028-3427-16-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 14:42       ` Christoph Lameter
     [not found]         ` <alpine.DEB.2.00.1205290939540.4666-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 15:59           ` Glauber Costa
2012-05-25 13:03   ` [PATCH v3 16/28] memcg: kmem controller charge/uncharge infrastructure Glauber Costa
2012-05-29 14:47     ` Christoph Lameter
2012-05-29 16:00       ` Glauber Costa
     [not found]     ` <1337951028-3427-17-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-30 12:17       ` Frederic Weisbecker
     [not found]         ` <20120530121706.GB25094-oHC15RC7JGTpAmv0O++HtFaTQe2KTcn/@public.gmane.org>
2012-05-30 12:26           ` Glauber Costa
2012-05-30 12:34       ` Frederic Weisbecker
     [not found]         ` <20120530123406.GC25094-oHC15RC7JGTpAmv0O++HtFaTQe2KTcn/@public.gmane.org>
2012-05-30 12:38           ` Glauber Costa
     [not found]             ` <4FC614CF.5000906-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-30 13:11               ` Frederic Weisbecker
     [not found]                 ` <20120530131059.GE25094-oHC15RC7JGTpAmv0O++HtFaTQe2KTcn/@public.gmane.org>
2012-05-30 13:09                   ` Glauber Costa
2012-05-30 13:04       ` Frederic Weisbecker [this message]
2012-05-30 13:06         ` Glauber Costa
2012-05-30 13:37           ` Frederic Weisbecker
2012-05-30 13:37             ` Glauber Costa
2012-05-30 13:53               ` Frederic Weisbecker
2012-05-30 13:55                 ` Glauber Costa
     [not found]                   ` <4FC626DA.3030408-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-30 15:33                     ` Frederic Weisbecker
     [not found]                       ` <20120530153256.GA27008-oHC15RC7JGTpAmv0O++HtFaTQe2KTcn/@public.gmane.org>
2012-05-30 16:16                         ` Glauber Costa
2012-05-25 13:03   ` [PATCH v3 17/28] skip memcg kmem allocations in specified code regions Glauber Costa
2012-05-25 13:03   ` [PATCH v3 18/28] slub: charge allocation to a memcg Glauber Costa
     [not found]     ` <1337951028-3427-19-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 14:51       ` Christoph Lameter
     [not found]         ` <alpine.DEB.2.00.1205290948250.4666-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 16:06           ` Glauber Costa
2012-05-25 13:03   ` [PATCH v3 19/28] slab: per-memcg accounting of slab caches Glauber Costa
     [not found]     ` <1337951028-3427-20-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 14:52       ` Christoph Lameter
     [not found]         ` <alpine.DEB.2.00.1205290951520.4666-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 16:07           ` Glauber Costa
     [not found]             ` <4FC4F42D.6060601-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 16:13               ` Glauber Costa
2012-05-25 13:03   ` [PATCH v3 20/28] memcg: disable kmem code when not in use Glauber Costa
2012-05-25 13:03   ` [PATCH v3 21/28] memcg: destroy memcg caches Glauber Costa
2012-05-25 13:03   ` [PATCH v3 22/28] memcg/slub: shrink dead caches Glauber Costa
2012-05-25 13:03   ` [PATCH v3 23/28] slab: Track all the memcg children of a kmem_cache Glauber Costa
2012-05-25 13:03   ` [PATCH v3 24/28] memcg: Per-memcg memory.kmem.slabinfo file Glauber Costa
2012-05-25 13:03   ` [PATCH v3 25/28] slub: create slabinfo file for memcg Glauber Costa
2012-05-25 13:03   ` [PATCH v3 26/28] slub: track all children of a kmem cache Glauber Costa
2012-05-25 13:03 ` [PATCH v3 27/28] memcg: propagate kmem limiting information to children Glauber Costa
2012-05-25 13:03 ` [PATCH v3 28/28] Documentation: add documentation for slab tracker for memcg Glauber Costa
2012-05-25 13:34 ` [PATCH v3 00/28] kmem limitation " Michal Hocko
2012-05-25 14:34   ` Christoph Lameter
2012-05-28  8:32     ` Glauber Costa
2012-05-29 15:07       ` Christoph Lameter
     [not found]         ` <alpine.DEB.2.00.1205290955270.4666-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2012-05-29 15:44           ` Glauber Costa
     [not found]             ` <4FC4EEF6.2050204-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2012-05-29 16:01               ` Christoph Lameter
2012-06-07 10:26 ` Frederic Weisbecker
2012-06-07 10:53   ` Glauber Costa
2012-06-07 14:00     ` Frederic Weisbecker
2012-06-14  2:24       ` Kamezawa Hiroyuki

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=20120530130416.GD25094@somewhere.redhat.com \
    --to=fweisbec-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org \
    --cc=devel-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org \
    --cc=glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org \
    --cc=gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
    --cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
    --cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
    --cc=penberg-bbCR+/B0CizivPeTLB3BmA@public.gmane.org \
    --cc=rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=suleiman-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /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).