Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

[PATCH] slob: reduce list scanning

 
   Soft32 Home -> Linux -> Kernel RSS
Next:  [2.6 patch] crypto/Kconfig: remove "default ..  
Author Message
Matt Mackall

External


Since: Dec 12, 2006
Posts: 338



(Msg. 1) Posted: Sat Jul 14, 2007 3:00 am
Post subject: [PATCH] slob: reduce list scanning
Archived from groups: linux>kernel (more info?)

The version of SLOB in -mm always scans its free list from the
beginning, which results in small allocations and free segments
clustering at the beginning of the list over time. This causes the
average search to scan over a large stretch at the beginning on each
allocation.

By starting each page search where the last one left off, we evenly
distribute the allocations and greatly shorten the average search.

Without this patch, kernel compiles on a 1.5G machine take a large
amount of system time for list scanning. With this patch, compiles are
within a few seconds of performance of a SLAB kernel with no notable
change in system time.

Signed-off-by: Matt Mackall <mpm RemoveThis @selenic.com>

Index: mm/mm/slob.c
===================================================================
--- mm.orig/mm/slob.c 2007-07-13 17:51:25.000000000 -0500
+++ mm/mm/slob.c 2007-07-13 18:42:59.000000000 -0500
@@ -293,6 +293,7 @@ static void *slob_page_alloc(struct slob
static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
{
struct slob_page *sp;
+ struct list_head *prev;
slob_t *b = NULL;
unsigned long flags;

@@ -307,12 +308,22 @@ static void *slob_alloc(size_t size, gfp
if (node != -1 && page_to_nid(&sp->page) != node)
continue;
#endif
+ /* Enough room on this page? */
+ if (sp->units < SLOB_UNITS(size))
+ continue;

- if (sp->units >= SLOB_UNITS(size)) {
- b = slob_page_alloc(sp, size, align);
- if (b)
- break;
- }
+ /* Attempt to alloc */
+ prev = sp->list.prev;
+ b = slob_page_alloc(sp, size, align);
+ if (!b)
+ continue;
+
+ /* Improve fragment distribution and reduce our average
+ * search time by starting our next search here. (see
+ * Knuth vol 1, sec 2.5, pg 449) */
+ if (free_slob_pages.next != prev->next)
+ list_move_tail(&free_slob_pages, prev->next);
+ break;
}
spin_unlock_irqrestore(&slob_lock, flags);



--
Mathematics is the supreme nostalgia of our time.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo RemoveThis @vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Nick Piggin

External


Since: Nov 27, 2006
Posts: 373



(Msg. 2) Posted: Mon Jul 16, 2007 3:10 am
Post subject: Re: [PATCH] slob: reduce list scanning [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Matt Mackall wrote:
> The version of SLOB in -mm always scans its free list from the
> beginning, which results in small allocations and free segments
> clustering at the beginning of the list over time. This causes the
> average search to scan over a large stretch at the beginning on each
> allocation.
>
> By starting each page search where the last one left off, we evenly
> distribute the allocations and greatly shorten the average search.
>
> Without this patch, kernel compiles on a 1.5G machine take a large
> amount of system time for list scanning. With this patch, compiles are
> within a few seconds of performance of a SLAB kernel with no notable
> change in system time.

This looks pretty nice, and performance results sound good too.
IMO this should probably be merged along with the previous
SLOB patches, because they removed the cyclic scanning to begin
with (so it may be possible that introduces a performnace
regression in some situations).

I wonder what it would take to close the performance gap further.
I still want to look at per-cpu freelists after Andrew merges
this set of patches. That may improve both cache hotness and
CPU scalability.

Actually SLOB potentially has some fundamental CPU cache hotness
advantages over the other allocators, for the same reasons as
its space advantages. It may be possible to make some workloads
faster with SLOB than with SLUB! Maybe we could remove SLAB and
SLUB then Smile

--
SUSE Labs, Novell Inc.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.TakeThisOut@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Pekka Enberg

External


Since: Nov 06, 2006
Posts: 190



(Msg. 3) Posted: Mon Jul 16, 2007 4:30 am
Post subject: Re: [PATCH] slob: reduce list scanning [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 7/16/07, Nick Piggin <nickpiggin.TakeThisOut@yahoo.com.au> wrote:
> Actually SLOB potentially has some fundamental CPU cache hotness
> advantages over the other allocators, for the same reasons as
> its space advantages.

Because consecutive allocations hit the same cache-hot page regardless
of requested size where as SLUB by definition distributes allocations
to different pages (some of which may not be hot)?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.TakeThisOut@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Nick Piggin

External


Since: Nov 27, 2006
Posts: 373



(Msg. 4) Posted: Mon Jul 16, 2007 5:40 am
Post subject: Re: [PATCH] slob: reduce list scanning [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Pekka Enberg wrote:
> On 7/16/07, Nick Piggin <nickpiggin RemoveThis @yahoo.com.au> wrote:
>
>> Actually SLOB potentially has some fundamental CPU cache hotness
>> advantages over the other allocators, for the same reasons as
>> its space advantages.
>
>
> Because consecutive allocations hit the same cache-hot page regardless
> of requested size where as SLUB by definition distributes allocations
> to different pages (some of which may not be hot)?

Yeah, that, and also a newly freed slab object is quite likely to be
hot, and that memory can be used by another subsequent allocation --
not always, because the allocation heuristics may not place it there,
but there is potential that is impossible with slab allocators.

--
SUSE Labs, Novell Inc.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo RemoveThis @vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Matt Mackall

External


Since: Dec 12, 2006
Posts: 338



(Msg. 5) Posted: Mon Jul 16, 2007 2:00 pm
Post subject: Re: [PATCH] slob: reduce list scanning [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mon, Jul 16, 2007 at 04:01:15PM +1000, Nick Piggin wrote:
> Matt Mackall wrote:
> >The version of SLOB in -mm always scans its free list from the
> >beginning, which results in small allocations and free segments
> >clustering at the beginning of the list over time. This causes the
> >average search to scan over a large stretch at the beginning on each
> >allocation.
> >
> >By starting each page search where the last one left off, we evenly
> >distribute the allocations and greatly shorten the average search.
> >
> >Without this patch, kernel compiles on a 1.5G machine take a large
> >amount of system time for list scanning. With this patch, compiles are
> >within a few seconds of performance of a SLAB kernel with no notable
> >change in system time.
>
> This looks pretty nice, and performance results sound good too.
> IMO this should probably be merged along with the previous
> SLOB patches, because they removed the cyclic scanning to begin
> with (so it may be possible that introduces a performnace
> regression in some situations).
>
> I wonder what it would take to close the performance gap further.
> I still want to look at per-cpu freelists after Andrew merges
> this set of patches. That may improve both cache hotness and
> CPU scalability.

The idea I'm currently kicking around is having an array of spinlocks
and list heads per CPU and add an array index to the SLOB page struct.

To allocate, we loop over the array starting at the current CPU
looking for space. On failure, we add a page to the current CPU's
list. We can imagine several variants here: attempting to trylock
while scanning the list or doing no fallback at all. The first is
liable to be unhelpful if there's actually contention, the second will
consume more total memory but reduce the average scan time.

To free, we locate the list from the page struct so we can grab the
relevant lock.

This probably also ends up being very friendly to NUMA. But it's not
clear that it's worth doing for the common case of 2 cores, where
contention may be too low to be worth the extra trouble.

> Actually SLOB potentially has some fundamental CPU cache hotness
> advantages over the other allocators, for the same reasons as
> its space advantages. It may be possible to make some workloads
> faster with SLOB than with SLUB! Maybe we could remove SLAB and
> SLUB then Smile

It's all handwaving until there are actually benchmarks.

--
Mathematics is the supreme nostalgia of our time.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.DeleteThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Display posts from previous:   
Related Topics:
[PATCH 10/12] SLOB: fix build error if SLOB && !NUMA - Fix build error: LD .tmp_vmlinux1 arch/x86_64/kernel/built-in.o: In function `__cpu_up': : undefined..

[rfc][patch] slob: improvements - This patch goes on top of my previous RCU patch, and has various improvements for slob I noticed while implementing sai...

[PATCH] slob: handle SLAB_PANIC flag - kmem_cache_create() for slob doesn't handle SLAB_PANIC. Cc: Matt Mackall <mpm@selenic.com> Signed-off-by: Akinob...

[PATCH] SLOB allocator imcompatible SLAB - Because the page which SLOB allocator got does not have PG_slab, I put back the result that kobjsize made a mistake in....

[PATCH] slob: poor man's NUMA support. - This adds preliminary NUMA support to SLOB, primarily aimed at systems with small nodes (tested all the way down to a..

[PATCH 1/1 2.6.20-rc2] MM: SLOB is broken by recent cleanu.. - From: Dimitri Gorokhovik <dimitri.gorokhovik@free.fr> Recent cleanup of slab.h broke SLOB allocator: the routine...
       Soft32 Home -> Linux -> Kernel All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]