*/
if (next_id < 0) { /* !CHECKPOINT_RESTORE or next_id is unset */
+ int max_idx;
+
+ max_idx = max(ids->in_use*3/2, ipc_min_cycle);
+ max_idx = min(max_idx, ipc_mni);
/* allocate the idx, with a NULL struct kern_ipc_perm */
- idx = idr_alloc(&ids->ipcs_idr, NULL, 0, 0, GFP_NOWAIT);
+ idx = idr_alloc_cyclic(&ids->ipcs_idr, NULL, 0, max_idx,
+ GFP_NOWAIT);
if (idx >= 0) {
/*