LibUring - low memlock limit

With the version using liburig I get a warning:
io_uring_register_buffers() failed due to low memlock limit (ulimit -l)

I run my mediasoup as www-data and I have increased the umlimit to 128 MB in the service file that starts mediasoup

When I check the limits for a running mediasoup process I get
Max locked memory 134217728 134217728 bytes

But still the warning get displayed. How much memory does it need?

When I run as root it does not show the warning.

Hi @Astagor,

That memory amount should be more than enough. Can you try setting it to unlimited to discard any other problem? If that works, increase the current value until you don’t get that message and tell us such value please.

Well, 512 MB worked, as well as unlimited.
For people who run as a service in Linux you should add to your .service file
in the [Service] section:

See here for reference: How to set ulimits on service with systemd? - Unix & Linux Stack Exchange

1 Like

It should definitely not need so much locked memory for the user. We’ll check it and see were the problem is.

1 Like

Thanks. It was Ubuntu 22.04 Desktop. Mediasoup running as www-data user.

I’ve tested myself and it needs ~=18MB for the current setup, which is the allocation of 4096 buffers of 1500 bytes each.

2024-02-13T10:16:18.698Z mediasoup:Channel [pid:1465711] DepLibUring::ClassInit() | liburing version: "2.4"
2024-02-13T10:16:18.698Z mediasoup:Channel [pid:1465711] DepLibUring::IsRuntimeSupported() | kernel version: #1 SMP PREEMPT_DYNAMIC Debian 6.1.55-1 (2023-09-29)
2024-02-13T10:16:18.700Z mediasoup:Channel [pid:1465711] DepLibUring::LibUring() | RLIMIT_MEMLOCK 18874368 18874368
2024-02-13T10:16:18.706Z mediasoup:Channel [pid:1465711] DepLibUring::ClassInit() | liburing supported, enabled

Even if 4096 * 1500 is definitely lower than 18MB, each registered buffer takes one page, which is 4KB, meaning 4096*4096=16MB plus some extra storage needed for the metadata ~= 18MB.

In the near future we’ll make the number of allocated buffers configurable.

NOTE 1: In a next PR we’ll print the current memlock limits when too low.
NOTE 2: The fact that zero copy is not enabled is not crucial. Most of the benefits of io_uring will apply regardless.

Thanks for the test. Maybe it was because of the total memory all workers needed? If you say 18 MB per worker, we use 1 worker per CPU core and we had 16 CPU cores, then 288 MB would be the total memory needed. After you add the printing of the limits, maybe the issue will become clearer. Thanks!