Linux Container Development
 help / color / mirror / Atom feed
From: Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
To: balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Cc: Linux Containers
	<containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>,
	Christoph Lameter <clameter-sJ/iWh9BUns@public.gmane.org>
Subject: Re: [PATCH 1/5] Add notification about some major slab events
Date: Mon, 01 Oct 2007 16:13:43 +0400	[thread overview]
Message-ID: <4700E477.2060607@openvz.org> (raw)
In-Reply-To: <4700E03B.6000102-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>

Balbir Singh wrote:
> Pavel Emelyanov wrote:
>> According to Christoph, there are already multiple people who 
>> want to control slab allocations and track memory for various 
>> reasons. So this is an introduction of such a hooks.
>>
>> Currently, functions that are to call the notifiers are empty
>> and marked as "weak". Thus, if there's only _one_ listener
>> to these events, it can happily link with the vmlinux and
>> handle the events with more than 10% of performance saved.
>>
> 
> Please check that weak objects work across platforms. Please see
> http://www.ussg.iu.edu/hypermail/linux/kernel/0706.0/0593.html

OK.

>> The events tracked are:
>> 1. allocation of an object;
>> 2. freeing of an object;
>> 3. allocation of a new page for objects;
>> 4. freeing this page.
>>
>> More events can be added on demand.
>>
>> The kmem cache marked with SLAB_NOTIFY flag will cause all the
>> events above to generate notifications. By default no caches
>> come with this flag.
>>
>> The events are generated on slow paths only and as soon as the
>> cache is marked as SLAB_NOTIFY, it will always use them for
>> allocation.
>>
>> Signed-off-by: Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
>>
>> ---
>>
>> diff --git a/include/linux/slab.h b/include/linux/slab.h
>> index f3a8eec..68d8e65 100644
>> --- a/include/linux/slab.h
>> +++ b/include/linux/slab.h
>> @@ -28,6 +28,7 @@
>>  #define SLAB_DESTROY_BY_RCU	0x00080000UL	/* Defer freeing slabs to RCU */
>>  #define SLAB_MEM_SPREAD		0x00100000UL	/* Spread some memory over cpuset */
>>  #define SLAB_TRACE		0x00200000UL	/* Trace allocations and frees */
>> +#define SLAB_NOTIFY		0x00400000UL	/* Notify major events */
>>
>>  /* The following flags affect the page allocator grouping pages by mobility */
>>  #define SLAB_RECLAIM_ACCOUNT	0x00020000UL		/* Objects are reclaimable */
>> diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
>> index 40801e7..8cfd9ff 100644
>> --- a/include/linux/slub_def.h
>> +++ b/include/linux/slub_def.h
>> @@ -200,4 +203,22 @@ static __always_inline void *kmalloc_nod
>>  }
>>  #endif
>>
>> +struct slub_notify_struct {
>> +	struct kmem_cache *cachep;
>> +	void *objp;
>> +	gfp_t gfp;
>> +};
>> +
>> +enum {
>> +	SLUB_ON,
>> +	SLUB_OFF,
>> +	SLUB_ALLOC,
>> +	SLUB_FREE,
>> +	SLUB_NEWPAGE,
>> +	SLUB_FREEPAGE,
>> +};
>> +
>> +int slub_register_notifier(struct notifier_block *nb);
>> +void slub_unregister_notifier(struct notifier_block *nb);
>> +
>>  #endif /* _LINUX_SLUB_DEF_H */
>> diff --git a/mm/slub.c b/mm/slub.c
>> index 31d04a3..e066a0e 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -1040,6 +1040,43 @@ static inline unsigned long kmem_cache_f
>>  }
>>  #define slub_debug 0
>>  #endif
>> +
>> +/*
>> + * notifiers
>> + */
>> +
>> +int __attribute__ ((weak)) slub_alloc_notify(struct kmem_cache *cachep,
>> +		void *obj, gfp_t gfp)
>> +{
>> +	return 0;
>> +}
>> +
>> +void __attribute__ ((weak)) slub_free_notify(struct kmem_cache *cachep,
>> +		void *obj)
>> +{
>> +}
>> +
>> +int __attribute__ ((weak)) slub_newpage_notify(struct kmem_cache *cachep,
>> +		struct page *pg, gfp_t gfp)
>> +{
>> +	return 0;
>> +}
>> +
>> +void __attribute__ ((weak)) slub_freepage_notify(struct kmem_cache *cachep,
>> +		struct page *pg)
>> +{
>> +}
>> +
>> +int __attribute__ ((weak)) slub_on_notify(struct kmem_cache *cachep)
>> +{
>> +	return 0;
>> +}
>> +
>> +int __attribute__ ((weak)) slub_off_notify(struct kmem_cache *cachep)
>> +{
>> +	return 0;
>> +}
>> +
>>  /*
>>   * Slab allocation and freeing
>>   */
>> @@ -1063,7 +1184,11 @@ static struct page *allocate_slab(struct
>>  		page = alloc_pages_node(node, flags, s->order);
>>
>>  	if (!page)
>> -		return NULL;
>> +		goto out;
>> +
>> +	if ((s->flags & SLAB_NOTIFY) &&
>> +			slub_newpage_notify(s, page, flags) < 0)
>> +		goto out_free;
>>
>>  	mod_zone_page_state(page_zone(page),
>>  		(s->flags & SLAB_RECLAIM_ACCOUNT) ?
>> @@ -1071,6 +1196,11 @@ static struct page *allocate_slab(struct
>>  		pages);
>>
>>  	return page;
>> +
>> +out_free:
>> +	__free_pages(page, s->order);
> 
> allocate_slab fails if sub_newpage_notify() fails? Sounds a bit

Yup. If we try to allocate some meta info for this page and fail,
what shall we do? Fail only!

> harsh, hard to review since the definition of the above function
> is not known.

What do you mean by "not known"? I is declared above :)

>> +out:
>> +	return NULL;
>>  }
>>
>>  static void setup_object(struct kmem_cache *s, struct page *page,
>> @@ -1103,7 +1233,7 @@ static struct page *new_slab(struct kmem
>>  	page->slab = s;
>>  	page->flags |= 1 << PG_slab;
>>  	if (s->flags & (SLAB_DEBUG_FREE | SLAB_RED_ZONE | SLAB_POISON |
>> -			SLAB_STORE_USER | SLAB_TRACE))
>> +			SLAB_STORE_USER | SLAB_TRACE | SLAB_NOTIFY))
>>  		SetSlabDebug(page);
>>
>>  	start = page_address(page);
>> @@ -1158,6 +1288,9 @@ static void rcu_free_slab(struct rcu_hea
>>
>>  static void free_slab(struct kmem_cache *s, struct page *page)
>>  {
>> +	if (s->flags & SLAB_NOTIFY)
>> +		slub_freepage_notify(s, page);
>> +
>>  	if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
>>  		/*
>>  		 * RCU free overloads the RCU head over the LRU
>> @@ -1548,9 +1681,16 @@ debug:
>>  	if (!alloc_debug_processing(s, c->page, object, addr))
>>  		goto another_slab;
>>
>> +	if ((s->flags & SLAB_NOTIFY) &&
>> +			slub_alloc_notify(s, object, gfpflags) < 0) {
>> +		object = NULL;
>> +		goto out;
>> +	}
>> +
>>  	c->page->inuse++;
>>  	c->page->freelist = object[c->offset];
>>  	c->node = -1;
>> +out:
>>  	slab_unlock(c->page);
>>  	return object;
>>  }
>> @@ -1659,6 +1799,10 @@ slab_empty:
>>  debug:
>>  	if (!free_debug_processing(s, page, x, addr))
>>  		goto out_unlock;
>> +
>> +	if (s->flags & SLAB_NOTIFY)
>> +		slub_free_notify(s, x);
>> +
>>  	goto checks_ok;
>>  }
>>
>>
> 
> 

  parent reply	other threads:[~2007-10-01 12:13 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-25 14:16 [PATCH 0/5] Kernel memory accounting container (v5) Pavel Emelyanov
     [not found] ` <46F91841.9070708-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-25 14:18   ` [PATCH 1/5] Add notification about some major slab events Pavel Emelyanov
     [not found]     ` <46F91898.5060400-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-25 21:47       ` Christoph Lameter
     [not found]         ` <Pine.LNX.4.64.0709251445400.5072-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-26  9:37           ` Pavel Emelyanov
     [not found]             ` <46FA285B.5060709-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-26 17:31               ` Christoph Lameter
     [not found]                 ` <Pine.LNX.4.64.0709261030270.15435-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-27  8:25                   ` Pavel Emelyanov
2007-10-01 11:55       ` Balbir Singh
     [not found]         ` <4700E03B.6000102-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 12:13           ` Pavel Emelyanov [this message]
     [not found]             ` <4700E477.2060607-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 12:32               ` Balbir Singh
     [not found]                 ` <4700E8F2.7000206-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 12:57                   ` Pavel Emelyanov
     [not found]                     ` <4700EEAE.1090208-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 13:03                       ` Balbir Singh
2007-09-25 14:19   ` [PATCH 2/5] Generic notifiers for SLUB events Pavel Emelyanov
     [not found]     ` <46F918D9.3020406-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 13:05       ` Balbir Singh
     [not found]         ` <4700F083.1070706-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 13:07           ` Pavel Emelyanov
     [not found]             ` <4700F120.2070302-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 20:39               ` Christoph Lameter
2007-09-25 14:22   ` [PATCH 3/5] Switch caches notification dynamically Pavel Emelyanov
     [not found]     ` <46F919BB.2000701-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-25 21:48       ` Christoph Lameter
     [not found]         ` <Pine.LNX.4.64.0709251447560.5072-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-26  9:39           ` Pavel Emelyanov
     [not found]             ` <46FA28C9.9060101-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-09-26 17:30               ` Christoph Lameter
     [not found]                 ` <Pine.LNX.4.64.0709261029300.15435-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-09-27  8:24                   ` Pavel Emelyanov
2007-10-01 13:15       ` Balbir Singh
     [not found]         ` <4700F2E8.5050904-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 13:19           ` Pavel Emelyanov
2007-10-01 13:21           ` Pavel Emelyanov
     [not found]             ` <4700F476.4070806-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 13:38               ` Balbir Singh
     [not found]                 ` <4700F85B.5090902-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 13:45                   ` Pavel Emelyanov
     [not found]                     ` <4700FA0A.5040707-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 14:14                       ` Balbir Singh
     [not found]                         ` <470100D0.7030700-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 15:45                           ` Pavel Emelyanov
2007-10-01 20:39                           ` Christoph Lameter
2007-09-25 14:24   ` [PATCH 4/5] Setup the control group Pavel Emelyanov
     [not found]     ` <46F91A1E.2060303-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 13:48       ` Balbir Singh
     [not found]         ` <4700FAAC.2050004-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 13:51           ` Pavel Emelyanov
     [not found]             ` <4700FB72.5070409-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 14:16               ` Balbir Singh
     [not found]                 ` <4701013A.3010307-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 14:17                   ` Pavel Emelyanov
     [not found]                     ` <47010169.5040102-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 14:21                       ` Balbir Singh
     [not found]                         ` <47010276.8060802-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 14:27                           ` Pavel Emelyanov
2007-10-01 15:50                           ` [Devel] " Paul Menage
     [not found]                             ` <6599ad830710010850q660d042av9fa5a461d3c3e445-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-01 15:53                               ` Balbir Singh
     [not found]                                 ` <47011812.2010406-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 16:04                                   ` Paul Menage
2007-10-01 15:52                   ` Paul Menage
2007-09-25 14:26   ` [PATCH 5/5] Account for the slub objects Pavel Emelyanov
     [not found]     ` <46F91A8A.9000001-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 14:07       ` Balbir Singh
     [not found]         ` <4700FF1F.7060604-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 14:10           ` Pavel Emelyanov
     [not found]             ` <4700FFC3.7050005-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-01 20:41               ` Christoph Lameter
     [not found]                 ` <Pine.LNX.4.64.0710011341000.19779-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-10-02 12:44                   ` Pavel Emelyanov
     [not found]                     ` <47023D18.3090304-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-02 18:04                       ` Christoph Lameter
     [not found]                         ` <Pine.LNX.4.64.0710021104000.30559-RYO/mD75kfhx2SFC9UQUAuF7EQX82lMiAL8bYrjMMd8@public.gmane.org>
2007-10-03  7:29                           ` Pavel Emelyanov
2007-10-01 14:12   ` [PATCH 0/5] Kernel memory accounting container (v5) Balbir Singh
     [not found]     ` <4701006B.6050809-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-01 15:43       ` Pavel Emelyanov
2007-10-01 16:32   ` [Devel] " Paul Menage
     [not found]     ` <6599ad830710010932t150aba2eid18864a90f169c64-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-02 12:51       ` Pavel Emelyanov
     [not found]         ` <47023EBE.7000708-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-10-05  7:11           ` Paul Menage
     [not found]             ` <6599ad830710050011x68a80013w3b60d663e2c087a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-05 13:17               ` Pavel Emelyanov

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=4700E477.2060607@openvz.org \
    --to=xemul-gefaqzzx7r8dnm+yrofe0a@public.gmane.org \
    --cc=balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    --cc=clameter-sJ/iWh9BUns@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@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