linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: sched_yield() makes OpenLDAP slow
@ 2005-08-19  6:03 Howard Chu
  2005-08-19  6:34 ` Nick Piggin
                   ` (2 more replies)
  0 siblings, 3 replies; 49+ messages in thread
From: Howard Chu @ 2005-08-19  6:03 UTC (permalink / raw)
  To: linux-kernel

Hm, seems there's a great deal of misinformation in this thread.

>  I also think OpenLDAP is wrong. First, it should be calling
>  pthread_yield() because slapd is a multithreading process and it just
>  wants to run the other threads. See:
...
>  AFAIKS, sched_yield should only really be used by realtime
>  applications that know exactly what they're doing.

pthread_yield() was deleted from the POSIX threads drafts years ago. 
sched_yield() is the officially supported API, and OpenLDAP is using it 
for the documented purpose. Anyone who says "applications shouldn't be 
using sched_yield()" doesn't know what they're talking about.

>  It's really more a feature than a bug that it breaks so easily
>  because they should be really using futexes instead, which have much
>  better behaviour than any sched_yield ever could (they will directly
>  wake up another process waiting for the lock and avoid the thundering
>  herd for contended locks)

You assume that spinlocks are the only reason a developer may want to 
yield the processor. This assumption is unfounded. Case in point - the 
primary backend in OpenLDAP uses a transactional database with 
page-level locking of its data structures to provide high levels of 
concurrency. It is the nature of such a system to encounter deadlocks 
over the normal course of operations. When a deadlock is detected, some 
thread must be chosen (by one of a variety of algorithms) to abort its 
transaction, in order to allow other operations to proceed to 
completion. In this situation, the chosen thread must get control of the 
CPU long enough to clean itself up, and then it must yield the CPU in 
order to allow any other competing threads to complete their 
transaction. The thread with the aborted transaction relinquishes all of 
its locks and then waits to get another shot at the CPU to try 
everything over again. Again, this is all fundamental to the nature of 
transactional programming. If the 2.6 kernel makes this programming 
model unreasonably slow, then quite simply this kernel is not viable as 
a database platform.

-- 
  -- Howard Chu
  Chief Architect, Symas Corp.  http://www.symas.com
  Director, Highland Sun        http://highlandsun.com/hyc
  OpenLDAP Core Team            http://www.openldap.org/project/


