Skip to contentSkip to conversation

Widespread misuse of GFP_ATOMIC

DISCUSSION [email protected] 3 participants 3 messages Apr 10, 2016 – Apr 11, 2016 Kernel janitors

lore
Share & tools
lore
#0 lore raw

Hello linux janitors,

from kmalloc man page:

GFP_ATOMIC - Allocation will not sleep. May use emergency pools. For example, use this inside interrupt handlers.
GFP_NOWAIT - Allocation will not sleep.

grepping linux kernel tree:

[0:/usr/linux-src> ]$ grep -R GFP_ATOMIC . |wc -l
4452
[0:/usr/linux-src> ]$ grep -R GFP_NOWAIT . |wc -l
220

(alternative flags and some accounting:
total k.*alloc calls: 34320
GFP_KERNEL appearances: 23819
GDP_ATOMIC appearances: 4452
GFP_NOWAIT appearances: 220

unaccounted: 5829)

GFP_ATOMIC is meant for interrupt handlers and emergency pool. Widespread misuse renders the emergency pool useless.

I believe the vast majority of such uses can be converted to GFP_NOWAIT. Even valid uses of GFP_ATOMIC are likely rendered useless by this widespread misuse.

You may wish to replace such calls.

Cheers, coypu

#1 lore raw
Quoted 23 lines · On Sun, 10 Apr 2016, [email protected] wrote:

Hello linux janitors,

from kmalloc man page:

GFP_ATOMIC - Allocation will not sleep. May use emergency pools. For example, use this inside interrupt handlers.
GFP_NOWAIT - Allocation will not sleep.

grepping linux kernel tree:

[0:/usr/linux-src> ]$ grep -R GFP_ATOMIC . |wc -l
4452
[0:/usr/linux-src> ]$ grep -R GFP_NOWAIT . |wc -l
220

(alternative flags and some accounting:
total k.*alloc calls: 34320
GFP_KERNEL appearances: 23819
GDP_ATOMIC appearances: 4452
GFP_NOWAIT appearances: 220

unaccounted: 5829)

Quoted 8 lines

GFP_ATOMIC is meant for interrupt handlers and emergency pool. Widespread misuse renders the emergency pool useless.

I believe the vast majority of such uses can be converted to GFP_NOWAIT. Even valid uses of GFP_ATOMIC are likely rendered useless by this widespread misuse.

You may wish to replace such calls.

How does one know which need the emergency pool?

julia

#2 lore raw
In reply to [email protected]

GFP_NOWAIT is when you have a somewhat painless backup plan in case the allocation fails. If you're worried that there are too many GFP_ATOMICs, then it's better to re-arrange the code so the allocation can sleep.

regards,
dan carpenter