Page 1 of 2

Getting "cannot allocate memory" error, although running in real time

Posted: Mon Aug 12, 2019 6:30 am
by Nachei
Hi, I recently installed Ubuntu Studio 19, and I'm in the process of optimizing it for my laptop. I recently completed the tests of Realtime Config Quick Scan, with everything showing "good" with the exception of "Realtime kernel" (a requirement that, as I understand according to this forum and other reads, is no longer essential, and I guess the reason why Ubuntu Studio ships with a low-latency kernel instead of a real time one).

The problem I'm facing now is that qjackctl output shows, no matter what settings I use, the message "ERROR: Cannot lock down 82280346 byte memory area (Cannot allocate memory)".

Here is the complete output:

Code: Select all

03:37:44.924 Statistics reset.
03:37:44.928 ALSA connection change.
03:37:44.975 D-BUS: Service is available (org.jackaudio.service aka jackdbus).
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
03:37:44.985 ALSA connection graph change.
03:37:57.966 D-BUS: JACK server is starting...
03:37:57.978 D-BUS: JACK server was started (org.jackaudio.service aka jackdbus).
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Sun Aug 11 03:37:57 2019: Starting jack server...
Sun Aug 11 03:37:57 2019: JACK server starting in realtime mode with priority 10
Sun Aug 11 03:37:57 2019: self-connect-mode is "Don't restrict self connect requests"
Sun Aug 11 03:37:57 2019: ERROR: Cannot lock down 82280346 byte memory area (Cannot allocate memory)
Sun Aug 11 03:37:57 2019: Acquired audio card Audio1
Sun Aug 11 03:37:57 2019: creating alsa driver ... hw:K6|hw:K6|64|2|44100|0|0|nomon|swmeter|-|32bit
Sun Aug 11 03:37:57 2019: configuring for 44100Hz, period = 64 frames (1.5 ms), buffer = 2 periods
Sun Aug 11 03:37:57 2019: ALSA: final selected sample format for capture: 32bit integer little-endian
Sun Aug 11 03:37:57 2019: ALSA: use 2 periods for capture
Sun Aug 11 03:37:57 2019: ALSA: final selected sample format for playback: 32bit integer little-endian
Sun Aug 11 03:37:57 2019: ALSA: use 2 periods for playback
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:capture_1'
Sun Aug 11 03:37:57 2019: New client 'system' with PID 0
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:capture_2'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:capture_3'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:capture_4'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:capture_5'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:capture_6'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:playback_1'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:playback_2'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:playback_3'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:playback_4'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:playback_5'
Sun Aug 11 03:37:57 2019: graph reorder: new port 'system:playback_6'
Sun Aug 11 03:37:57 2019: New client 'PulseAudio JACK Sink' with PID 2353
Sun Aug 11 03:37:57 2019: Connecting 'PulseAudio JACK Sink:front-left' to 'system:playback_1'
Sun Aug 11 03:37:57 2019: Connecting 'PulseAudio JACK Sink:front-right' to 'system:playback_2'
Sun Aug 11 03:37:58 2019: New client 'PulseAudio JACK Source' with PID 2353
Sun Aug 11 03:37:58 2019: Connecting 'system:capture_1' to 'PulseAudio JACK Source:front-left'
Sun Aug 11 03:37:58 2019: Connecting 'system:capture_2' to 'PulseAudio JACK Source:front-right'
Sun Aug 11 03:37:59 2019: Saving settings to "/home/palmiro/.config/jack/conf.xml" ...
03:38:00.044 JACK connection change.
03:38:00.045 Server configuration saved to "/home/palmiro/.jackdrc".
03:38:00.045 Statistics reset.
03:38:00.046 Client activated.
03:38:00.046 Patchbay deactivated.
03:38:00.054 JACK connection graph change.
Sun Aug 11 03:38:00 2019: New client 'qjackctl' with PID 11746
A perhaps relevant fact is that that amount of memory that cannot be allocated remains the same number (82280346) across all my qjackctl settings, both for external interface and computer's inner sound card -and the fact that some of those settings generate xruns and others don't, doesn't seem to make any difference-.


After research in this forum, I checked what seem to be the usual suspects, and they have been discarded:

1) There exists indeed an "audio" group, to which I belong.

2) As far as I can tell, the memory allocation parameters in /etc/security/limits.d/audio.conf and /etc/security/limits.conf are correct:

