Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 20:33, Trond Myklebust wrote: > ty den 25.01.2005 Klokka 19:12 (+0100) skreiv Andreas Gruenbacher: > > > Ah, I see now what you mean. The setxattr syscall only accepts > > well-formed acls (that is, sorted plus a few other restrictions), and > > user-space is expected to

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 19:12 (+0100) skreiv Andreas Gruenbacher: > Ah, I see now what you mean. The setxattr syscall only accepts > well-formed acls (that is, sorted plus a few other restrictions), and > user-space is expected to take care of that. In turn, getxattr returns > only well-formed

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 18:37, Trond Myklebust wrote: > ty den 25.01.2005 Klokka 18:16 (+0100) skreiv Andreas Gruenbacher: > > > > Whatever Sun chooses to do or not do changes nothing to the question of > > > why our client would want to do a quicksort in the kernel. > > > > Well, it determines

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 18:16 (+0100) skreiv Andreas Gruenbacher: > > Whatever Sun chooses to do or not do changes nothing to the question of > > why our client would want to do a quicksort in the kernel. > > Well, it determines what we must accept, both on the server side and the > client

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 18:03, Trond Myklebust wrote: > ty den 25.01.2005 Klokka 17:53 (+0100) skreiv Andreas Gruenbacher: > > On Tue, 2005-01-25 at 17:52, Trond Myklebust wrote: > > > So here's an iconoclastic question or two: > > > > > > Why can't clients sort the list in userland, before they

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 17:53 (+0100) skreiv Andreas Gruenbacher: > On Tue, 2005-01-25 at 17:52, Trond Myklebust wrote: > > So here's an iconoclastic question or two: > > > > Why can't clients sort the list in userland, before they call down to > > the kernel? > > Tell that to Sun

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 17:52, Trond Myklebust wrote: > So here's an iconoclastic question or two: > > Why can't clients sort the list in userland, before they call down to > the kernel? Tell that to Sun Microsystems. Regards, -- Andreas Gruenbacher <[EMAIL PROTECTED]> SUSE Labs, SUSE LINUX

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 13:05 (+0100) skreiv Olaf Kirch: > On Tue, Jan 25, 2005 at 01:00:23PM +0100, Andi Kleen wrote: > > group initialization is not time critical, it typically only happens > > at login. Also it's doubleful you'll even be able to measure the > > difference. > > nfsd updates

Re: [patch 1/13] Qsort

2005-01-25 Thread Olaf Kirch
On Tue, Jan 25, 2005 at 01:00:23PM +0100, Andi Kleen wrote: > group initialization is not time critical, it typically only happens > at login. Also it's doubleful you'll even be able to measure the difference. nfsd updates its group list for every request it processes, so you don't want to make

Re: [patch 1/13] Qsort

2005-01-25 Thread Andi Kleen
> It would slow down the groups case (unless we leave the specialized version > in). Gcc doesn't inline a cmp function pointer, and a C preprocessor > templatized version would be really ugly. A variant with of this routine with > qsort like interface should be good enough for nfsacl and xfs

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tuesday 25 January 2005 07:51, Andi Kleen wrote: > > FWIW, we already have a Shell sort for the ngroups stuff in > > kernel/sys.c:groups_sort() that could be made generic. > > Sounds like a good plan. Any takers? It would slow down the groups case (unless we leave the specialized version in).

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tuesday 25 January 2005 07:51, Andi Kleen wrote: FWIW, we already have a Shell sort for the ngroups stuff in kernel/sys.c:groups_sort() that could be made generic. Sounds like a good plan. Any takers? It would slow down the groups case (unless we leave the specialized version in). Gcc

Re: [patch 1/13] Qsort

2005-01-25 Thread Andi Kleen
It would slow down the groups case (unless we leave the specialized version in). Gcc doesn't inline a cmp function pointer, and a C preprocessor templatized version would be really ugly. A variant with of this routine with qsort like interface should be good enough for nfsacl and xfs

Re: [patch 1/13] Qsort

