ubuntu20.04 将 max locked memory从默认的65536改为无限制

发布时间 2023-10-02 16:54:18作者: ac23

RDMA开发中,需要注册Memory Rigon,需要比较大的内存区域,如果不把Ubuntu20.04系统默认的max locked memory从默认的65536改为unlimited,将会报出这个错误:Couldn't allocate MR
解决办法如下(感谢chatGPT老师哈哈)

To set the maximum locked memory from 65536 to unlimited on Ubuntu 20.04, you can follow these steps:

1.Open a terminal window by pressing Ctrl + Alt + T or by searching for "Terminal" in the application launcher.

2.Edit the /etc/security/limits.conf file using a text editor such as nano or vi. For example, run the following command to open the file with nano:

sudo nano /etc/security/limits.conf

3.Scroll down to the end of the file and add the following lines:

  •     hard    memlock     unlimited
    
  •     soft    memlock     unlimited
    

These lines will set the maximum locked memory (memlock) to unlimited for all users (*).

4.Save the changes in nano by pressing Ctrl + O, then press Enter to confirm the filename. Exit nano by pressing Ctrl + X.

5.Next, edit the /etc/systemd/user.conf.d/override.conf file by running the following command:

sudo nano /etc/systemd/user.conf.d/override.conf

6.Add the following line to the file:

DefaultLimitMEMLOCK=infinity

This line sets the default memory lock limit to infinity.

7.Save the changes and exit nano as mentioned in step 4.

8.Finally, restart your system or log out and log back in for the changes to take effect.

After completing these steps, the maximum locked memory should be set to unlimited (infinity) for all users on your Ubuntu 20.04 system.