[PATCH v2] ipc: only destroy orphaned shm segments on sysctl write
From: Jianlin Shi
Date: Sun Jun 14 2026 - 22:28:26 EST
proc_ipc_dointvec_minmax_orphans() currently calls
shm_destroy_orphaned() whenever shm_rmid_forced is set, including on
sysctl reads. Reading /proc/sys/kernel/shm_rmid_forced should not take
shm_ids rwsem for write and walk all segments.
Only run the cleanup when the sysctl is written and the forced RMID
policy is enabled.
When shm_rmid_forced=1, monitoring tools that read
/proc/sys/kernel/shm_rmid_forced trigger the cleanup on every read.
Changes in v2:
- No functional changes since v1
- Reposting after no responses for two weeks (v1 sent on 2 Jun 2026)
Link: https://lore.kernel.org/all/?q=only+destroy+orphaned+shm+segments+on+sysctl+write
Signed-off-by: Jianlin Shi <shijianlin11@xxxxxxxxxxx>
---
ipc/ipc_sysctl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index 71d0a4ef5..8bf0e9a5f 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -28,7 +28,7 @@ static int proc_ipc_dointvec_minmax_orphans(const struct ctl_table *table, int w
if (err < 0)
return err;
- if (ns->shm_rmid_forced)
+ if (write && ns->shm_rmid_forced)
shm_destroy_orphaned(ns);
return err;
}
--
2.43.0