LINUX:如何在内存中锁定进程的页面 [英] LINUX: How to lock the pages of a process in memory

查看:74
本文介绍了LINUX:如何在内存中锁定进程的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台LINUX服务器,该服务器运行的进程占用大量内存(某种数据库引擎).此过程分配的内存太大,以致于其中的一部分需要换出(分页).

我想做的是将所有其他进程(或正在运行的进程的子集)的内存页锁定在内存中,以便仅交换数据库进程的页.例如,我想确保我可以继续远程连接并监视计算机,而不会受到交换过程的影响.IE.我希望sshd,X,top,vmstat等具有所有驻留页面的内存.

在linux上,有mlock()和mlockall()系统调用似乎提供了正确的旋钮来进行固定.不幸的是,在我看来,我需要在每个进程内进行显式调用,并且不能从其他进程或父进程调用mlock()(在fork()或evecve()之后,mlock()不会继承).

任何帮助将不胜感激.虚拟披萨提供啤酒:-).

解决方案

自从我这样做已经有一段时间了,所以我可能错过了一些步骤.

制作一个包含以下内容的GDB命令文件:

 调用mlockall(3)分离 

然后在命令行上,找到要锁定的进程的PID.类型:
gdb --pid [PID] --batch -x [命令文件]

如果您喜欢 pgrep ,可能是:
gdb --pid $(pgrep sshd)--batch -x [命令文件]

I have a LINUX server running a process with a large memory footprint (some sort of a database engine). The memory allocated by this process is so large that part of it needs to be swapped (paged) out.

What I would like to do is to lock the memory pages of all the other processes (or a subset of the running processes) in memory, so that only the pages of the database process get swapped out. For example I would like to make sure that i can continue to connect remotely and monitor the machine without having the processes impacted by swapping. I.e. I want sshd, X, top, vmstat, etc to have all pages memory resident.

On linux there are the mlock(), mlockall() system calls that seem to offer the right knob to do the pinning. Unfortunately, it seems to me that I need to make an explicit call inside every process and cannot invoke mlock() from a different process or from the parent (mlock() is not inherited after fork() or evecve()).

Any help is greatly appreciated. Virtual pizza & beer offered :-).

解决方案

It has been a while since I've done this so I may have missed a few steps.

Make a GDB command file that contains something like this:

call mlockall(3)
detach

Then on the command line, find the PID of the process you want to mlock. Type:
gdb --pid [PID] --batch -x [command file]

If you get fancy with pgrep that could be:
gdb --pid $(pgrep sshd) --batch -x [command file]

这篇关于LINUX:如何在内存中锁定进程的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