ipc: add shm_locked for IPC shm
RFC PATCH 1/1 ipc: add shm_locked for IPC shm
From: Hiroshi Shimamoto <[email protected]>
Shared memory users probably don't think the shared memory is swapped out. But actually shared memory could be swapped out under memory pressure.
Linux has SHM_LOCK feature for prevent shared memory swapping, and it can be used by shmctl() after create the shared memory. There are some needs that SHM_LOCK is default behavior.
This patch adds shm_locked sysctl to turn SHM_LOCK on when creating. kernel.shm_locked = 0, is default and the behavior is not changed. kernel.shm_locked = 1, means shared memory will be locked when it's created.
Signed-off-by Hiroshi Shimamoto <[email protected]>
--- include/linux/ipc_namespace.h | 1 + include/linux/sysctl.h | 1 + ipc/ipc_sysctl.c | 9 +++++ ipc/shm.c | 70 ++++++++++++++++++++++++---------------- kernel/sysctl_check.c | 2 + 5 files changed, 55 insertions(+), 28 deletions(-)
include/linux/ipc_namespace.h +1 -0
@@ -29,6 +29,7 @@ struct ipc_namespace {size_t shm_ctlmax;size_t shm_ctlall;int shm_ctlmni; +int shm_ctllocked;int shm_tot; };
include/linux/sysctl.h +1 -0
@@ -163,6 +163,7 @@ enumKERN_MAX_LOCK_DEPTH =74 ,KERN_NMI_WATCHDOG =75 ,/* int: enable/disable nmi watchdog */ KERN_PANIC_ON_NMI =76 ,/* int: whether we will panic on an unrecovered */ + KERN_SHMLOCKED=77, /* int: make shared memory locked */ };
ipc/ipc_sysctl.c +9 -0
@@ -123,6 +123,15 @@ static struct ctl_table ipc_kern_table[] = { .strategy = sysctl_ipc_data, }, { + .ctl_name = KERN_SHMLOCKED, + .procname = "shm_locked", + .data = &init_ipc_ns.shm_ctllocked, + .maxlen = sizeof (init_ipc_ns.shm_ctllocked), + .mode = 0644, + .proc_handler = proc_ipc_dointvec, + .strategy = sysctl_ipc_data, + }, + { .ctl_name = KERN_MSGMAX, .procname = "msgmax", .data = &init_ipc_ns.msg_ctlmax,
ipc/shm.c +42 -28
100 lines not on this page · raw message
kernel/sysctl_check.c +2 -0
@@ -104,6 +104,8 @@ static const struct trans_ctl_table trans_kern_table[] = { { KERN_MAX_LOCK_DEPTH, "max_lock_depth" }, { KERN_NMI_WATCHDOG, "nmi_watchdog" }, { KERN_PANIC_ON_NMI, "panic_on_unrecovered_nmi" }, + + { KERN_SHMLOCKED, "shm_locked" }, {} };
Signature · 1 line
1.5.4.1