mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH 1/2] posix-timers: move global timer id management to signal_struct v4
Date: Tue, 20 Sep 2011 01:07:05 +0200	[thread overview]
Message-ID: <1316473625.2455.30.camel@edumazet-laptop> (raw)
In-Reply-To: <1316472096.2455.27.camel@edumazet-laptop>

Le mardi 20 septembre 2011 à 00:41 +0200, Eric Dumazet a écrit :

> I'll provide not a hack but a clean patch for this.
> 

Here is a draft, just in case. (not even booted, its late here...)

I'll test it tomorrow with a variant of your patch.


 include/linux/idr.h |   13 +++++++++++++
 lib/idr.c           |   32 +++++++++++++++++++++-----------
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/include/linux/idr.h b/include/linux/idr.h
index 255491c..a6b7655 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -64,6 +64,14 @@ struct idr {
 	spinlock_t	  lock;
 };
 
+/* special id_free_cnt value to mark idr without freelist */
+#define IDR_NOFREELIST -1
+
+static inline bool idr_nofreelist(const struct idr *idr)
+{
+	return idr->id_free_cnt == IDR_NOFREELIST;
+}
+
 #define IDR_INIT(name)						\
 {								\
 	.top		= NULL,					\
@@ -114,6 +122,11 @@ void idr_remove_all(struct idr *idp);
 void idr_destroy(struct idr *idp);
 void idr_init(struct idr *idp);
 
+static inline void idr_nofreelist_init(struct idr *idp)
+{
+	idr_init(idp);
+	idp->id_free_cnt = IDR_NOFREELIST;
+}
 
 /*
  * IDA - IDR based id allocator, use when translation from id to
diff --git a/lib/idr.c b/lib/idr.c
index db040ce..d4ce74d 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -44,6 +44,9 @@ static struct idr_layer *get_from_free_list(struct idr *idp)
 	struct idr_layer *p;
 	unsigned long flags;
 
+	if (idr_nofreelist(idp))
+		return kmem_cache_zalloc(idr_layer_cache, GFP_KERNEL);
+
 	spin_lock_irqsave(&idp->lock, flags);
 	if ((p = idp->id_free)) {
 		idp->id_free = p->ary[0];
@@ -77,14 +80,17 @@ static void __move_to_free_list(struct idr *idp, struct idr_layer *p)
 
 static void move_to_free_list(struct idr *idp, struct idr_layer *p)
 {
-	unsigned long flags;
-
-	/*
-	 * Depends on the return element being zeroed.
-	 */
-	spin_lock_irqsave(&idp->lock, flags);
-	__move_to_free_list(idp, p);
-	spin_unlock_irqrestore(&idp->lock, flags);
+	if (idr_nofreelist(idp)) {
+		kmem_cache_free(idr_layer_cache, p);
+	} else {
+		unsigned long flags;
+		/*
+		 * Depends on the return element being zeroed.
+		 */
+		spin_lock_irqsave(&idp->lock, flags);
+		__move_to_free_list(idp, p);
+		spin_unlock_irqrestore(&idp->lock, flags);
+	}
 }
 
 static void idr_mark_full(struct idr_layer **pa, int id)
@@ -122,6 +128,7 @@ static void idr_mark_full(struct idr_layer **pa, int id)
  */
 int idr_pre_get(struct idr *idp, gfp_t gfp_mask)
 {
+	BUG_ON(idr_nofreelist(idp));
 	while (idp->id_free_cnt < IDR_FREE_MAX) {
 		struct idr_layer *new;
 		new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
@@ -243,7 +250,10 @@ build_up:
 				p = p->ary[0];
 				new->ary[0] = NULL;
 				new->bitmap = new->count = 0;
-				__move_to_free_list(idp, new);
+				if (idr_nofreelist(idp))
+					kmem_cache_free(idr_layer_cache, p);
+				else
+					__move_to_free_list(idp, new);
 			}
 			spin_unlock_irqrestore(&idp->lock, flags);
 			return -1;
@@ -487,7 +497,7 @@ EXPORT_SYMBOL(idr_remove_all);
  */
 void idr_destroy(struct idr *idp)
 {
-	while (idp->id_free_cnt) {
+	while (idp->id_free_cnt > 0) {
 		struct idr_layer *p = get_from_free_list(idp);
 		kmem_cache_free(idr_layer_cache, p);
 	}
@@ -839,7 +849,7 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
 	 * Throw away extra resources one by one after each successful
 	 * allocation.
 	 */
-	if (ida->idr.id_free_cnt || ida->free_bitmap) {
+	if (ida->idr.id_free_cnt > 0 || ida->free_bitmap) {
 		struct idr_layer *p = get_from_free_list(&ida->idr);
 		if (p)
 			kmem_cache_free(idr_layer_cache, p);



  reply	other threads:[~2011-09-19 23:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19 21:48 Andi Kleen
2011-09-19 21:48 ` [PATCH 2/2] posix-timers: limit the number of posix timers per process v2 Andi Kleen
2011-09-19 22:23 ` [PATCH 1/2] posix-timers: move global timer id management to signal_struct v4 Eric Dumazet
2011-09-19 22:36   ` Andi Kleen
2011-09-19 22:41     ` Eric Dumazet
2011-09-19 23:07       ` Eric Dumazet [this message]
2011-09-19 23:11       ` Andi Kleen
2011-09-19 23:15         ` Eric Dumazet
2011-09-20  9:51       ` Thomas Gleixner
2011-09-20  9:19 ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316473625.2455.30.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®