Code: Select all

cat /etc/security/limits.d/audio.conf

# Provided by the jackd package.
#
# Changes to this file will be preserved.
#
# If you want to enable/disable realtime permissions, run
#
#    dpkg-reconfigure -p high jackd

@audio   -  rtprio     95
@audio   -  memlock    unlimited
#@audio   -  nice      -19

Code: Select all

cat /etc/security/limits.conf

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#        - NOTE: group and wildcard limits are not applied to root.
#          To apply a limit to the root user, <domain> must be
#          the literal username root.
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#        - chroot - change root to directory (Debian-specific)
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4

# End of file
(All of this was supposed to come already configured by default in Ubuntu Studio, but I checked it just in case.)

My computer has 16Gb RAM, so I don't think there's a problem of RAM shortage either.

Other things I've tried have been: changing the rtprio value to from 95 to 90 (as that is the value that appears in the documentation example - https://wiki.linuxaudio.org/wiki/system ... faudioconf), and uncommenting the line #@audio - nice -19 at the end of audio.conf. None of them have had any effect on that unexplainable "cannot lock down memory" message.

What could be causing this error? In addition to the aforementioned settings, is there any other configuration I should check, that could be obstructing the computer from using real time mode? Or maybe this is a normal thing and shouldn't worry me as long as I don't get xruns? Thank you in advance for any suggestion.

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Mon Aug 12, 2019 1:04 pm
by Linuxmusician01
I see that you are starting Jack via qjackctl. Could you try to start it another way, via the command line? That way standard settings are used. I personally think that the following command should always work:

Code: Select all

jackd -d alsa --device hw:K6
If I'm not mistaken the audiocard that you want to use is called "K6". Is that right? Good luck!

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Mon Aug 12, 2019 3:38 pm
by merlyn
I had a problem with allocating memory. It was caused by systemd and it was fixed with a systemd update. I've got systemd 242.81-1 now, but it was fixed a few months ago.

No amount of editing configuration files made any difference -- it needed an update.

In JACK the amount of memory locked depends on the number of ports. You can change the number of ports in QJackCtl in Settings > Advanced with the 'Port Maximum' dropdown. If you reduce it and the error goes away I would think it's the same problem I had.

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Tue Aug 13, 2019 11:10 pm
by Nachei
Thank you so much to both of you for your suggestions...

@Linuxmusician01:

I've tried the command you provide and, on the positive side, the output shows no "lockdown" message. I opened a project in Reaper and it seemed to work and be very stable. However, it seems to have a very high latency (~0.5 seconds with Rakarrack), making it suitable for production, but unusable to play.

What would be the way to modify the defaults? jackd --help doesn't show any option regarding the usual frames/period, sample rate... And also, how can you know your latency when you use this command?
Linuxmusician01 wrote:If I'm not mistaken the audiocard that you want to use is called "K6". Is that right? Good luck!
Thank you for the good wishes, fellow musician :) Yes, it's Native Instruments' Komplete Audio 6, and in the "interface" section of qjackctl it appears as "hw:K6 Komplete Audio 6 (hw:1)" and "hw:K6,0 USB Audio (hw:1,0)".

@merlyn:

Firstly I tried your suggestion of reducing the number of ports, in qjackctl as it is now. I've dropped it from 256 to 128 (the smallest available value), and it hasn't had any effect on the error message.

So then I've looked into updating systemd.

My systemd version, as reported by "dpkg -l systemd", is 240-6ubuntu5, a lower version than yours, so that could be the cause.

I then researched how to update systemd, and to tell the truth I'm a bit intimidated. The "how to update systemd in ubuntu" internet query does not generate a lot of information (at least not enough for my level of newbieness :) ), and starts with this StackExchange thread: https://askubuntu.com/questions/627174/ ... emd#627203, where the first thing you read is:
As already pointed out by @mikewhatever and @earthmeLon you really shouldn't mess around with this.

