ES mlockall作用——preventing that memory from being paged to the swap area

elasticsearch还有一个重要的参数bootstrap.mlockall,这个参数的目的是当你无法关闭系统的swap的时候,建议把这个参数设为true。防止在内存不够用的时候,elasticsearch的内存被交换至交换区,导致性能骤降

 

mlock, munlock, mlockall, munlockall - lock and unlock memory

Synopsis

#include <sys/mman.h>

int mlock(const void *addr, size_t len);
int munlock(const void *addr, size_t len);

int mlockall(int flags);
int munlockall(void);

Description

mlock() and mlockall() respectively lock part or all of the calling process's virtual address space into RAM, preventing that memory from being paged to the swap areamunlock() andmunlockall() perform the converse operation, respectively unlocking part or all of the calling process's virtual address space, so that pages in the specified virtual address range may once more to be swapped out if required by the kernel memory manager. Memory locking and unlocking are performed in units of whole pages.

 

mlock系统调用的作用mlock系统调用允许程序在物理内存上锁住它的部分或全部地址空间,这将阻止Linux将这个内存页调度到交换空间(即阻止系统将某个页面换出到交换分区),即使该程序已有一段时间没有访问这段空间。一个严格时间相关的程序可能会希望锁住物理内存,因为内存页面调出调入的时间延迟可能太长或过于不可预知。安全性要求较高的应用程序可能希望防止敏感数据被换出到交换文件中,因为这样在程序结束后,攻击者可能从交换文件中恢复出这些数据。锁定一个内存区间只需简单将指向区间开始的指针及区间长度作为参数调用mlock()Linux分配内存到页且每次只能锁定整页内存,被指定的区间涉及到的每个内存页都将被锁定。

 

参考:https://linux.die.net/man/2/mlockall

posted @   bonelee  阅读(633)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示