[pulseaudio-discuss] Understanding PulseSimple Large Memory Allocations
Ryan McClue
re.mcclue at protonmail.com
Tue Oct 5 21:14:51 UTC 2021
Thanks Sean,
What threw me was that VTune has one column Memory Allocated and another Memory Used.
Both were ~200MB. Using htop I was able to verify what you said.
Perhaps VTune needs to change their naming!
--
Ryan McClue, Sydney
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, October 5th, 2021 at 8:19 AM, Sean Greenslade <sean at seangreenslade.com> wrote:
> On Sun, Oct 03, 2021 at 07:44:13AM +0000, Ryan McClue wrote:
>
> > I'm on an Ubuntu system and want to write to a PCM buffer and play it.
> >
> > I created the most basic C program that only calls pa_simple_new(). I
> >
> > launched this program into Intel VTune and performed a Memory
> >
> > Consumption analysis. It showed that libpulsecommon.so allocates
> >
> > ~200MB and pa_simple_new() allocates ~67MB. Why is so much memory
> >
> > allocated?
>
> Hi, Ryan.
>
> There are a few subtleties in Linux with regards to memory usage. First,
>
> I recommend taking a look at the usage through a tool like "top", and
>
> notice that it reports three separete values for memory usage: VIRT,
>
> RES, and SHR. These stand for Virtual, Resident, and Shared. Each of
>
> these behaves a little differently.
>
> VIRT is how many kilobytes of memory address space is currently used by
>
> the application. This includes all memory allocations, memory mapped
>
> files, libraries, and anything else that gets addressed by memory. But
>
> just because something is using memory address space doesn't necessarily
>
> mean that it's using physical memory.
>
> RES is how many kilobytes of physical memory are in use by
>
> the application. This is more or less the "true memory usage" of the
>
> application.
>
> The SHR number is how much shared memory is in use by the application.
>
> This can be things like libraries or shared buffers (which pulse uses to
>
> transfer audio data between processes).
>
> I ran a test of pacat-simple.c on my machine and got the following
>
> values:
>
> VIRT - 339 MB
>
> RES - 5.3 MB
>
> SHR - 4.6 MB
>
> So you can see that despite the fact that ~300 MB of address space is
>
> used, only ~5 MB of actual RAM is consumed, and most of that is shared
>
> memory (likely the libraries and IPC audio buffers).
>
> Also, something a little unintuitive about Linux and the way it
>
> allocates memory is that allocations don't actually get assigned to
>
> physical memory until they are used. If you call malloc(), you will get
>
> address space assigned which will add to your VIRT count but your RES
>
> count will stay the same. Once you insert values into those memory
>
> addresses, then the RES count will increase, but only by the amount you
>
> actually fill. This causes mallocs to be almost no cost memory-wise,
>
> and there's pretty much no harm in over-allocating memory if it's not
>
> used.
>
> In summary, don't worry about the VIRT memory consumed by a process;
>
> it's not the amount of physical RAM used.
>
> > Also, as pulseaudio is what is adopted by Ubuntu, is it
> >
> > true that I have no other choice than to use pulseaudio as it owns all
> >
> > the sound devices?
>
> This question would be better asked on an Ubuntu-specific list. That
>
> said, if your audio needs are very simple (e.g. only one application
>
> ever playing audio at a time), then it should be possible to disable
>
> pulseaudio and use ALSA directly.
>
> --Sean
More information about the pulseaudio-discuss
mailing list