mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 09:22:18 +00:00
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:
@@ -62,6 +62,10 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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/time.h>
|
||||||
#include <px4_platform_common/log.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);
|
return client.process_args(argc, (const char **)argv);
|
||||||
|
|
||||||
} else {
|
} 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. */
|
/* Server/daemon apps need to parse the command line arguments. */
|
||||||
|
|
||||||
std::string data_path{};
|
std::string data_path{};
|
||||||
|
|||||||
Reference in New Issue
Block a user