Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.

Bug 486525

Summary: Pulseaudio disregards the --disable-shm command line option
Product: [Fedora] Fedora Reporter: Darryl Bond <darryl.bond>
Component: pulseaudioAssignee: Lennart Poettering <lpoetter>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 10CC: lkundrak, lpoetter, pierre-bugzilla, ryanryan52, wtogami
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-02-26 16:01:27 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 188611    

Description Darryl Bond 2009-02-20 06:11:17 UTC
Description of problem: Pulse audio dies on LTSP clients with low memory

Client is Fedora 10 LTSP. 

Version-Release number of selected component (if applicable):
pulseaudio-0.9.14-1.fc10.i386


How reproducible:
Pulseaudio dies on a thin client with 64MB of RAM which includes 8MB of Video RAM.
The pulse audio startup script command is 
 /usr/bin/pulseaudio --system \
                --exit-idle-time=-1 \
                --disable-shm=1 \
                --no-cpu-limit \
                --resample-method=trivial \
                --high-priority \
                -L module-detect \
                -L "module-esound-protocol-tcp auth-anonymous=1" \
                -L "module-native-protocol-tcp auth-anonymous=1" \
                -L module-volume-restore \
                -L module-rescue-streams \
                -L module-native-protocol-unix \
                -n

Steps to Reproduce:
1. Boot the client
2. Check for running processes
3. Find that pulseaudio is not running
  
Actual results:
Re-running the command
W: main.c: Running in system mode, but --disallow-exit not set!
W: main.c: Running in system mode, but --disallow-module-loading not set!
E: shm.c: mmap() failed: Cannot allocate memory
E: core.c: pa_mempool_new() failed.
E: main.c: pa_core_new() failed.

From strace:
open("/dev/shm/", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5
fstat64(5, {st_mode=S_IFDIR|0755, st_size=40, ...}) = 0
getdents64(5, /* 2 entries */, 4096)    = 48
getdents64(5, /* 0 entries */, 4096)    = 0
close(5)                                = 0
mmap2(NULL, 67108864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
ioctl(2, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(2, "E: shm.c: \33[1;31mmmap() failed: C"..., 59E: shm.c: mmap() failed: Cannot allocate memory
) = 59
ioctl(2, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(2, "E: core.c: \33[1;31mpa_mempool_new("..., 47E: core.c: pa_mempool_new() failed.
) = 47
ioctl(2, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(2, "E: main.c: \33[1;31mpa_core_new() f"..., 44E: main.c: pa_core_new() failed.

Note that even with --disable-shm and running in --system it tried to allocate 64MB RAM
Expected results:
pulse audio should take notice of the --disable-shm and --system flag and not use shared memory as documented in the man page 


Additional info:

Adding the following lines to the pulse/daemon.conf file resolved the problem:
disable-shm = yes
shm-size-bytes = 1048576 # setting this 0 will use the system-default, usually 64 MiB
I have not tried to optimise the shm-size-bytes just tried 1M and it worked.

Comment 1 Lennart Poettering 2009-02-25 02:08:32 UTC
This is a misunderstanding --disable-shm only disables usage of SHM as transport. The PA internal memory allocation will still use a 64mb pool, allocating with mmap().

Note that even though we allocate 64mb initially this doesn't mean we actually use this memory. Due to how modern operating systems work this is only allocation of address space -- not of actual memory. The memory is only allocated when the memory is first accessed. Hence it should be fine to allocate that much even on systems with little memory.

The only drawback of this logic is that pages are never handed back to the kernel this way: if memory is used once it stays in the pool and is never given back, however reused the next time.  If this is a problem, shm-size-bytes is of help.

Comment 2 Warren Togami 2009-02-25 05:16:03 UTC
Lennart, what is the drawback of using an exceedingly small shm-size-bytes like 1MB?  4MB?  (Please go ahead and close again after you have answered this question.)

Comment 3 Lennart Poettering 2009-02-26 16:01:27 UTC
TBH I have no idea what the real-life effect of that will be. If the pool is full PA will fallback to malloc() for allocating memory blocks. Hence I assume the effect is not that bad. 

Try to set it to 1MB and check if that works fine!

BTW, I PA git now hands back those pages to the kernel when idle.

Comment 4 Darryl Bond 2009-02-26 21:04:15 UTC
I set the shm-size-bytes = 65536 (64kb) without any adverse effects that I can see (hear).

Comment 5 Warren Togami 2009-02-26 21:28:21 UTC
Is it possible to set this option without using the conf file?  Command line option?