The patch titled Subject: ipc: do cyclic id allocation with ipcmni_extend mode has been added to the -mm tree. Its filename is ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Waiman Long <longman@xxxxxxxxxx> Subject: ipc: do cyclic id allocation with ipcmni_extend mode For ipcmni_extend mode, the sequence number space is only 7 bits. So the chance of id reuse is relatively high compared with the non-extended mode. To alleviate this id reuse problem, the id allocation will be done cyclically to cycle through all the 24-bit id space before wrapping around when in ipcmni_extend mode. This may cause the use of more memory in term of the number of xa_nodes allocated as well as potentially more cachelines used as the xa_nodes may be spread more sparsely in this case. There is probably a slight memory and performance cost in doing cyclic id allocation. For applications that really need more than 32k unique IPC identifiers, this is a small price to pay to avoid the id reuse problem. As a result, the chance of id reuse should be even smaller in the ipcmni_extend mode. For users who worry about id reuse, they can turn on ipcmni_extend mode, even if they don't need more than 32k IPC identifiers. Link: http://lkml.kernel.org/r/1551379645-819-4-git-send-email-longman@xxxxxxxxxx Signed-off-by: Waiman Long <longman@xxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Davidlohr Bueso <dbueso@xxxxxxx> Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Cc: Jonathan Corbet <corbet@xxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Cc: "Luis R. Rodriguez" <mcgrof@xxxxxxxxxx> Cc: Manfred Spraul <manfred@xxxxxxxxxxxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Cc: Takashi Iwai <tiwai@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- Documentation/admin-guide/kernel-parameters.txt | 5 ++++- ipc/ipc_sysctl.c | 2 ++ ipc/util.c | 7 ++++++- ipc/util.h | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) --- a/Documentation/admin-guide/kernel-parameters.txt~ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode +++ a/Documentation/admin-guide/kernel-parameters.txt @@ -1813,7 +1813,10 @@ See Documentation/filesystems/nfs/nfsroot.txt. ipcmni_extend [KNL] Extend the maximum number of unique System V - IPC identifiers from 32,768 to 16,777,216. + IPC identifiers from 32,768 to 16,777,216. Also do + cyclical identifier allocation through the entire + 24-bit identifier space to reduce the chance of + identifier reuse. irqaffinity= [SMP] Set the default irq affinity mask The argument is a cpu list, as described above. --- a/ipc/ipc_sysctl.c~ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode +++ a/ipc/ipc_sysctl.c @@ -122,6 +122,7 @@ static int one = 1; static int int_max = INT_MAX; int ipc_mni = IPCMNI; int ipc_mni_shift = IPCMNI_SHIFT; +bool ipc_mni_extended; static struct ctl_table ipc_kern_table[] = { { @@ -252,6 +253,7 @@ static int __init ipc_mni_extend(char *s { ipc_mni = IPCMNI_EXTEND; ipc_mni_shift = IPCMNI_EXTEND_SHIFT; + ipc_mni_extended = true; pr_info("IPCMNI extended to %d.\n", ipc_mni); return 0; } --- a/ipc/util.c~ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode +++ a/ipc/util.c @@ -221,7 +221,12 @@ static inline int ipc_idr_alloc(struct i */ if (next_id < 0) { /* !CHECKPOINT_RESTORE or next_id is unset */ - idx = idr_alloc(&ids->ipcs_idr, new, 0, 0, GFP_NOWAIT); + if (ipc_mni_extended) + idx = idr_alloc_cyclic(&ids->ipcs_idr, new, 0, ipc_mni, + GFP_NOWAIT); + else + idx = idr_alloc(&ids->ipcs_idr, new, 0, 0, GFP_NOWAIT); + if ((idx <= ids->last_idx) && (++ids->seq > IPCID_SEQ_MAX)) ids->seq = 0; new->seq = ids->seq; --- a/ipc/util.h~ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode +++ a/ipc/util.h @@ -33,6 +33,7 @@ #ifdef CONFIG_SYSVIPC_SYSCTL extern int ipc_mni; extern int ipc_mni_shift; +extern bool ipc_mni_extended; #define IPCMNI_SEQ_SHIFT ipc_mni_shift #define IPCMNI_IDX_MASK ((1 << ipc_mni_shift) - 1) @@ -40,6 +41,7 @@ extern int ipc_mni_shift; #else /* CONFIG_SYSVIPC_SYSCTL */ #define ipc_mni IPCMNI +#define ipc_mni_extended false #define IPCMNI_SEQ_SHIFT IPCMNI_SHIFT #define IPCMNI_IDX_MASK ((1 << IPCMNI_SHIFT) - 1) #endif /* CONFIG_SYSVIPC_SYSCTL */ _ Patches currently in -mm which might be from longman@xxxxxxxxxx are debugobjects-move-printk-out-of-db-lock-critical-sections.patch include-linux-nodemaskh-use-nr_node_ids-not-max_numnodes-in-__nodemask_pr_numnodes.patch ipc-allow-boot-time-extension-of-ipcmni-from-32k-to-16m.patch ipc-conserve-sequence-numbers-in-ipcmni_extend-mode.patch ipc-do-cyclic-id-allocation-with-ipcmni_extend-mode.patch