But if you really want to (make sure you've backups!)...
Are the instructions in that StackExchange post what you used to update systemd, could you confirm that they work? Otherwise, would you care to share a bit how you did it, or point me to some link with instructions? I don't even know what you're supposed to "backup" before upgrading systemd... Thank you.

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Wed Aug 14, 2019 1:32 am
by merlyn
Nachei wrote: I've dropped it from 256 to 128 (the smallest available value), and it hasn't had any effect on the error message.
This is a different issue.

I'd agree that updating systemd is not something easily done manually. I use Arch Linux and it updates constantly. If you want to update systemd you would be best with the Ubuntu version, so you would be best to wait for them to update it.

There is something strange -- 82280346 is the amount of memory locked with 2048 ports. Here's the relevant part of my (verbose) JACK log with 2048 ports :

Code: Select all

Wed Aug 14 01:10:40 2019: Jack: JackShmMem::new index = 0 attached = 4fef4000 size = 82280346 
Wed Aug 14 01:10:40 2019: Jack: JackShmMem::new placement size = 13047706
Wed Aug 14 01:10:41 2019: Jack: Succeeded in locking 82280346 byte memory area
Here it is with 128 ports :

Code: Select all

Wed Aug 14 01:14:02 2019: Jack: JackShmMem::new index = 0 attached = 53cda000 size = 17374746 
Wed Aug 14 01:14:02 2019: Jack: JackShmMem::new placement size = 13047706
Wed Aug 14 01:14:02 2019: Jack: Succeeded in locking 17374746 byte memory area
So even if you can't lock memory, JACK should be trying to lock less.

Looking at your QJackCtl output the problem happens when using jackdbus :
Nachei wrote:

Code: Select all

03:37:57.966 D-BUS: JACK server is starting...
03:37:57.978 D-BUS: JACK server was started (org.jackaudio.service aka jackdbus).
I would think QjackCtl is using jackdbus because Ubuntu Studio comes with Ubuntu Studio Controls. You could try deleting ~/.config/jack/conf.xml and ~/.config/rncbc.org/QjackCtl.conf which will reset JACK settings.

Locking memory means that that part of memory won't end up in the swap space. You've got 16GB of RAM, so that's unlikely to happen anyway. I tend to fix these niggles, but I wouldn't think it's critical :)

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Wed Aug 14, 2019 1:35 am
by rghvdberg
Does the error message actually produce any errors?
If audio is doing fine just leave it like this.
I wouldn't mess with systemd unless you're 100% certain it's the issue.
Maybe add the 19.10 backport ppa and see if it wants to update jack itself, I sooner suspect a bug in jack than a bug in systemd.

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Wed Aug 14, 2019 5:05 am
by merlyn
rghvdberg wrote: I sooner suspect a bug in jack than a bug in systemd.
systemd isn't immune to bugs :wink:

https://github.com/systemd/systemd/issues/11386

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Thu Aug 15, 2019 7:39 pm
by Nachei
Thank you for all the answers. This error is not really critical, my system is quite stable now, but I wanted to "iron out" the problem just in case it could influence others... So I think by the moment I'm going to live with it and wait until Ubuntu updates systemd (or better said, until Ubuntu updates and Ubuntu Studio follows through)...

I did try, however, the "low hanging fruit" of deleting ~/.config/jack/conf.xml and ~/.config/rncbc.org/QjackCtl.conf so that qjackctl rebuilt them. The result was not good: under exactly the same settings as before, this time Qjackctl started to sputter xruns like crazy -and the cannot allocate message was still there!-. Maybe there's some strange interaction with some of the tailored stuff of the distro (like that Ubuntu Studio Controls merlyn mentions, which I've never used). Luckily, recovering the backup files turned things easily back to normal.

Anyways, after this post I know where I'm at, and I've had a first "cross of swords" with systemd, so I'm greatly enlightened. Thank you all for the help. :)

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Thu Aug 15, 2019 10:38 pm
by Michael Willis
Nachei wrote: I've had a first "cross of swords" with systemd
Did you yell "TASTE COLD STEEL!" when you crossed swords?

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Fri Aug 16, 2019 12:17 am
by merlyn
When I had this problem I was able to lock memory when I changed the number of ports to 1024. The reason that you didn't get the error using jackd is because the default number of ports when using jackd is 256.

For some reason QjackCtl isn't changing the number of ports.

You can change the number of ports with jack_control using this command :

Code: Select all

$ jack_control eps port-max 1024
Then restart JACK.

If that doesn't get rid of the error try a lower number of ports. You already know 256 works :)

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Sat Aug 17, 2019 11:53 pm
by Nachei
Success! Thank you so much merlyn, the jack_control command finally did the trick: good bye to the cannot allocate error, for all qjackctl configurations, and even after rebooting.

