Re: [PATCH v2 3/3] ipc/sem: remove obsolete SEMOPM fragmentation warning
From: Manfred Spraul
Date: Fri Oct 23 2026 - 15:32:38 EST
Hi Yingjie,
On 10/23/26 5:19 AM, Yingjie Wang wrote:
The UAPI comment advises keeping SEMOPM at or below 1000 because a larger
operation array may fail due to physical memory fragmentation.
Commit e4243b8062c1 ("ipc/sem: play nicer with large nsops allocations")
changed the operation array to kvmalloc() specifically to support larger
configured limits, with vmalloc fallback when a physically contiguous
allocation is unavailable.
Replace the obsolete warning with a description of the compiled-in
default and the runtime sysctl.
Signed-off-by: Yingjie Wang <x-professor@xxxxxxxxxxx>
---
include/uapi/linux/sem.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/sem.h b/include/uapi/linux/sem.h
index 75aa3b273cd99..cfd772f4c3396 100644
--- a/include/uapi/linux/sem.h
+++ b/include/uapi/linux/sem.h
@@ -71,16 +71,15 @@ struct seminfo {
* The values has been chosen to be larger than necessary for any
* known configuration.
*
- * SEMOPM should not be increased beyond 1000, otherwise there is the
- * risk that semop()/semtimedop() fails due to kernel memory fragmentation when
- * allocating the sop array.
+ * SEMOPM is the default maximum number of operations per semop() call. The
+ * runtime limit can be changed through /proc/sys/kernel/sem.
*/
#define SEMMNI 32000 /* <= IPCMNI max # of semaphore identifiers */
#define SEMMSL 32000 /* <= INT_MAX max num of semaphores per id */
#define SEMMNS (SEMMNI*SEMMSL) /* <= INT_MAX max # of semaphores in system */
-#define SEMOPM 500 /* <= 1 000 max num of ops per semop call */
+#define SEMOPM 500 /* default max num of ops per semop call */
#define SEMVMX 32767 /* <= 32767 semaphore maximum value */
#define SEMAEM SEMVMX /* adjust on exit max value */
I think there is a conceptual issue, but perhaps it is today not relevant anymore:
The values in uapi/linux/{sem,shm,msg}.h can be adapted as needed: Just change the values to what you need, compile a new kernel and you have a suitable system, even without sysctl compiled in.
Your change breaks this: SEMOPM is both the compiled in value, and the implied limit when _ACCOUNT is used. If someone increases SEMOPM in the header file - suddenly more unaccounted memory can be allocated.
Perhaps there should be two defines: SEMOPM and e.g. SEMOPM_NOACCOUNT?
SEPMOPM_NOACCOUNT defined in ipc/sem.c, perhaps 500 or 1000.
And SEMOPM remains in the uapi header file.
Minor point: So far, the format of all limits is identical. Could we keep this?
#define VALUE 1234 /* <= 4321, due to whatever reason */
Perhaps something like:
-#define SEMOPM 500 /* <= 1 000 max num of ops per semop call */Reviewed-By: Manfred Spraul <manfred@xxxxxxxxxxxxxxxx>
+#define SEMOPM 500 /* <= INT_MAX max num of ops per semop call */
--
Manfred