Re: [PATCH v12 3/3] ipc: Do cyclic id allocation with ipcmni_extend mode
From: Manfred Spraul
Date: Tue Mar 19 2019 - 14:18:48 EST
This is a multi-part message in MIME format.
Hi Waiman,
On 3/18/19 7:46 PM, Waiman Long wrote:
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -221,9 +221,17 @@ static inline int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new)
*/
if (next_id < 0) { /* !CHECKPOINT_RESTORE or next_id is unset */
+ int max_idx;
+
+ max_idx = ids->in_use*3/2;
+ if (max_idx > ipc_mni)
+ max_idx = ipc_mni;
+ if (max_idx < ipc_min_cycle)
+ max_idx = ipc_min_cycle;
Why don't you use the min() and max() macros which will make it easier
to read?
Changed.
/* 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) {
/*
diff --git a/ipc/util.h b/ipc/util.h
index 8c834ed39012..ef4e86bb2db8 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -27,12 +27,14 @@
*/
#define IPCMNI_SHIFT 15
#define IPCMNI_EXTEND_SHIFT 24
+#define IPCMNI_EXTEND_MIN_CYCLE (2 << 12)
How about
#define IPCMNI_EXTEND_MIN_CYCLEÂÂÂ (RADIX_TREE_MAP_SIZE *
RADIX_TREE_MAP_SIZE)
Good idea.
Actually, "2<<12" was the initial guess.
And then I noticed that this ends up as a two level radix tree during
testing :-)
Updated patch attached.
--
ÂÂÂ Manfred