[PATCH 2/4] idr: reduce the number of MAX_IDR_FREE

From: Lai Jiangshan
Date: Tue Apr 22 2014 - 06:15:18 EST


Whe need to prepare MAX_IDR_FREE idr_layers for allocation.

But when idr is not empty, we need atmost (MAX_IDR_LEVEL - 1) idr_layers
to build up and atmost (MAX_IDR_LEVEL - 1) idr_layers to allocate down.
When idr is empty need atmost MAX_IDR_LEVEL layers.

So max((MAX_IDR_LEVEL * 2 - 2), MAX_IDR_LEVEL) idr_layers is enough.

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
---
lib/idr.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/idr.c b/lib/idr.c
index 87c98fc..871991b 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -36,8 +36,13 @@
/* Leave the possibility of an incomplete final layer */
#define MAX_IDR_LEVEL ((MAX_IDR_SHIFT + IDR_BITS - 1) / IDR_BITS)

-/* Number of id_layer structs to leave in free list */
-#define MAX_IDR_FREE (MAX_IDR_LEVEL * 2)
+/*
+ * Number of idr_layer structs to leave in free list.
+ * When idr is not empty, we need atmost (MAX_IDR_LEVEL - 1) idr_layers
+ * to build up and atmost (MAX_IDR_LEVEL - 1) idr_layers to allocate down.
+ * When idr is empty need atmost MAX_IDR_LEVEL layers.
+ */
+#define MAX_IDR_FREE max((MAX_IDR_LEVEL * 2 - 2), MAX_IDR_LEVEL)

static struct kmem_cache *idr_layer_cache;
static DEFINE_PER_CPU(struct idr_layer *, idr_preload_head);
--
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/