# LibUring - low memlock limit

**URL:** <https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826>\
**Category:** mediasoup libraries\
**Created:** [February 6, 2024, 2:37pm UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826 "2024-02-06T14:37:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Astagor](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/astagor/32/2515_2.png) [@Astagor](https://mediasoup.discourse.group/u/Astagor)\
**Post date:** [February 6, 2024, 2:37pm UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826/1 "2024-02-06T14:37:04Z")

</div>

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  
LimitMEMLOCK=134217728

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.

---

<div class="post-metadata">

**Author:** ![jmillan](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jmillan/32/9_2.png) [@jmillan](https://mediasoup.discourse.group/u/jmillan)\
**Post date:** [February 6, 2024, 5:17pm UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826/2 "2024-02-06T17:17:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Astagor](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/astagor/32/2515_2.png) [@Astagor](https://mediasoup.discourse.group/u/Astagor)\
**Post date:** [February 6, 2024, 5:31pm UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826/3 "2024-02-06T17:31:24Z")

</div>

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:  
LimitMEMLOCK=infinity

See here for reference: [How to set ulimits on service with systemd? - Unix & Linux Stack Exchange](https://unix.stackexchange.com/a/345596)

---

<div class="post-metadata">

**Author:** ![jmillan](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jmillan/32/9_2.png) [@jmillan](https://mediasoup.discourse.group/u/jmillan)\
**Post date:** [February 7, 2024, 9:25am UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826/4 "2024-02-07T09:25:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Astagor](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/astagor/32/2515_2.png) [@Astagor](https://mediasoup.discourse.group/u/Astagor)\
**Post date:** [February 7, 2024, 9:40am UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826/5 "2024-02-07T09:40:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jmillan](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jmillan/32/9_2.png) [@jmillan](https://mediasoup.discourse.group/u/jmillan)\
**Post date:** [February 13, 2024, 10:28am UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826/6 "2024-02-13T10:28:28Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Astagor](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/astagor/32/2515_2.png) [@Astagor](https://mediasoup.discourse.group/u/Astagor)\
**Post date:** [February 13, 2024, 10:58am UTC](https://mediasoup.discourse.group/t/liburing-low-memlock-limit/5826/7 "2024-02-13T10:58:32Z")

</div>

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!
