From: Denis Vlasenko <vda@ilport.com.ua>
To: linux-kernel@vger.kernel.org
Subject: kmalloc without GFP_xxx?
Date: Wed, 29 Jun 2005 14:02:18 +0300 [thread overview]
Message-ID: <200506291402.18064.vda@ilport.com.ua> (raw)
Hi,
As anybody knows here, one needs to be careful with GFP_xxx
flags. I've no doubts it's important to get it right in fs
and elsewhere in critical places or else nasty things will happen.
However, for driver code it seems like questionaire
"do you remember which network callback is atomic?".
It struck me that kernel actually can figure out whether it's okay
to sleep or not by looking at combination of (flags & __GFP_WAIT)
and ((in_atomic() || irqs_disabled()) as it already does this for
might_sleep() barfing:
kmalloc => __cache_alloc =>
static inline void
cache_alloc_debugcheck_before(kmem_cache_t *cachep, unsigned int __nocast flags)
{
might_sleep_if(flags & __GFP_WAIT);
#if DEBUG
kmem_flagcheck(cachep, flags);
#endif
}
and
void __might_sleep(char *file, int line)
{
#if defined(in_atomic)
static unsigned long prev_jiffy; /* ratelimiting */
if ((in_atomic() || irqs_disabled()) &&
system_state == SYSTEM_RUNNING && !oops_in_progress) {
if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
return;
prev_jiffy = jiffies;
printk(KERN_ERR "Debug: sleeping function called from invalid"
" context at %s:%d\n", file, line);
printk("in_atomic():%d, irqs_disabled():%d\n",
in_atomic(), irqs_disabled());
dump_stack();
}
#endif
}
So why can't we have kmalloc_auto(size) which does GFP_KERNEL alloc
if called from non-atomic context and GFP_ATOMIC one otherwise?
--
vda
next reply other threads:[~2005-06-29 11:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-29 11:02 Denis Vlasenko [this message]
2005-06-29 11:15 ` Jens Axboe
2005-06-29 11:18 ` Denis Vlasenko
2005-06-29 11:25 ` Jens Axboe
2005-06-29 11:15 ` Arjan van de Ven
2005-06-29 11:20 ` Denis Vlasenko
2005-06-29 11:37 ` Arjan van de Ven
2005-06-29 13:44 ` Steven Rostedt
2005-06-29 14:14 ` Denis Vlasenko
2005-06-29 14:23 ` Jörn Engel
2005-06-29 14:53 ` Steven Rostedt
2005-06-29 15:10 ` Jörn Engel
2005-06-29 15:48 ` Steven Rostedt
2005-06-29 15:54 ` Jörn Engel
2005-06-29 16:04 ` Steven Rostedt
2005-06-29 15:12 ` Oliver Neukum
2005-06-29 16:48 ` Timur Tabi
2005-06-29 17:22 ` Steven Rostedt
2005-06-29 17:43 ` Richard B. Johnson
2005-06-29 18:07 ` Steven Rostedt
2005-06-30 7:52 ` Denis Vlasenko
2005-06-30 8:05 ` Steven Rostedt
2005-06-30 1:02 ` Benjamin Herrenschmidt
2005-06-30 6:02 ` Steven Rostedt
2005-06-29 20:28 Manfred Spraul
2005-06-29 20:44 Manfred Spraul
2005-06-30 5:57 ` Steven Rostedt
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=200506291402.18064.vda@ilport.com.ua \
--to=vda@ilport.com.ua \
--cc=linux-kernel@vger.kernel.org \
/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®