mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Lameter <clameter@sgi.com>
To: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: Eric Dumazet <dada1@cosmosbay.com>,
	Pekka Enberg <penberg@cs.helsinki.fi>,
	Torsten Kaiser <just.for.lkml@googlemail.com>,
	Ingo Molnar <mingo@elte.hu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Implement slub fastpath in terms of freebase and freeoffset
Date: Thu, 28 Feb 2008 16:57:02 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0802281648510.1954@schroedinger.engr.sgi.com> (raw)
In-Reply-To: <20080228232507.GB20319@Krystal>

On Thu, 28 Feb 2008, Mathieu Desnoyers wrote:

> static inline void set_freelist_ptr(struct kmem_cache_cpu *c, void **freelist)
> {
>         unsigned long offset;
> 
>         offset = c->freeoffset + c->off_mask + 1;
>         offset &= ~c->off_mask;
>         offset |= (unsigned long)freelist & c->off_mask;
>         c->freeoffset = offset;
> }
> 
> Which will insure c->freeoffset is always in a valid state, therefore
> allowing interrupts to nest over it.

Ok.

> Should be ok now since we allow interrupts to nest over
> set_freelist_ptr. But I think this is also protected by slab_lock, taken
> both in the slow path and in deactivate_slab.

The slab locks can only be taken with interrupts disabled.
 

> In any case, doing a 
> 
>                 object = get_freelist_ptr(c);
>                 set_freelist_ptr(c, object[c->offset]);
> 
> Like deactivate_slab does should be either protected by disabling
> interrupts or by the slab_lock. Am I right ?

Correct.

> Ah! I think I found the issue. It should become :
> 
> 
>                 newoffset = freeoffset;
>                 newoffset &= ~c->off_mask;
>                 newoffset |= (unsigned long)(object[c->offset]) & c->off_mask;
>         } while (cmpxchg_local(&c->freeoffset, freeoffset, newoffset)
>                         != freeoffset);

Looks okay.

> Index: linux-2.6-lttng/mm/slub.c
> ===================================================================
> --- linux-2.6-lttng.orig/mm/slub.c	2008-02-27 20:41:14.000000000 -0500
> +++ linux-2.6-lttng/mm/slub.c	2008-02-28 18:22:14.000000000 -0500
> @@ -138,6 +138,22 @@ static inline void ClearSlabDebug(struct
>  	page->flags &= ~SLABDEBUG;
>  }
>  
> +static inline void **get_freelist_ptr(struct kmem_cache_cpu *c)
> +{
> +	return (void **)((unsigned long)page_address(c->page)
> +		| (c->freeoffset & c->off_mask));
> +}

Hmmmm... page_address() is an expensive operation.

