public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Roland Dreier <roland@topspin.com>
To: Olaf Dietsche <olaf.dietsche#list.linux-kernel@t-online.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: programming for preemption (was: [PATCH] 2.5.46: access permission filesystem)
Date: 11 Nov 2002 10:23:05 -0800	[thread overview]
Message-ID: <528z00neye.fsf@topspin.com> (raw)
In-Reply-To: <87znsgov9e.fsf@goat.bogus.local>

>>>>> "Olaf" == Olaf Dietsche <olaf.dietsche#list.linux-kernel@t-online.de> writes:

    Olaf> So this means kmalloc(GFP_KERNEL) inside spinlock is not
    Olaf> necessarily dangerous, but should be avoided if possible? Is
    Olaf> using a semaphore better than using spinlocks?

You should never kmalloc(GFP_KERNEL) while holding a spinlock, since
it is dangerous even without preempt.  kmalloc(GFP_KERNEL) may sleep,
which will lead to deadlock (the code holding the spinlock gets
scheduled out because of the kmalloc, then some other code tries to
take the lock -- deadlock).

A semaphore is safer, because if you fail to get the semaphore you
will go to sleep, which allows the process that holds the semaphore to
get scheduled again and release it.  However you cannot use semaphores
in interrupt handlers -- you must be in process context when you
down() the semaphore.  (Note that it is OK to up() a semaphore from an
interrupt handler)

Best,
  Roland

  parent reply	other threads:[~2002-11-11 18:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-05 15:51 [PATCH] 2.5.46: access permission filesystem Olaf Dietsche
2002-11-10  1:33 ` Ben Clifford
2002-11-10 15:56   ` Olaf Dietsche
2002-11-11  0:11     ` Ben Clifford
2002-11-11  1:57       ` Olaf Dietsche
2002-11-11  2:27         ` Andrew Morton
2002-11-11 17:45           ` programming for preemption (was: [PATCH] 2.5.46: access permission filesystem) Olaf Dietsche
2002-11-11 18:17             ` programming for preemption (was: [PATCH] 2.5.46: accesspermission filesystem) Andrew Morton
2002-11-11 23:19               ` Olaf Dietsche
2002-11-11 18:23             ` Roland Dreier [this message]
2002-11-11 23:58             ` programming for preemption (was: [PATCH] 2.5.46: access permission filesystem) Zwane Mwaikambo

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=528z00neye.fsf@topspin.com \
    --to=roland@topspin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf.dietsche#list.linux-kernel@t-online.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