There's a peculiar side effect, though. Things go well during the session (although I still have to test further), but when I click "stop" in Qjackctl at the end, now I'm getting these new messages:

Code: Select all

Sat Aug 17 07:28:57 2019: Client 'qjackctl' with PID 1565 is out
Sat Aug 17 07:28:57 2019: Stopping jack server...
Sat Aug 17 07:28:57 2019: Client 'system' with PID 0 is out
Sat Aug 17 07:28:57 2019: Client 'PulseAudio JACK Sink' with PID 1569 is out
Sat Aug 17 07:28:57 2019: Client 'PulseAudio JACK Source' with PID 1569 is out
Sat Aug 17 07:28:57 2019: ERROR: Cannot write socket fd = 16 err = Broken pipe
Sat Aug 17 07:28:57 2019: ERROR: CheckRes error
Sat Aug 17 07:28:57 2019: ERROR: Could not write notification
Sat Aug 17 07:28:57 2019: ERROR: ClientNotify fails name = system notification = 1 val1 = 0 val2 = 0
Sat Aug 17 07:28:57 2019: ERROR: Cannot write socket fd = 19 err = Broken pipe
Sat Aug 17 07:28:57 2019: ERROR: CheckRes error
Sat Aug 17 07:28:57 2019: ERROR: Could not write notification
Sat Aug 17 07:28:57 2019: ERROR: ClientNotify fails name = system notification = 1 val1 = 0 val2 = 0
Sat Aug 17 07:28:57 2019: Released audio card Audio1
Sat Aug 17 07:28:57 2019: ERROR: Cannot write socket fd = 16 err = Broken pipe
Sat Aug 17 07:28:57 2019: ERROR: CheckRes error
Sat Aug 17 07:28:57 2019: ERROR: Could not write notification
Sat Aug 17 07:28:57 2019: ERROR: ClientNotify fails name = freewheel notification = 1 val1 = 0 val2 = 0
Sat Aug 17 07:28:57 2019: ERROR: Cannot write socket fd = 19 err = Broken pipe
Sat Aug 17 07:28:57 2019: ERROR: CheckRes error
Sat Aug 17 07:28:57 2019: ERROR: Could not write notification
Sat Aug 17 07:28:57 2019: ERROR: ClientNotify fails name = freewheel notification = 1 val1 = 0 val2 = 0
This happens with all qjackctl configurations, with or without external soundcard, and with different values for the "jack_control eps port-max" command, from 1024 to 128. I assume it is not a very serious problem, as it happens only at the end and there's always the same number of lines (they don't "heap up" from one session to the next), but, any idea of what they could mean? Anyways, thank you for your help.
Michael Willis wrote:Did you yell "TASTE COLD STEEL!" when you crossed swords?
:lol: No, too bad I didn't... To be honest it was more like Monty Python's bard, "he bravely ran away..." :)

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Sun Aug 18, 2019 3:45 am
by Michael Willis
Nachei wrote:
Michael Willis wrote:Did you yell "TASTE COLD STEEL!" when you crossed swords?
:lol: No, too bad I didn't... To be honest it was more like Monty Python's bard, "he bravely ran away..." :)
His head smashed in
And his heart cut out
And his liver removed

...and other stuff I won't repeat so that I don't get banned...

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Sun Aug 18, 2019 10:28 am
by Linuxmusician01
1. Can one check on a running instance of Jack how many ports it is using?

2. On my current system (Mint 17.1 'Rebecca') I cannot install jack_control and it is not installed. But on my "toy" (antique little laptop) with Debian 10 'Buster' it is installed. How did y'all install jack_control?

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Mon Aug 19, 2019 6:38 am
by Nachei
Linuxmusician01 wrote:How did y'all install jack_control?
In the case of Ubuntu Studio 19, didn't have to install it, it came with it already.

Re: Getting "cannot allocate memory" error, although running in real time

Posted: Mon Aug 19, 2019 7:23 am
by raboof
Linuxmusician01 wrote:On my current system (Mint 17.1 'Rebecca') I cannot install jack_control and it is not installed. But on my "toy" (antique little laptop) with Debian 10 'Buster' it is installed. How did y'all install jack_control?
I think Mint is Debian-based as well right? Then a useful tool is 'apt-file': 'apt-file jack_control' shows this tool is in the jackd2 package.