mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Jens Axboe <axboe@suse.de>, <linux-kernel@vger.kernel.org>,
	Suparna Bhattacharya <suparna@in.ibm.com>
Subject: [patch] mempool-2.5.1-D1
Date: Fri, 14 Dec 2001 19:14:54 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.33.0112141908420.12688-200000@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.33.0112141446030.8724-100000@localhost.localdomain>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 288 bytes --]


there is another thinko in the mempool code, reported by Suparna
Bhattacharya. If mempool_alloc() is called from an IRQ context then we
return too early. The correct behavior is to allocate GFP_ATOMIC, if that
fails then we look at the pool and return an element, or return NULL.

	Ingo

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1883 bytes --]

--- linux/mm/mempool.c.orig	Fri Dec 14 16:55:12 2001
+++ linux/mm/mempool.c	Fri Dec 14 17:03:52 2001
@@ -176,7 +176,8 @@
  *
  * this function only sleeps if the alloc_fn function sleeps or
  * returns NULL. Note that due to preallocation, this function
- * *never* fails.
+ * *never* fails when called from process contexts. (it might
+ * fail if called from an IRQ context.)
  */
 void * mempool_alloc(mempool_t *pool, int gfp_mask)
 {
@@ -185,7 +186,7 @@
 	struct list_head *tmp;
 	int curr_nr;
 	DECLARE_WAITQUEUE(wait, current);
-	int gfp_nowait = gfp_mask & ~__GFP_WAIT;
+	int gfp_nowait = gfp_mask & ~(__GFP_WAIT | __GFP_IO);
 
 repeat_alloc:
 	element = pool->alloc(gfp_nowait, pool->pool_data);
@@ -196,15 +197,11 @@
 	 * If the pool is less than 50% full then try harder
 	 * to allocate an element:
 	 */
-	if (gfp_mask != gfp_nowait) {
-		if (pool->curr_nr <= pool->min_nr/2) {
-			element = pool->alloc(gfp_mask, pool->pool_data);
-			if (likely(element != NULL))
-				return element;
-		}
-	} else
-		/* we must not sleep */
-		return NULL;
+	if ((gfp_mask != gfp_nowait) && (pool->curr_nr <= pool->min_nr/2)) {
+		element = pool->alloc(gfp_mask, pool->pool_data);
+		if (likely(element != NULL))
+			return element;
+	}
 
 	/*
 	 * Kick the VM at this point.
@@ -217,10 +214,12 @@
 		list_del(tmp);
 		element = tmp;
 		pool->curr_nr--;
-		spin_unlock_irqrestore(&pool->lock, flags);
-
-		return element;
+		goto out_unlock;
 	}
+	/* We must not sleep in the GFP_ATOMIC case */
+	if (gfp_mask == gfp_nowait)
+		goto out_unlock;
+
 	add_wait_queue_exclusive(&pool->wait, &wait);
 	set_task_state(current, TASK_UNINTERRUPTIBLE);
 
@@ -236,6 +235,9 @@
 	remove_wait_queue(&pool->wait, &wait);
 
 	goto repeat_alloc;
+out_unlock:
+	spin_unlock_irqrestore(&pool->lock, flags);
+	return element;
 }
 
 /**

  reply	other threads:[~2001-12-14 16:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-14 13:49 [patch] mempool-2.5.1-D0 Ingo Molnar
2001-12-14 18:14 ` Ingo Molnar [this message]
2001-12-14 19:13   ` [patch] mempool-2.5.1-D2 Ingo Molnar
2001-12-14 22:27     ` Benjamin LaHaise
2001-12-15  6:41       ` Ingo Molnar
2001-12-15  5:29         ` Benjamin LaHaise
2001-12-18  0:46         ` Pavel Machek
2001-12-15 17:50       ` Stephan von Krawczynski

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=Pine.LNX.4.33.0112141908420.12688-200000@localhost.localdomain \
    --to=mingo@elte.hu \
    --cc=axboe@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=suparna@in.ibm.com \
    --cc=torvalds@transmeta.com \
    /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®