Bug 529202 - CPU Load Avg calculation gets very confused by multiple recv()s on the same PF_UNIX/SOCK_DGRAM socket
CPU Load Avg calculation gets very confused by multiple recv()s on the same P...
Status: CLOSED WONTFIX
Product: Fedora
Classification: Fedora
Component: kernel (Show other bugs)
13
All Linux
low Severity medium
: ---
: ---
Assigned To: Michal Schmidt
Fedora Extras Quality Assurance
:
: 529504 570323 (view as bug list)
Depends On:
Blocks: F12Target 529504
  Show dependency treegraph
 
Reported: 2009-10-15 09:26 EDT by Lennart Poettering
Modified: 2013-01-10 03:03 EST (History)
9 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2011-06-27 10:27:05 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
the test case (556 bytes, text/plain)
2009-10-15 09:26 EDT, Lennart Poettering
no flags Details
modified test case with processes instead of threads (617 bytes, text/plain)
2009-10-17 19:42 EDT, Michal Schmidt
no flags Details


External Trackers
Tracker ID Priority Status Summary Last Updated
Launchpad 379452 None None None Never

  None (edit)
Description Lennart Poettering 2009-10-15 09:26:42 EDT
Created attachment 364906 [details]
the test case

Consider the attached example code. All it does is create a PF_UNIX/SOCK_DGRAM socket, spawn 4 threads, and call recv() on the socket in each of those threads. Nothing else. Because nobody is sending anything on the socket the program bsically just hangs, rightly does not appear in top -- except that the CPU load average top shows starts to go up and up. Which it shouldn't of course.
Comment 1 Lennart Poettering 2009-10-15 09:35:27 EDT
use case written by the ubuntians btw.
Comment 2 Lennart Poettering 2009-10-15 09:35:52 EDT
s/use case/test case/
Comment 3 Matthew Garrett 2009-10-15 10:36:15 EDT
Load average seems to go to 4 for me, which is what I'd expect. Do you see different behaviour?
Comment 4 Lennart Poettering 2009-10-15 11:53:43 EDT
yes, that's what i see too, butnot what i expected. recv() hangs in D state, and it should be in S state i believe, given that the sleeping actually *is* interruptable with a simple C-c which causes EINTR on the recv().
Comment 5 Lennart Poettering 2009-10-15 18:40:50 EDT
Problem seems to be related to the simultaneous recv() in multiple threads: 

One of the threads will be hanging in S state, and the others in D. The load avg should hence go up to n-1 if we have n threads calling recv() on the same socket.

I would say this a bug.
Comment 6 Lennart Poettering 2009-10-15 18:44:05 EDT
doing the same thing with a pipe instead of an AF_UNIX socket btw works properly: all threads will hang in S.

Whether read() or recv() is used on the fd makes no real difference for the AF_UNIX case.
Comment 7 Lennart Poettering 2009-10-15 18:46:51 EDT
If this code is done with AF_UNIX/SOCK_STREAM then all threads will hang in S. As it should be.

Summarizing:

On pipes all threads waiting will be in S state
On AF_UNIX/SOCK_STREAM all threads waiting will be in S state
On AF_UNIX/SOCK_DGRAM one thread will be in S state, the others in D state (BROKEN!)

So, yes, this is definitely a bug in the socket handling code.
Comment 8 Lennart Poettering 2009-10-15 18:52:08 EDT
I am now setting this as F12Target. glib now uses libasyncns for the resolver and we probably shouldn't show a completely bogus loadavg when the user runs a glib app that uses the resolver.

It's admittedly not high prio though, given that only the statistics are wrong but everything else seems to be fine.
Comment 9 Matěj Cepl 2009-10-17 17:27:53 EDT
(In reply to comment #8)
> It's admittedly not high prio though, given that only the statistics are wrong
> but everything else seems to be fine.  

Are you sure about this? My gajim when tries to use python-libasyncns makes whole computer pretty slowly reacting.
Comment 10 Michal Schmidt 2009-10-17 19:42:44 EDT
Created attachment 365146 [details]
modified test case with processes instead of threads

I modified the test case slightly to use full processes instead of threads, just to demonstrate that it's not a threads-only issue. The high loadavg is reproducible just as well here and the processes are really in D state.

I can't reproduce the system slowdown (which Matěj is seeing) with this. I'll try Gajim later.

I wonder if we can just use mutex_lock_interruptible(&u->readlock) in unix_dgram_recvmsg...
Comment 11 Lennart Poettering 2009-10-19 13:36:26 EDT
(In reply to comment #9)
> (In reply to comment #8)
> > It's admittedly not high prio though, given that only the statistics are wrong
> > but everything else seems to be fine.  
> 
> Are you sure about this? My gajim when tries to use python-libasyncns makes
> whole computer pretty slowly reacting.  

Hmm, no, never seen that. Everyone else reports as if this is only a statistics issue. Is the process actually showing up as CPU time consuming in top?
Comment 12 Lennart Poettering 2009-10-19 13:40:38 EDT
*** Bug 529504 has been marked as a duplicate of this bug. ***
Comment 13 Matěj Cepl 2009-10-19 15:49:28 EDT
(In reply to comment #11)
> (In reply to comment #9)
> > (In reply to comment #8)
> > > It's admittedly not high prio though, given that only the statistics are wrong
> > > but everything else seems to be fine.  
> > 
> > Are you sure about this? My gajim when tries to use python-libasyncns makes
> > whole computer pretty slowly reacting.  
> 
> Hmm, no, never seen that. Everyone else reports as if this is only a statistics
> issue. Is the process actually showing up as CPU time consuming in top?  

Yes, gajim is then pretty active process (low tens of per cent).
Comment 14 Michal Schmidt 2010-03-04 02:55:35 EST
*** Bug 570323 has been marked as a duplicate of this bug. ***
Comment 15 Michal Schmidt 2010-03-04 09:34:24 EST
Note to self: The mutex was added in 2.6.10 by DaveM in:
[AF_UNIX]: Serialize dgram read using semaphore just like stream
It fixed an exploitable race condition (http://www.securityfocus.com/archive/1/381689).
Using mutex_lock_interruptible() almost works, except that SO_RCVTIMEO will still work badly in this situation.
Comment 16 Bug Zapper 2010-03-15 08:56:44 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 13 development cycle.
Changing version to '13'.

More information and reason for this action is here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping
Comment 17 Bug Zapper 2011-06-02 13:36:26 EDT
This message is a reminder that Fedora 13 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 13.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '13'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 13's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 13 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping
Comment 18 Bug Zapper 2011-06-27 10:27:05 EDT
Fedora 13 changed to end-of-life (EOL) status on 2011-06-25. Fedora 13 is 
no longer maintained, which means that it will not receive any further 
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of 
Fedora please feel free to reopen this bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.

Note You need to log in before you can comment on or make changes to this bug.