2005-01-25 Thread Olaf Kirch
On Tue, Jan 25, 2005 at 01:00:23PM +0100, Andi Kleen wrote: group initialization is not time critical, it typically only happens at login. Also it's doubleful you'll even be able to measure the difference. nfsd updates its group list for every request it processes, so you don't want to make

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 13:05 (+0100) skreiv Olaf Kirch: On Tue, Jan 25, 2005 at 01:00:23PM +0100, Andi Kleen wrote: group initialization is not time critical, it typically only happens at login. Also it's doubleful you'll even be able to measure the difference. nfsd updates its group

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 17:52, Trond Myklebust wrote: So here's an iconoclastic question or two: Why can't clients sort the list in userland, before they call down to the kernel? Tell that to Sun Microsystems. Regards, -- Andreas Gruenbacher [EMAIL PROTECTED] SUSE Labs, SUSE LINUX GMBH -

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 17:53 (+0100) skreiv Andreas Gruenbacher: On Tue, 2005-01-25 at 17:52, Trond Myklebust wrote: So here's an iconoclastic question or two: Why can't clients sort the list in userland, before they call down to the kernel? Tell that to Sun Microsystems.

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 18:03, Trond Myklebust wrote: ty den 25.01.2005 Klokka 17:53 (+0100) skreiv Andreas Gruenbacher: On Tue, 2005-01-25 at 17:52, Trond Myklebust wrote: So here's an iconoclastic question or two: Why can't clients sort the list in userland, before they call down to

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 18:16 (+0100) skreiv Andreas Gruenbacher: Whatever Sun chooses to do or not do changes nothing to the question of why our client would want to do a quicksort in the kernel. Well, it determines what we must accept, both on the server side and the client side. I

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 18:37, Trond Myklebust wrote: ty den 25.01.2005 Klokka 18:16 (+0100) skreiv Andreas Gruenbacher: Whatever Sun chooses to do or not do changes nothing to the question of why our client would want to do a quicksort in the kernel. Well, it determines what we must

Re: [patch 1/13] Qsort

2005-01-25 Thread Trond Myklebust
ty den 25.01.2005 Klokka 19:12 (+0100) skreiv Andreas Gruenbacher: Ah, I see now what you mean. The setxattr syscall only accepts well-formed acls (that is, sorted plus a few other restrictions), and user-space is expected to take care of that. In turn, getxattr returns only well-formed acls.

Re: [patch 1/13] Qsort

2005-01-25 Thread Andreas Gruenbacher
On Tue, 2005-01-25 at 20:33, Trond Myklebust wrote: ty den 25.01.2005 Klokka 19:12 (+0100) skreiv Andreas Gruenbacher: Ah, I see now what you mean. The setxattr syscall only accepts well-formed acls (that is, sorted plus a few other restrictions), and user-space is expected to take care

Re: [patch 1/13] Qsort

2005-01-24 Thread Andi Kleen
> FWIW, we already have a Shell sort for the ngroups stuff in > kernel/sys.c:groups_sort() that could be made generic. Sounds like a good plan. Any takers? -Andi - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo

Re: [patch 1/13] Qsort

