platforms/posix: mlockall() support

* add basic mlock support to increase stability when system is under high load and RAM is almost full
 * mainly about minimizing or completely eliminating RAM page swap time
This commit is contained in:
SalimTerryLi 2020-11-16 12:53:10 +08:00 committed by GitHub
parent 37567bbee0
commit ad4068f472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -62,6 +62,10 @@
#include <sys/file.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if (_POSIX_MEMLOCK > 0)
#include <sys/mman.h>
#endif
#include <px4_platform_common/time.h>
#include <px4_platform_common/log.h>
@ -174,6 +178,22 @@ int main(int argc, char **argv)
return client.process_args(argc, (const char **)argv);
} else {
#if (_POSIX_MEMLOCK > 0)
// try to lock address space into RAM, to avoid page swap delay
// TODO: Check CAP_IPC_LOCK instead of euid
if (geteuid() == 0) { // root user
if (mlockall(MCL_CURRENT) + mlockall(MCL_FUTURE)) { // check if both works
PX4_ERR("mlockall() failed! errno: %d", errno);
munlockall(); // avoid mlock limitation caused alloc failure in future
} else {
PX4_INFO("mlockall() enabled. PX4's virtual address space is locked into RAM.");
}
}
#endif
/* Server/daemon apps need to parse the command line arguments. */
std::string data_path{};