public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Olaf Dietsche <olaf.dietsche#list.linux-kernel@t-online.de>
To: Andrew Morton <akpm@digeo.com>, Roland Dreier <roland@topspin.com>
Cc: Ben Clifford <benc@hawaga.org.uk>, linux-kernel@vger.kernel.org
Subject: Re: programming for preemption (was: [PATCH] 2.5.46: accesspermission  filesystem)
Date: Tue, 12 Nov 2002 00:19:34 +0100	[thread overview]
Message-ID: <87u1inofsp.fsf@goat.bogus.local> (raw)
In-Reply-To: 3DCFF447.43EE55FE@digeo.com

Andrew Morton <akpm@digeo.com> writes:

> Olaf Dietsche wrote:
>> 
>> Thanks for this hint. So this means kmalloc(GFP_KERNEL) inside
>> spinlock is not necessarily dangerous, but should be avoided if
>> possible?
>
> It can lock an SMP kernel up.  This CPU can switch to another task in the
> page allocator and then, within the context of the new task, come around
> and try to take the same lock.

Alright, this means kmalloc(GFP_KERNEL) inside spinlock is a bug.

>> Is using a semaphore better than using spinlocks?

Andrew Morton <akpm@digeo.com> writes:

> A semaphore won't have that problem.  If your CPU comes around again onto
> the already-held lock it will just switch to another task.

Roland Dreier <roland@topspin.com> writes:

> 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)

So, as a rule of thumb, I would say use semaphores, if you need some
locking. And in interrupt context, use spinlocks. Do spinlocks have
other benefits, beside being interrupt safe?

Regards, Olaf.

  reply	other threads:[~2002-11-11 23:13 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 [this message]
2002-11-11 18:23             ` programming for preemption (was: [PATCH] 2.5.46: access permission filesystem) Roland Dreier
2002-11-11 23:58             ` 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=87u1inofsp.fsf@goat.bogus.local \
    --to=olaf.dietsche#list.linux-kernel@t-online.de \
    --cc=akpm@digeo.com \
    --cc=benc@hawaga.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@topspin.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