> @@ -1636,28 +1652,48 @@ static __always_inline void *slab_alloc(
>   */
>  
>  #ifdef SLUB_FASTPATH
> +	unsigned long freeoffset, newoffset;
> +
>  	c = get_cpu_slab(s, raw_smp_processor_id());
>  	do {
> -		object = c->freelist;
> -		if (unlikely(is_end(object) || !node_match(c, node))) {
> +		freeoffset = c->freeoffset;
> +		/*
> +		 * If c->page is changed, freeoffset _must_ have its
> +		 * counter incremented.
> +		 * read freeoffset before c->page (wrt interrupts).
> +		 */
> +		barrier();
> +		if (unlikely(is_end(freeoffset) || !node_match(c, node))) {
>  			object = __slab_alloc(s, gfpflags, node, addr, c);
>  			break;
>  		}
> +		object = (void **)((unsigned long)page_address(c->page)

Expensive op page_address().

> @@ -1779,21 +1815,21 @@ static __always_inline void slab_free(st
>  	struct kmem_cache_cpu *c;
>  
>  #ifdef SLUB_FASTPATH
> -	void **freelist;
> +	unsigned long freeoffset, newoffset;
>  
>  	c = get_cpu_slab(s, raw_smp_processor_id());
>  	debug_check_no_locks_freed(object, s->objsize);
>  	do {
> -		freelist = c->freelist;
> +		freeoffset = c->freeoffset;
>  		barrier();
>  		/*
>  		 * If the compiler would reorder the retrieval of c->page to
> -		 * come before c->freelist then an interrupt could
> -		 * change the cpu slab before we retrieve c->freelist. We
> -		 * could be matching on a page no longer active and put the
> -		 * object onto the freelist of the wrong slab.
> +		 * come before c->freeoffset then an interrupt could change the
> +		 * cpu slab before we retrieve c->freelist. We could be matching
> +		 * on a page no longer active and put the object onto the
> +		 * freelist of the wrong slab.
>  		 *
> -		 * On the other hand: If we already have the freelist pointer
> +		 * On the other hand: If we already have the freeoffset
>  		 * then any change of cpu_slab will cause the cmpxchg to fail
>  		 * since the freelist pointers are unique per slab.
>  		 */
> @@ -1801,9 +1837,15 @@ static __always_inline void slab_free(st
>  			__slab_free(s, page, x, addr, c->offset);
>  			break;
>  		}
> -		object[c->offset] = freelist;
> +		object[c->offset] =
> +			(void **)((unsigned long)page_address(c->page) |
> +					(freeoffset & c->off_mask));
>  		stat(c, FREE_FASTPATH);
> -	} while (cmpxchg_local(&c->freelist, freelist, object) != freelist);
> +		newoffset = freeoffset + PAGE_SIZE;
> +		newoffset &= ~c->off_mask;
> +		newoffset |= (unsigned long)object & c->off_mask;
> +	} while (cmpxchg_local(&c->freeoffset, freeoffset, newoffset)
> +			!= freeoffset);

Hmmm.. The cmpxchg_local was intended to check for a change of slab too 
(addresses from different slabs are disjunct). 
That is no longer possible since the upper bits are used by the 
versioning? (Same issue in slab_alloc).


  reply	other threads:[~2008-02-29  1:07 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-15 21:23 Linux 2.6.25-rc2 Linus Torvalds
2008-02-16  2:08 ` Rafael J. Wysocki
2008-02-16  5:44 ` [BUG] Linux 2.6.25-rc2 - Kernel Ooops while running dbench Kamalesh Babulal
2008-02-18 12:59   ` Andrew Morton
2008-02-18 14:25     ` Jeff Garzik
2008-02-18 16:11       ` Frans Pop
2008-03-03 11:51     ` Pekka Enberg
2008-03-04  4:03       ` Kamalesh Babulal
2008-02-16  6:10 ` [BUG] Linux 2.6.25-rc2 - Regression from 2.6.24-rc1-git1 softlockup while bootup on powerpc Kamalesh Babulal
2008-02-17 19:29   ` Jens Axboe
2008-02-19  8:04     ` KAMEZAWA Hiroyuki
2008-02-19  8:36       ` Jens Axboe
2008-02-19  8:47         ` KAMEZAWA Hiroyuki
2008-02-19  8:58           ` Jens Axboe
2008-02-19  9:07             ` KAMEZAWA Hiroyuki
2008-02-19  9:09               ` Jens Axboe
2008-02-19  9:02         ` KAMEZAWA Hiroyuki
2008-02-19  9:01           ` Jens Axboe
2008-02-19 13:19         ` Kamalesh Babulal
2008-02-22  7:24         ` Andrew Morton
2008-02-22  7:40           ` Jens Axboe
2008-02-17 20:08   ` Rafael J. Wysocki
2008-02-16 16:52 ` Linux 2.6.25-rc2 Jan Engelhardt
2008-02-16 19:14 ` Linux 2.6.25-rc2 regression: LVM cannot find volume group Tilman Schmidt
2008-02-16 20:12   ` Alan Cox
2008-02-16 22:37     ` Jiri Slaby
2008-02-18  0:57       ` Tilman Schmidt
2008-02-18  1:22         ` Jeff Chua
2008-02-18 10:35           ` Tilman Schmidt
2008-02-19  1:53       ` Alasdair G Kergon
2008-02-19  8:56         ` Tilman Schmidt
2008-02-16 21:38 ` Linux 2.6.25-rc2 Torsten Kaiser
2008-02-17 20:25   ` Rafael J. Wysocki
2008-02-17 21:32     ` Torsten Kaiser
2008-02-18 23:54   ` Linus Torvalds
2008-02-19  6:44     ` Torsten Kaiser
2008-02-19  6:11   ` Ingo Molnar
2008-02-19  6:54     ` Torsten Kaiser
2008-02-19  7:21       ` Pekka Enberg
2008-02-19 10:27         ` Ingo Molnar
2008-02-19 10:45           ` Pekka Enberg
2008-02-19 13:02           ` Mathieu Desnoyers
2008-02-19 14:00             ` Ingo Molnar
2008-02-19 14:02         ` Mathieu Desnoyers
2008-02-19 14:21           ` Pekka Enberg
2008-02-19 14:38             ` Pekka Enberg
2008-02-19 14:55               ` Ingo Molnar
2008-02-19 14:57                 ` Ingo Molnar
2008-02-19 15:54                   ` Pekka Enberg
2008-02-19 15:52                 ` Pekka Enberg
2008-02-20  0:36                   ` Zhang, Yanmin
2008-02-20  2:08                     ` Zhang, Yanmin
2008-02-20  6:53                       ` Zhang, Yanmin
2008-02-20  7:10                         ` Pekka Enberg
2008-02-19 16:20               ` Linus Torvalds
2008-02-19 16:45                 ` Ingo Molnar
2008-02-19 16:48                   ` Ingo Molnar
2008-02-19 19:27                 ` Torsten Kaiser
2008-02-19 20:08             ` Mathieu Desnoyers
2008-02-27 23:32               ` Christoph Lameter
2008-02-28  1:57                 ` Andrew Morton
2008-02-28  2:43                   ` Christoph Lameter
2008-02-28  8:14                   ` Ingo Molnar
2008-02-28 11:15                     ` Alan Cox
2008-02-28 11:13                   ` Jiri Kosina
2008-02-19 16:27           ` Eric Dumazet
2008-02-19 16:38             ` Linus Torvalds
2008-02-19 20:03             ` Mathieu Desnoyers
2008-02-27 23:34               ` Christoph Lameter
2008-02-28  5:55                 ` [PATCH] Implement slub fastpath in terms of freebase and freeoffset Mathieu Desnoyers
2008-02-28 19:08                   ` Christoph Lameter
2008-02-28 23:25                     ` Mathieu Desnoyers
2008-02-29  0:57                       ` Christoph Lameter [this message]
2008-02-29  1:56                         ` Mathieu Desnoyers
2008-02-29  2:12                           ` Christoph Lameter
2008-02-29  3:32                             ` Mathieu Desnoyers
2008-02-29  5:11                               ` Christoph Lameter
2008-02-29 13:03                                 ` Mathieu Desnoyers
2008-02-29 19:57                                   ` Christoph Lameter
2008-02-29 13:28                                 ` [PATCH] Slub Freeoffset check overflow Mathieu Desnoyers
2008-03-04  6:17                                   ` [PATCH] Slub Freeoffset check overflow (updated) Mathieu Desnoyers
2008-03-04  7:15                                     ` Christoph Lameter
2008-02-27 23:32             ` Linux 2.6.25-rc2 Christoph Lameter
2008-02-19 18:39           ` Torsten Kaiser

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=Pine.LNX.4.64.0802281648510.1954@schroedinger.engr.sgi.com \
    --to=clameter@sgi.com \
    --cc=dada1@cosmosbay.com \
    --cc=just.for.lkml@googlemail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=mingo@elte.hu \
    --cc=penberg@cs.helsinki.fi \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®