^ permalink raw reply	[flat|nested] 49+ messages in thread
* e100 oops on resume
@ 2006-01-24 22:59 Stefan Seyfried
  2006-01-24 23:21 ` Mattia Dongili
  0 siblings, 1 reply; 49+ messages in thread
From: Stefan Seyfried @ 2006-01-24 22:59 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: netdev

Hi,
since 2.6.16rc1-git3, e100 dies on resume (regardless if from disk, ram or
runtime powermanagement). Unfortunately i only have a bad photo of
the oops right now, it is available from
https://bugzilla.novell.com/attachment.cgi?id=64761&action=view
I have reproduced this on a second e100 machine and can get a serial
console log from this machine tomorrow if needed.
It did resume fine with 2.6.15-git12
-- 
Stefan Seyfried                  \ "I didn't want to write for pay. I
QA / R&D Team Mobile Devices      \ wanted to be paid for what I write."
SUSE LINUX Products GmbH, Nürnberg \                    -- Leonard Cohen

^ permalink raw reply	[flat|nested] 49+ messages in thread
[parent not found: <5uZqb-4fo-15@gated-at.bofh.it>]
* Re: sched_yield() makes OpenLDAP slow
@ 2006-01-14 19:29 Howard Chu
  0 siblings, 0 replies; 49+ messages in thread
From: Howard Chu @ 2006-01-14 19:29 UTC (permalink / raw)
  To: linux-kernel

Resurrecting a dead horse...
> *From: *Lee Revell
> *Date: * Sat Aug 20 2005 - 15:57:36 EST
>
> ------------------------------------------------------------------------
> On Sat, 2005-08-20 at 11:38 -0700, Howard Chu wrote:
> >/ But I also found that I needed to add a new /
> >/ yield(), to work around yet another unexpected issue on this system -/
> >/ we have a number of threads waiting on a condition variable, and the/
> >/ thread holding the mutex signals the var, unlocks the mutex, and then /
> >/ immediately relocks it. The expectation here is that upon unlocking/
> >/ the mutex, the calling thread would block while some waiting thread/
> >/ (that just got signaled) would get to run. In fact what happened is/
> >/ that the calling thread unlocked and relocked the mutex without/
> >/ allowing any of the waiting threads to run. In this case the only/
> >/ solution was to insert a yield() after the mutex_unlock(). /
>
> That's exactly the behavior I would expect. Why would you expect
> unlocking a mutex to cause a reschedule, if the calling thread still has
> timeslice left?
>
> Lee

POSIX requires a reschedule to occur, as noted here:
http://blog.firetree.net/2005/06/22/thread-yield-after-mutex-unlock/

The relevant SUSv3 text is here
http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutex_unlock.html

I suppose if pthread_mutex_unlock() actually behaved correctly we could 
remove the other sched_yield() hacks that didn't belong there in the 
first place and go on our merry way.

-- 
  -- Howard Chu
  Chief Architect, Symas Corp.  http://www.symas.com
  Director, Highland Sun        http://highlandsun.com/hyc
  OpenLDAP Core Team            http://www.openldap.org/project/


^ permalink raw reply	[flat|nested] 49+ messages in thread
[parent not found: <43057641.70700@symas.com.suse.lists.linux.kernel>]
[parent not found: <4D8eT-4rg-31@gated-at.bofh.it>]
[parent not found: <4303DB48.8010902@develer.com.suse.lists.linux.kernel>]
* sched_yield() makes OpenLDAP slow
@ 2005-08-18  0:50 Bernardo Innocenti
  2005-08-18  0:47 ` Con Kolivas
  2005-08-18  1:07 ` Joseph Fannin
  0 siblings, 2 replies; 49+ messages in thread
From: Bernardo Innocenti @ 2005-08-18  0:50 UTC (permalink / raw)
  To: lkml, OpenLDAP-devel; +Cc: Giovanni Bajo, Simone Zinanni

Hello,

I've been investigating a performance problem on a
server using OpenLDAP 2.2.26 for nss resolution and
running kernel 2.6.12.

When a CPU bound process such as GCC is running in the
background (even at nice 10), many trivial commands such
as "su" or "groups" become extremely slow and take a few
seconds to complete.

strace revealed that data exchange over the slapd socket
was where most of the time was spent.  Looking at the
slapd side, I see several calls to sched_yield() like this:


[pid  8780]      0.000033 stat64("gidNumber.dbb", 0xb7b3ebcc) = -1 EACCES (Permission denied)
[pid  8780]      0.000059 pread(20, "\0\0\0\0\1\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\2\0\344\17\2\3"..., 4096, 4096) = 4096
[pid  8780]      0.000083 pread(20, "\0\0\0\0\1\0\0\0\4\0\0\0\3\0\0\0\0\0\0\0\222\0<\7\1\5\370"..., 4096, 16384) = 4096
[pid  8780]      0.000078 time(NULL)    = 1124322520
[pid  8780]      0.000066 pread(11, "\0\0\0\0\1\0\0\0\250\0\0\0\231\0\0\0\235\0\0\0\16\0000"..., 4096, 688128) = 4096
[pid  8780]      0.000241 write(19, "0e\2\1\3d`\4$cn=bernie,ou=group,dc=d"..., 103) = 103
[pid  8780]      0.000137 sched_yield( <unfinished ...>
[pid  8781]      0.050020 <... sched_yield resumed> ) = 0
[pid  8780]      0.000025 <... sched_yield resumed> ) = 0
[pid  8781]      0.000060 futex(0x925ab20, FUTEX_WAIT, 33, NULL <unfinished ...>
[pid  8780]      0.000026 write(19, "0\f\2\1\3e\7\n\1\0\4\0\4\0", 14) = 14
[pid  8774]      0.000774 <... select resumed> ) = 1 (in [19])


The relative timestamp reveals that slapd is spending 50ms
after yielding.  Meanwhile, GCC is probably being scheduled
for a whole quantum.

Reading the man-page of sched_yield() it seems this isn't
the correct behavior:

   Note: If the current process is the only process in the
   highest priority list at that time, this process will
   continue to run after a call to sched_yield.

I also think OpenLDAP is wrong.  First, it should be calling
pthread_yield() because slapd is a multithreading process
and it just wants to run the other threads.  See:

int
ldap_pvt_thread_yield( void )
{
#if HAVE_THR_YIELD
        return thr_yield();

#elif HAVE_PTHREADS == 10
        return sched_yield();

#elif defined(_POSIX_THREAD_IS_GNU_PTH)
        sched_yield();
        return 0;

#elif HAVE_PTHREADS == 6
        pthread_yield(NULL);
        return 0;
#else
        pthread_yield();
        return 0;
#endif
}


-- 
  // Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/  http://www.develer.com/


^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2006-01-26 10:50 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-19  6:03 sched_yield() makes OpenLDAP slow Howard Chu
2005-08-19  6:34 ` Nick Piggin
2005-08-19  6:59 ` Chris Wedgwood
2005-08-19 22:45   ` Howard Chu
2005-08-19 10:21 ` Nikita Danilov
2005-08-19 23:10   ` Howard Chu
2005-08-20 13:23     ` Nikita Danilov
2005-08-20 19:49       ` Howard Chu
2005-08-20 22:08         ` Nikita Danilov
  -- strict thread matches above, loose matches on Subject: below --
2006-01-24 22:59 e100 oops on resume Stefan Seyfried
2006-01-24 23:21 ` Mattia Dongili
2006-01-25  9:02   ` Olaf Kirch
2006-01-25 12:11     ` Olaf Kirch
2006-01-25 13:51       ` sched_yield() makes OpenLDAP slow Howard Chu
2006-01-25 14:38         ` Robert Hancock
2006-01-25 17:49         ` Christopher Friesen
2006-01-26  1:07         ` David Schwartz
2006-01-26  8:30           ` Helge Hafting
2006-01-26  9:01             ` Nick Piggin
2006-01-26 10:50             ` Nikita Danilov
     [not found] <5uZqb-4fo-15@gated-at.bofh.it>
2006-01-14 22:47 ` Robert Hancock
2006-01-14 19:29 Howard Chu
     [not found] <43057641.70700@symas.com.suse.lists.linux.kernel>
     [not found] ` <17157.45712.877795.437505@gargle.gargle.HOWL.suse.lists.linux.kernel>
     [not found]   ` <430666DB.70802@symas.com.suse.lists.linux.kernel>
2005-08-20 13:48     ` Andi Kleen
2005-08-21 19:47       ` Florian Weimer
2005-08-22  5:09         ` Howard Chu
2005-08-22 13:06           ` Andi Kleen
2005-08-22 18:47             ` Howard Chu
2005-08-22 13:20           ` Florian Weimer
2005-08-22 23:19             ` Howard Chu
     [not found] <4D8eT-4rg-31@gated-at.bofh.it>
2005-08-20  3:20 ` Robert Hancock
2005-08-20  4:18   ` Nick Piggin
2005-08-20 18:38     ` Howard Chu
2005-08-20 20:57       ` Lee Revell
2005-08-20 21:24         ` Howard Chu
2005-08-21  0:36           ` Nick Piggin
2005-08-21 11:33           ` Nikita Danilov
2005-08-22  8:06             ` Howard Chu
2005-08-20 21:50       ` Lee Revell
2005-08-21  1:04       ` Robert Hancock
2005-08-22 11:44         ` linux-os (Dick Johnson)
2005-08-22 14:26           ` Robert Hancock
2005-08-23 11:17             ` linux-os (Dick Johnson)
2005-08-23 12:07               ` Denis Vlasenko
2005-08-24  3:37                 ` Lincoln Dale
     [not found] <4303DB48.8010902@develer.com.suse.lists.linux.kernel>
     [not found] ` <20050818010703.GA13127@nineveh.rivenstone.net.suse.lists.linux.kernel>
     [not found]   ` <4303F967.6000404@yahoo.com.au.suse.lists.linux.kernel>
     [not found]     ` <43054D9A.7090509@develer.com.suse.lists.linux.kernel>
2005-08-19  3:19       ` Andi Kleen
2005-08-19  3:30         ` Bernardo Innocenti
2005-08-18  0:50 Bernardo Innocenti
2005-08-18  0:47 ` Con Kolivas
2005-08-18 10:48   ` Maciej Soltysiak
2005-08-18  1:07 ` Joseph Fannin
2005-08-18  2:25   ` Bernardo Innocenti
2005-08-18  2:58   ` Nick Piggin
2005-08-19  3:10     ` Bernardo Innocenti

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).