linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Is it safe to kmalloc a large size of memory in interrupt handler?
@ 2019-08-05 11:57 Fuqian Huang
  2019-08-05 12:13 ` Michal Hocko
  0 siblings, 1 reply; 2+ messages in thread
From: Fuqian Huang @ 2019-08-05 11:57 UTC (permalink / raw)
  To: Linux Kernel Mailing List

In the implementation of kmalloc.
when the allocated size is larger than KMALLOC_MAX_CACHE_SIZE,
it will call kmalloc_large to allocate the memory.
kmalloc_large ->
kmalloc_order_trace->kmalloc_order->alloc_pages->alloc_pages_current->alloc_pages_nodemask->get_page_from_freelist->node_reclaim->__node_reclaim->shrink_node->shrink_node_memcg->get_scan_count

get_scan_count will call spin_unlock_irq which enables local interrupt.
As the local interrupt should be disabled in the interrupt handler.
It is safe to use kmalloc to allocate a large size of memory in
interrupt handler?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Is it safe to kmalloc a large size of memory in interrupt handler?
  2019-08-05 11:57 Is it safe to kmalloc a large size of memory in interrupt handler? Fuqian Huang
@ 2019-08-05 12:13 ` Michal Hocko
  0 siblings, 0 replies; 2+ messages in thread
From: Michal Hocko @ 2019-08-05 12:13 UTC (permalink / raw)
  To: Fuqian Huang; +Cc: Linux Kernel Mailing List

On Mon 05-08-19 19:57:54, Fuqian Huang wrote:
> In the implementation of kmalloc.
> when the allocated size is larger than KMALLOC_MAX_CACHE_SIZE,
> it will call kmalloc_large to allocate the memory.
> kmalloc_large ->
> kmalloc_order_trace->kmalloc_order->alloc_pages->alloc_pages_current->alloc_pages_nodemask->get_page_from_freelist->node_reclaim->__node_reclaim->shrink_node->shrink_node_memcg->get_scan_count

You shouldn't really get there when using GFP_NOWAIT/GFP_ATOMIC.

> get_scan_count will call spin_unlock_irq which enables local interrupt.
> As the local interrupt should be disabled in the interrupt handler.
> It is safe to use kmalloc to allocate a large size of memory in
> interrupt handler?

It will work very unreliably because larger physically contiguous memory
is not generally available without doing compaction after a longer
runtime. In general I would recommend to use pre allocated buffers or
defer the actual handling to a less restricted context if possible.

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-05 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-05 11:57 Is it safe to kmalloc a large size of memory in interrupt handler? Fuqian Huang
2019-08-05 12:13 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).