Saturday, August 20, 2016

Linux: Sleeping while atomic during kmalloc solved

So you ran into a crash where the kernel complains that you were sleeping while atomic.
You were either able to run objdump or gdb and track down that the crash is caused due
to a kmalloc? How is that possible?
Did you make recent changes which included putting in a kmalloc?

Typical format:
The function is declared in <linux/slab.h>:
void * kmalloc(size_t size, int flags)

This function is often used in a similar fashion:
struct packet_st *ptr;
ptr = kmalloc(sizeof(struct packet_st), GFP_KERNEL);
if (!ptr)
        /* handle error ... */

The problem is that the GFP_KERNEL has to be used in proper context. i.e. you cannot use GFP_KERNEL from IRQ context. This is because GFP_KERNEL tells the kernel that if it was not able to immediately allocate the required page, it is free to sleep. However, as we know, we are not allowed to sleep in "atomic" context. 

Hence, we need to make sure that appropriate context flag is used while requesting memory. If you are in the IRQ context, it is useful to use the GFP_ATOMIC flag instead of GFP_KERNEL. This will solve the problem of the crash.


6 comments:

sports online said...

UFC 210
Watch UFC 210
UFC 210 Live
UFC 210 Fight Card
UFC 210 Main Card
UFC 210 Free


UFC 210 Live
UFC 210 Live Stream
UFC 210 Live Online

Mailey Sirus 2 said...

24's Aljamain Sterling: I let fans, media coordinate style in 2 Profoundly Cited-MMAjunkie.com-19 hours earlier. Dana White: McGregor versus Mayweather is 'one and done,' no more. All the talk about UFC lightweight champion Conor McGregor going up against multi-time champion Floyd Mayweather has stirred up a couple of other.
UFC 210
UFC 210 Live , UFC 210 Fight Card , UFC 210 Fight , UFC 210 Card , UFC 210 Live Stream , UFC 210 PPV



"Disorder" Miller admits to around dozen. The past UFC middleweight yielded to just about twelve legal offenses and wrongdoings beginning from various clashes with police over. UFC on FOX 24: Aljamain Sterling let fans and media play into his. Sterling will want to end his slide when he goes up against Augusto Mendes at UFC on FOX 24 on April 15 in Kansas City, Mo. Additionally, you can trust.
UFC 210
UFC 210 Live , UFC 210 Fight Card , UFC 210 Fight , UFC 210 Card , UFC 210 Live Stream , UFC 210 PPV

David E. Alexander said...

Kentucky Derby 2017
Watch Kentucky Derby 2017
2017 Kentucky Derby
Kentucky Derby

Kentucky Derby 2017 Live
Canelo vs Chavez
Canelo vs Chavez jr
Alvarez vs Chavez
Monster Energy Supercross Finals 2017

David E. Alexander said...

Mtv movie awards 2017
Mtv movie awards
Mtv movie and tv awards 2017 Nominees
Mtv movie awards 2017 Live
MTV Movie And TV Awards 2017
Watch Mtv movie awards 2017
Mtv movie awards Online

nd nasif adnan said...

The 28-year-old UFC star moved before Mayweather as their press visit commenced in Los Angeles in front of the August 26 session in Las Vegas which will see McGregor in his first expert boxing battle against five-weight undefeated champion Mayweather vs Mcgregor

ptman said...


Mayweather vs McGregor
McGregor vs Mayweather
Mayweather vs McGregor Live
McGregor vs Mayweather Live
McGregor vs Mayweather Live Stream

Conor McGregor vs Floyd Mayweather
Floyd Mayweather vs Conor McGregor
Floyd Mayweather vs Conor McGregor Live
Conor McGregor vs Floyd Mayweather Live

Post a Comment