* Re: can kfree sleep?
@ 2004-11-21 18:56 Manfred Spraul
2004-11-21 20:51 ` Peter T. Breuer
0 siblings, 1 reply; 8+ messages in thread
From: Manfred Spraul @ 2004-11-21 18:56 UTC (permalink / raw)
To: Peter T. Breuer; +Cc: linux-kernel
Hi Peter,
>Just a question: can kfree sleep?
>
>
>
>
No, it never sleeps. It's safe to call kfree from arbitrary context. The
only exception is the NMI oopser and similar arch code.
>I believe so, but slab.c does not enlighten me immediately:
>
>
Yes, the kfree code is quite long - it must check if freeing one object
created a freeable page and return it to the page allocator. Together
with lots of caching and debug checks.
--
Manfred
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: can kfree sleep?
2004-11-21 18:56 can kfree sleep? Manfred Spraul
@ 2004-11-21 20:51 ` Peter T. Breuer
0 siblings, 0 replies; 8+ messages in thread
From: Peter T. Breuer @ 2004-11-21 20:51 UTC (permalink / raw)
To: Manfred Spraul, linux-kernel
In article <41A0E4E9.3040902@colorfullife.com> you wrote:
> Hi Peter,
Hi!
> >Just a question: can kfree sleep?
> >
> No, it never sleeps. It's safe to call kfree from arbitrary context. The
> only exception is the NMI oopser and similar arch code.
OK - thanks. I'll take that as read and eliminate kfree from the list
of sleep "seeds" in my code analyser.
> >I believe so, but slab.c does not enlighten me immediately:
> >
> Yes, the kfree code is quite long - it must check if freeing one object
> created a freeable page and return it to the page allocator. Together
> with lots of caching and debug checks.
May I ask where your knowledge of this comes from? (So I can duplicate
the learning process)!
Peter
^ permalink raw reply [flat|nested] 8+ messages in thread
* can kfree sleep?
@ 2004-11-21 12:23 Peter T. Breuer
2004-11-21 21:10 ` Andrew Morton
0 siblings, 1 reply; 8+ messages in thread
From: Peter T. Breuer @ 2004-11-21 12:23 UTC (permalink / raw)
To: linux kernel
Just a question: can kfree sleep?
I believe so, but slab.c does not enlighten me immediately:
void
kfree (const void *objp)
{
kmem_cache_t *c;
unsigned long flags;
if (!objp)
return;
local_irq_save (flags);
c = GET_PAGE_CACHE (virt_to_page (objp));
__cache_free (c, (void *) objp);
local_irq_restore (flags);
}
static inline void __cache_free (kmem_cache_t *cachep, void* objp)
{
struct array_cache *ac = ac_data(cachep);
check_irq_off();
objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
if (likely(ac->avail < ac->limit)) {
STATS_INC_FREEHIT(cachep);
ac_entry(ac)[ac->avail++] = objp;
return;
} else {
STATS_INC_FREEMISS(cachep);
cache_flusharray(cachep, ac);
ac_entry(ac)[ac->avail++] = objp;
}
}
...
Peter
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: can kfree sleep?
2004-11-21 12:23 Peter T. Breuer
@ 2004-11-21 21:10 ` Andrew Morton
2004-11-21 21:14 ` Christoph Hellwig
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2004-11-21 21:10 UTC (permalink / raw)
To: ptb; +Cc: ptb, linux-kernel
"Peter T. Breuer" <ptb@it.uc3m.es> wrote:
>
> Just a question: can kfree sleep?
Nope. All memory freeing codepaths are atomic and may be called from any
context except NMI handlers.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: can kfree sleep?
2004-11-21 21:10 ` Andrew Morton
@ 2004-11-21 21:14 ` Christoph Hellwig
2004-11-21 22:30 ` Peter T. Breuer
0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2004-11-21 21:14 UTC (permalink / raw)
To: Andrew Morton; +Cc: ptb, ptb, linux-kernel
On Sun, Nov 21, 2004 at 01:10:38PM -0800, Andrew Morton wrote:
> Nope. All memory freeing codepaths are atomic and may be called from any
> context except NMI handlers.
Not true for vfree()
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: can kfree sleep?
2004-11-21 21:14 ` Christoph Hellwig
@ 2004-11-21 22:30 ` Peter T. Breuer
2004-11-22 5:41 ` Christoph Hellwig
2004-11-22 8:18 ` Arjan van de Ven
0 siblings, 2 replies; 8+ messages in thread
From: Peter T. Breuer @ 2004-11-21 22:30 UTC (permalink / raw)
To: Christoph Hellwig, linux-kernel
In article <20041121211451.GA12826@infradead.org> you wrote:
> On Sun, Nov 21, 2004 at 01:10:38PM -0800, Andrew Morton wrote:
> > Nope. All memory freeing codepaths are atomic and may be called from any
> > context except NMI handlers.
>
> Not true for vfree()
My interest at the moment is in what can sleep and what cannot sleep.
Are you saying that vfree can sleep or that vfree cannot be called from
at least one other context in addition to the NMI handler context (from
which it cannot be called ...)?
:)
Peter
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: can kfree sleep?
2004-11-21 22:30 ` Peter T. Breuer
@ 2004-11-22 5:41 ` Christoph Hellwig
2004-11-22 8:18 ` Arjan van de Ven
1 sibling, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2004-11-22 5:41 UTC (permalink / raw)
To: Peter T. Breuer; +Cc: Christoph Hellwig, linux-kernel
On Sun, Nov 21, 2004 at 11:30:38PM +0100, Peter T. Breuer wrote:
> In article <20041121211451.GA12826@infradead.org> you wrote:
> > On Sun, Nov 21, 2004 at 01:10:38PM -0800, Andrew Morton wrote:
> > > Nope. All memory freeing codepaths are atomic and may be called from any
> > > context except NMI handlers.
> >
> > Not true for vfree()
>
> My interest at the moment is in what can sleep and what cannot sleep.
> Are you saying that vfree can sleep or that vfree cannot be called from
> at least one other context in addition to the NMI handler context (from
> which it cannot be called ...)?
vfree can't sleep, but it can't be called from every context.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: can kfree sleep?
2004-11-21 22:30 ` Peter T. Breuer
2004-11-22 5:41 ` Christoph Hellwig
@ 2004-11-22 8:18 ` Arjan van de Ven
1 sibling, 0 replies; 8+ messages in thread
From: Arjan van de Ven @ 2004-11-22 8:18 UTC (permalink / raw)
To: Peter T. Breuer; +Cc: Christoph Hellwig, linux-kernel
> > Not true for vfree()
>
> My interest at the moment is in what can sleep and what cannot sleep.
> Are you saying that vfree can sleep or that vfree cannot be called from
> at least one other context in addition to the NMI handler context (from
> which it cannot be called ...)?
vfree() is not allowed to be called from irq context, and since it can do cross cpu IPI's, you have to generally be careful with it.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-11-22 8:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-21 18:56 can kfree sleep? Manfred Spraul
2004-11-21 20:51 ` Peter T. Breuer
-- strict thread matches above, loose matches on Subject: below --
2004-11-21 12:23 Peter T. Breuer
2004-11-21 21:10 ` Andrew Morton
2004-11-21 21:14 ` Christoph Hellwig
2004-11-21 22:30 ` Peter T. Breuer
2004-11-22 5:41 ` Christoph Hellwig
2004-11-22 8:18 ` Arjan van de Ven
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.