2005-01-24 Thread Eric St-Laurent
On Mon, 2005-01-24 at 21:43 -0300, Horst von Brand wrote: > AFAICS, this is just a badly implemented Shellsort (the 10/13 increment > sequence starting with the number of elements is probably not very good, > besides swapping stuff is inefficient (just juggling like Shellsort does > gives you

Re: [patch 1/13] Qsort

2005-01-24 Thread Horst von Brand
[EMAIL PROTECTED] (H. Peter Anvin) said: [...] > In klibc, I use combsort: > > /* > * qsort.c > * > * This is actually combsort. It's an O(n log n) algorithm with > * simplicity/small code size being its main virtue. > */ > > #include > #include > > static inline size_t newgap(size_t

Re: [patch 1/13] Qsort

2005-01-24 Thread Mike Waychison
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andi Kleen wrote: >>How about a shell sort? if the data is mostly sorted shell sort beats >>qsort lots of times, and since the data sets are often small in-kernel, >>shell sorts O(n^2) behaviour won't harm it too much, shell sort is also >>faster

Re: [patch 1/13] Qsort

2005-01-24 Thread Matt Mackall
On Mon, Jan 24, 2005 at 01:02:44AM -0300, Horst von Brand wrote: > Matt Mackall <[EMAIL PROTECTED]> said: > > On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: > > [...] > > > > -Andi (who thinks the glibc qsort is vast overkill for kernel purposes > > > where there are only small data

Re: [patch 1/13] Qsort

2005-01-24 Thread vlobanov
On Mon, 24 Jan 2005, Matt Mackall wrote: > On Sun, Jan 23, 2005 at 05:58:00AM +0100, Felipe Alfaro Solana wrote: > > On 23 Jan 2005, at 03:39, Andi Kleen wrote: > > > > >Felipe Alfaro Solana <[EMAIL PROTECTED]> writes: > > >> > > >>AFAIK, XOR is quite expensive on IA32 when compared to simple MOV

Re: [patch 1/13] Qsort

2005-01-24 Thread Matt Mackall
On Sun, Jan 23, 2005 at 05:58:00AM +0100, Felipe Alfaro Solana wrote: > On 23 Jan 2005, at 03:39, Andi Kleen wrote: > > >Felipe Alfaro Solana <[EMAIL PROTECTED]> writes: > >> > >>AFAIK, XOR is quite expensive on IA32 when compared to simple MOV > >>operatings. Also, since the original patch uses

Re: [patch 1/13] Qsort

2005-01-24 Thread H. Peter Anvin
Followup to: <[EMAIL PROTECTED]> By author:Jesper Juhl <[EMAIL PROTECTED]> In newsgroup: linux.dev.kernel > > On Sun, 23 Jan 2005, Andi Kleen wrote: > > > > How about a shell sort? if the data is mostly sorted shell sort beats > > > qsort lots of times, and since the data sets are often

Re: [patch 1/13] Qsort

2005-01-24 Thread Alan Cox
On Sul, 2005-01-23 at 05:05, Jesper Juhl wrote: > On Sun, 23 Jan 2005, Andi Kleen wrote: > Even with large data sets that are mostly unsorted shell sorts performance > is close to qsort, and there's an optimization that gives it O(n^(3/2)) > runtime (IIRC), and another nice property is that it's

Re: [patch 1/13] Qsort

2005-01-24 Thread Alan Cox
On Sul, 2005-01-23 at 05:05, Jesper Juhl wrote: On Sun, 23 Jan 2005, Andi Kleen wrote: Even with large data sets that are mostly unsorted shell sorts performance is close to qsort, and there's an optimization that gives it O(n^(3/2)) runtime (IIRC), and another nice property is that it's

Re: [patch 1/13] Qsort

2005-01-24 Thread H. Peter Anvin
Followup to: [EMAIL PROTECTED] By author:Jesper Juhl [EMAIL PROTECTED] In newsgroup: linux.dev.kernel On Sun, 23 Jan 2005, Andi Kleen wrote: How about a shell sort? if the data is mostly sorted shell sort beats qsort lots of times, and since the data sets are often small

Re: [patch 1/13] Qsort

2005-01-24 Thread Matt Mackall
On Sun, Jan 23, 2005 at 05:58:00AM +0100, Felipe Alfaro Solana wrote: On 23 Jan 2005, at 03:39, Andi Kleen wrote: Felipe Alfaro Solana [EMAIL PROTECTED] writes: AFAIK, XOR is quite expensive on IA32 when compared to simple MOV operatings. Also, since the original patch uses 3 MOVs to

Re: [patch 1/13] Qsort

2005-01-24 Thread vlobanov
On Mon, 24 Jan 2005, Matt Mackall wrote: On Sun, Jan 23, 2005 at 05:58:00AM +0100, Felipe Alfaro Solana wrote: On 23 Jan 2005, at 03:39, Andi Kleen wrote: Felipe Alfaro Solana [EMAIL PROTECTED] writes: AFAIK, XOR is quite expensive on IA32 when compared to simple MOV operatings.

Re: [patch 1/13] Qsort

2005-01-24 Thread Matt Mackall
On Mon, Jan 24, 2005 at 01:02:44AM -0300, Horst von Brand wrote: Matt Mackall [EMAIL PROTECTED] said: On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: [...] -Andi (who thinks the glibc qsort is vast overkill for kernel purposes where there are only small data sets and it

Re: [patch 1/13] Qsort

2005-01-24 Thread Mike Waychison
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andi Kleen wrote: How about a shell sort? if the data is mostly sorted shell sort beats qsort lots of times, and since the data sets are often small in-kernel, shell sorts O(n^2) behaviour won't harm it too much, shell sort is also faster if the

Re: [patch 1/13] Qsort

2005-01-24 Thread Horst von Brand
[EMAIL PROTECTED] (H. Peter Anvin) said: [...] In klibc, I use combsort: /* * qsort.c * * This is actually combsort. It's an O(n log n) algorithm with * simplicity/small code size being its main virtue. */ #include stddef.h #include string.h static inline size_t

Re: [patch 1/13] Qsort

2005-01-24 Thread Eric St-Laurent
On Mon, 2005-01-24 at 21:43 -0300, Horst von Brand wrote: AFAICS, this is just a badly implemented Shellsort (the 10/13 increment sequence starting with the number of elements is probably not very good, besides swapping stuff is inefficient (just juggling like Shellsort does gives you almost a

Re: [patch 1/13] Qsort

2005-01-24 Thread Andi Kleen
FWIW, we already have a Shell sort for the ngroups stuff in kernel/sys.c:groups_sort() that could be made generic. Sounds like a good plan. Any takers? -Andi - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo

Re: [patch 1/13] Qsort

2005-01-23 Thread Horst von Brand
"Rafael J. Wysocki" <[EMAIL PROTECTED]> said: [...] > To be precise, one needs ~(log N) of stack space for qsort, and frankly, one > should use something like the shell (or should I say Shell?) Shell. It is named for a person. > sort

Re: [patch 1/13] Qsort

2005-01-23 Thread Horst von Brand
Matt Mackall <[EMAIL PROTECTED]> said: > On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: [...] > > -Andi (who thinks the glibc qsort is vast overkill for kernel purposes > > where there are only small data sets and it would be better to use a > > simpler one optimized for code size)

Re: [patch 1/13] Qsort

2005-01-23 Thread Horst von Brand
Andreas Gruenbacher <[EMAIL PROTECTED]> said: > Signed-off-by: Andreas Gruenbacher <[EMAIL PROTECTED]> > Acked-by: Olaf Kirch <[EMAIL PROTECTED]> [...] > +/* Order size using quicksort. This implementation incorporates > + four optimizations discussed in Sedgewick: > + > + 1. Non-recursive,

Re: [patch 1/13] Qsort

2005-01-23 Thread Charles R Harris
Here are semi-templated versions of quicksort and heapsort, just for completeness. The quicksort uses the median of three. Chuck void quicksort0( *pl, *pr) { vp, SWAP_temp; *stack[100], **sptr = stack, *pm, *pi, *pj, *pt; for(;;) { while ((pr

Re: [patch 1/13] Qsort

2005-01-23 Thread Matt Mackall
On Mon, Jan 24, 2005 at 11:21:29AM +1100, Nathan Scott wrote: > On Sat, Jan 22, 2005 at 08:29:30PM -0800, Matt Mackall wrote: > > On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: > > > > c) the three-way median selection does help avoid worst-case O(n^2) > > behavior, which might

Re: [patch 1/13] Qsort

2005-01-23 Thread James Lamanna
> On Sunday, January 23, 2005, Rafael J. Wysocki wrote: > > On Sunday, 23 of January 2005 06:05, Jesper Juhl wrote: > > > On Sun, 23 Jan 2005, Andi Kleen wrote: > > Even with large data sets that are mostly unsorted shell sorts performance > > is close to qsort, and there's an optimization that

Re: [patch 1/13] Qsort

2005-01-23 Thread Nathan Scott
On Sat, Jan 22, 2005 at 08:29:30PM -0800, Matt Mackall wrote: > On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: > > c) the three-way median selection does help avoid worst-case O(n^2) > behavior, which might potentially be triggerable by users in places > like XFS where this is used

Re: [patch 1/13] Qsort

2005-01-23 Thread Richard Henderson
On Sat, Jan 22, 2005 at 01:00:24PM -0800, vlobanov wrote: > #define SWAP(a, b, size) \ > do { \ > register size_t __size = (size);\ > register char * __a = (a), * __b = (b); \ > do {

Re: [patch 1/13] Qsort

2005-01-23 Thread Matt Mackall
On Sun, Jan 23, 2005 at 01:22:13PM +0100, Andreas Gruenbacher wrote: > On Sunday 23 January 2005 06:32, Matt Mackall wrote: > > Yes, indeed. Though I think even here, we'd prefer to use kmalloc > > because gcc generates suboptimal code for variable-sized stack vars. > > That's ridiculous. kmalloc

Re: [patch 1/13] Qsort

2005-01-23 Thread Andreas Gruenbacher
On Sunday 23 January 2005 06:32, Matt Mackall wrote: > Yes, indeed. Though I think even here, we'd prefer to use kmalloc > because gcc generates suboptimal code for variable-sized stack vars. That's ridiculous. kmalloc isn't even close to whatever suboptimal code gcc might produce here. Also I'm

Re: [patch 1/13] Qsort

2005-01-23 Thread Rafael J. Wysocki
On Sunday, 23 of January 2005 06:05, Jesper Juhl wrote: > On Sun, 23 Jan 2005, Andi Kleen wrote: > > > > How about a shell sort? if the data is mostly sorted shell sort beats > > > qsort lots of times, and since the data sets are often small in-kernel, > > > shell sorts O(n^2) behaviour won't

Re: [patch 1/13] Qsort

2005-01-23 Thread Rafael J. Wysocki
On Sunday, 23 of January 2005 06:05, Jesper Juhl wrote: On Sun, 23 Jan 2005, Andi Kleen wrote: How about a shell sort? if the data is mostly sorted shell sort beats qsort lots of times, and since the data sets are often small in-kernel, shell sorts O(n^2) behaviour won't harm it too

Re: [patch 1/13] Qsort

2005-01-23 Thread Andreas Gruenbacher
On Sunday 23 January 2005 06:32, Matt Mackall wrote: Yes, indeed. Though I think even here, we'd prefer to use kmalloc because gcc generates suboptimal code for variable-sized stack vars. That's ridiculous. kmalloc isn't even close to whatever suboptimal code gcc might produce here. Also I'm

Re: [patch 1/13] Qsort

2005-01-23 Thread Matt Mackall
On Sun, Jan 23, 2005 at 01:22:13PM +0100, Andreas Gruenbacher wrote: On Sunday 23 January 2005 06:32, Matt Mackall wrote: Yes, indeed. Though I think even here, we'd prefer to use kmalloc because gcc generates suboptimal code for variable-sized stack vars. That's ridiculous. kmalloc isn't

Re: [patch 1/13] Qsort

2005-01-23 Thread Nathan Scott
On Sat, Jan 22, 2005 at 08:29:30PM -0800, Matt Mackall wrote: On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: c) the three-way median selection does help avoid worst-case O(n^2) behavior, which might potentially be triggerable by users in places like XFS where this is used XFS's

Re: [patch 1/13] Qsort

2005-01-23 Thread James Lamanna
On Sunday, January 23, 2005, Rafael J. Wysocki wrote: On Sunday, 23 of January 2005 06:05, Jesper Juhl wrote: On Sun, 23 Jan 2005, Andi Kleen wrote: Even with large data sets that are mostly unsorted shell sorts performance is close to qsort, and there's an optimization that gives it

Re: [patch 1/13] Qsort

2005-01-23 Thread Matt Mackall
On Mon, Jan 24, 2005 at 11:21:29AM +1100, Nathan Scott wrote: On Sat, Jan 22, 2005 at 08:29:30PM -0800, Matt Mackall wrote: On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: c) the three-way median selection does help avoid worst-case O(n^2) behavior, which might potentially be

Re: [patch 1/13] Qsort

2005-01-23 Thread Charles R Harris
Here are semi-templated versions of quicksort and heapsort, just for completeness. The quicksort uses the median of three. Chuck void quicksort0typename(typename *pl, typename *pr) { typename vp, SWAP_temp; typename *stack[100], **sptr = stack, *pm, *pi, *pj, *pt;

Re: [patch 1/13] Qsort

2005-01-23 Thread Horst von Brand
Andreas Gruenbacher [EMAIL PROTECTED] said: Signed-off-by: Andreas Gruenbacher [EMAIL PROTECTED] Acked-by: Olaf Kirch [EMAIL PROTECTED] [...] +/* Order size using quicksort. This implementation incorporates + four optimizations discussed in Sedgewick: + + 1. Non-recursive, using an

Re: [patch 1/13] Qsort

2005-01-23 Thread Horst von Brand
Matt Mackall [EMAIL PROTECTED] said: On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: [...] -Andi (who thinks the glibc qsort is vast overkill for kernel purposes where there are only small data sets and it would be better to use a simpler one optimized for code size) Mostly

Re: [patch 1/13] Qsort

2005-01-23 Thread Horst von Brand
Rafael J. Wysocki [EMAIL PROTECTED] said: [...] To be precise, one needs ~(log N) of stack space for qsort, and frankly, one should use something like the shell (or should I say Shell?) Shell. It is named for a person. sort for

Re: [patch 1/13] Qsort

2005-01-22 Thread Willy Tarreau
Hi, On Sun, Jan 23, 2005 at 03:03:32AM +0100, Felipe Alfaro Solana wrote: > On 22 Jan 2005, at 22:00, vlobanov wrote: > >#define SWAP(a, b, size) \ > >do { \ > > register size_t __size = (size);\ > > register char * __a =

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sun, Jan 23, 2005 at 06:08:36AM +0100, Andreas Gruenbacher wrote: > On Sunday 23 January 2005 00:28, Matt Mackall wrote: > > So the stack is going to be either 256 or 1024 bytes. Seems like we > > ought to kmalloc it. > > This will do. I didn't check if the +1 is strictly needed. > > -

Re: [patch 1/13] Qsort

2005-01-22 Thread Andreas Gruenbacher
On Sunday 23 January 2005 00:28, Matt Mackall wrote: > So the stack is going to be either 256 or 1024 bytes. Seems like we > ought to kmalloc it. This will do. I didn't check if the +1 is strictly needed. - stack_node stack[STACK_SIZE]; + stack_node stack[fls(size) - fls(MAX_THRESH) +

Re: [patch 1/13] Qsort

2005-01-22 Thread Jesper Juhl
On Sun, 23 Jan 2005, Andi Kleen wrote: > > How about a shell sort? if the data is mostly sorted shell sort beats > > qsort lots of times, and since the data sets are often small in-kernel, > > shell sorts O(n^2) behaviour won't harm it too much, shell sort is also > > faster if the data is

Re: [patch 1/13] Qsort

2005-01-22 Thread Felipe Alfaro Solana
On 23 Jan 2005, at 03:39, Andi Kleen wrote: Felipe Alfaro Solana <[EMAIL PROTECTED]> writes: AFAIK, XOR is quite expensive on IA32 when compared to simple MOV operatings. Also, since the original patch uses 3 MOVs to perform the swapping, and your version uses 3 XOR operations, I don't see any

Re: [patch 1/13] Qsort

2005-01-22 Thread Andi Kleen
> How about a shell sort? if the data is mostly sorted shell sort beats > qsort lots of times, and since the data sets are often small in-kernel, > shell sorts O(n^2) behaviour won't harm it too much, shell sort is also > faster if the data is already completely sorted. Shell sort is certainly

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: > Felipe Alfaro Solana <[EMAIL PROTECTED]> writes: > > > > AFAIK, XOR is quite expensive on IA32 when compared to simple MOV > > operatings. Also, since the original patch uses 3 MOVs to perform the > > swapping, and your version uses 3

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sun, Jan 23, 2005 at 03:03:32AM +0100, Felipe Alfaro Solana wrote: > On 22 Jan 2005, at 22:00, vlobanov wrote: > > >Hi, > > > >I was just reading over the patch, and had a quick question/comment > >upon > >the SWAP macro defined below. I think it's possible to do a tiny bit > >better (better,

Re: [patch 1/13] Qsort

2005-01-22 Thread Jesper Juhl
On Sun, 23 Jan 2005, Andi Kleen wrote: > Felipe Alfaro Solana <[EMAIL PROTECTED]> writes: > > > > AFAIK, XOR is quite expensive on IA32 when compared to simple MOV > > operatings. Also, since the original patch uses 3 MOVs to perform the > > swapping, and your version uses 3 XOR operations, I

Re: [patch 1/13] Qsort

2005-01-22 Thread Andi Kleen
Felipe Alfaro Solana <[EMAIL PROTECTED]> writes: > > AFAIK, XOR is quite expensive on IA32 when compared to simple MOV > operatings. Also, since the original patch uses 3 MOVs to perform the > swapping, and your version uses 3 XOR operations, I don't see any > gains. Both are one cycle latency

Re: [patch 1/13] Qsort

2005-01-22 Thread Felipe Alfaro Solana
On 22 Jan 2005, at 22:00, vlobanov wrote: Hi, I was just reading over the patch, and had a quick question/comment upon the SWAP macro defined below. I think it's possible to do a tiny bit better (better, of course, being subjective), as follows: #define SWAP(a, b, size)\

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sat, Jan 22, 2005 at 03:28:14PM -0800, Matt Mackall wrote: > On Sat, Jan 22, 2005 at 09:34:01PM +0100, Andreas Gruenbacher wrote: > > Add a quicksort from glibc as a kernel library function, and switch > > xfs over to using it. The implementations are equivalent. The nfsacl > > protocol also

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sat, Jan 22, 2005 at 09:34:01PM +0100, Andreas Gruenbacher wrote: > Add a quicksort from glibc as a kernel library function, and switch > xfs over to using it. The implementations are equivalent. The nfsacl > protocol also requires a sort function, so it makes more sense in > the common code.

Re: [patch 1/13] Qsort

2005-01-22 Thread Andreas Gruenbacher
On Sat, 2005-01-22 at 23:06, Arjan van de Ven wrote: > since you took the glibc one.. the glibc authors have repeatedly asked > if glibc code that goes into the kernel will be export_symbol_gpl only > due to their view of the gpl and lgpl Sure, no big deal. We could equally well take the xfs one

Re: [patch 1/13] Qsort

2005-01-22 Thread vlobanov
Hi, I was just reading over the patch, and had a quick question/comment upon the SWAP macro defined below. I think it's possible to do a tiny bit better (better, of course, being subjective), as follows: #define SWAP(a, b, size)\ do {

Re: [patch 1/13] Qsort

2005-01-22 Thread vlobanov
Hi, I was just reading over the patch, and had a quick question/comment upon the SWAP macro defined below. I think it's possible to do a tiny bit better (better, of course, being subjective), as follows: #define SWAP(a, b, size)\ do {

Re: [patch 1/13] Qsort

2005-01-22 Thread Andreas Gruenbacher
On Sat, 2005-01-22 at 23:06, Arjan van de Ven wrote: since you took the glibc one.. the glibc authors have repeatedly asked if glibc code that goes into the kernel will be export_symbol_gpl only due to their view of the gpl and lgpl Sure, no big deal. We could equally well take the xfs one

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sat, Jan 22, 2005 at 09:34:01PM +0100, Andreas Gruenbacher wrote: Add a quicksort from glibc as a kernel library function, and switch xfs over to using it. The implementations are equivalent. The nfsacl protocol also requires a sort function, so it makes more sense in the common code.

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sat, Jan 22, 2005 at 03:28:14PM -0800, Matt Mackall wrote: On Sat, Jan 22, 2005 at 09:34:01PM +0100, Andreas Gruenbacher wrote: Add a quicksort from glibc as a kernel library function, and switch xfs over to using it. The implementations are equivalent. The nfsacl protocol also requires

Re: [patch 1/13] Qsort

2005-01-22 Thread Felipe Alfaro Solana
On 22 Jan 2005, at 22:00, vlobanov wrote: Hi, I was just reading over the patch, and had a quick question/comment upon the SWAP macro defined below. I think it's possible to do a tiny bit better (better, of course, being subjective), as follows: #define SWAP(a, b, size)\

Re: [patch 1/13] Qsort

2005-01-22 Thread Andi Kleen
Felipe Alfaro Solana [EMAIL PROTECTED] writes: AFAIK, XOR is quite expensive on IA32 when compared to simple MOV operatings. Also, since the original patch uses 3 MOVs to perform the swapping, and your version uses 3 XOR operations, I don't see any gains. Both are one cycle latency for

Re: [patch 1/13] Qsort

2005-01-22 Thread Jesper Juhl
On Sun, 23 Jan 2005, Andi Kleen wrote: Felipe Alfaro Solana [EMAIL PROTECTED] writes: AFAIK, XOR is quite expensive on IA32 when compared to simple MOV operatings. Also, since the original patch uses 3 MOVs to perform the swapping, and your version uses 3 XOR operations, I don't see any

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sun, Jan 23, 2005 at 03:03:32AM +0100, Felipe Alfaro Solana wrote: On 22 Jan 2005, at 22:00, vlobanov wrote: Hi, I was just reading over the patch, and had a quick question/comment upon the SWAP macro defined below. I think it's possible to do a tiny bit better (better, of course,

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sun, Jan 23, 2005 at 03:39:34AM +0100, Andi Kleen wrote: Felipe Alfaro Solana [EMAIL PROTECTED] writes: AFAIK, XOR is quite expensive on IA32 when compared to simple MOV operatings. Also, since the original patch uses 3 MOVs to perform the swapping, and your version uses 3 XOR

Re: [patch 1/13] Qsort

2005-01-22 Thread Andi Kleen
How about a shell sort? if the data is mostly sorted shell sort beats qsort lots of times, and since the data sets are often small in-kernel, shell sorts O(n^2) behaviour won't harm it too much, shell sort is also faster if the data is already completely sorted. Shell sort is certainly

Re: [patch 1/13] Qsort

2005-01-22 Thread Felipe Alfaro Solana
On 23 Jan 2005, at 03:39, Andi Kleen wrote: Felipe Alfaro Solana [EMAIL PROTECTED] writes: AFAIK, XOR is quite expensive on IA32 when compared to simple MOV operatings. Also, since the original patch uses 3 MOVs to perform the swapping, and your version uses 3 XOR operations, I don't see any

Re: [patch 1/13] Qsort

2005-01-22 Thread Jesper Juhl
On Sun, 23 Jan 2005, Andi Kleen wrote: How about a shell sort? if the data is mostly sorted shell sort beats qsort lots of times, and since the data sets are often small in-kernel, shell sorts O(n^2) behaviour won't harm it too much, shell sort is also faster if the data is already

Re: [patch 1/13] Qsort

2005-01-22 Thread Andreas Gruenbacher
On Sunday 23 January 2005 00:28, Matt Mackall wrote: So the stack is going to be either 256 or 1024 bytes. Seems like we ought to kmalloc it. This will do. I didn't check if the +1 is strictly needed. - stack_node stack[STACK_SIZE]; + stack_node stack[fls(size) - fls(MAX_THRESH) +

Re: [patch 1/13] Qsort

2005-01-22 Thread Matt Mackall
On Sun, Jan 23, 2005 at 06:08:36AM +0100, Andreas Gruenbacher wrote: On Sunday 23 January 2005 00:28, Matt Mackall wrote: So the stack is going to be either 256 or 1024 bytes. Seems like we ought to kmalloc it. This will do. I didn't check if the +1 is strictly needed. - stack_node

Re: [patch 1/13] Qsort

2005-01-22 Thread Willy Tarreau
Hi, On Sun, Jan 23, 2005 at 03:03:32AM +0100, Felipe Alfaro Solana wrote: On 22 Jan 2005, at 22:00, vlobanov wrote: #define SWAP(a, b, size) \ do { \ register size_t __size = (size);\ register char * __a = (a), *