[Devel] [PATCH rh7 1/2] net/skbuff: Don't waste memory reserves

Andrey Ryabinin aryabinin at virtuozzo.com
Mon Apr 8 19:29:03 MSK 2019


On 4/8/19 4:24 PM, Alexey Kuznetsov wrote:
> Hello!
> 
> Does not this mean that now we have a reserve,
> which nobody ever uses?
> 

Don't think so.

> I am aware this reserve can be used in theory
> from mm itself.

Yes, it the whole idea of reserves - to use them only for memory reclaim.


> When?

Most common case must be kswapd (it has PF_MEMALLOC in task->flags which tells page_alloc ) doing ->writepage(), e.g. see bellow.
Also it could be any task in direct reclaim (again PF_MEMALLOC in ->flags) and allocation in ->scan_objects() callback in slab shrinkers.

            7fffa98279bd __alloc_pages_nodemask ([kernel.kallsyms])
            7fffa987d077 alloc_pages_current ([kernel.kallsyms])
            7fffa9887d1d new_slab ([kernel.kallsyms])
            7fffa9889ae7 ___slab_alloc ([kernel.kallsyms])
            7fffa9889c70 __slab_alloc ([kernel.kallsyms])
            7fffa988a927 __kmalloc ([kernel.kallsyms])
            7fffc04b4a7d alloc_indirect.isra.11 ([kernel.kallsyms])
            7fffc04b5030 virtqueue_add_sgs ([kernel.kallsyms])
            7fffc051b6e8 __virtblk_add_req ([kernel.kallsyms])
            7fffc051b9ff virtio_queue_rq ([kernel.kallsyms])
            7fffa99d0982 blk_mq_dispatch_rq_list ([kernel.kallsyms])
            7fffa99d59af blk_mq_do_dispatch_sched ([kernel.kallsyms])
            7fffa99d638e blk_mq_sched_dispatch_requests ([kernel.kallsyms])
            7fffa99ce8b0 __blk_mq_run_hw_queue ([kernel.kallsyms])
            7fffa99cea38 __blk_mq_delay_run_hw_queue ([kernel.kallsyms])
            7fffa99ceb41 blk_mq_run_hw_queue ([kernel.kallsyms])
            7fffa99d685e blk_mq_sched_insert_requests ([kernel.kallsyms])
            7fffa99d1989 blk_mq_flush_plug_list ([kernel.kallsyms])
            7fffa99c6a5e blk_flush_plug_list ([kernel.kallsyms])
            7fffa99d1596 blk_mq_make_request ([kernel.kallsyms])
            7fffa99c4ea2 generic_make_request ([kernel.kallsyms])
            7fffa99c5171 submit_bio ([kernel.kallsyms])
            7fffa986d400 __swap_writepage ([kernel.kallsyms])
            7fffa986d5ee swap_writepage ([kernel.kallsyms])
            7fffa98341ae shrink_page_list ([kernel.kallsyms])
            7fffa983511a shrink_inactive_list ([kernel.kallsyms])
            7fffa9835b54 shrink_zone_memcg ([kernel.kallsyms])
            7fffa9836007 shrink_zone ([kernel.kallsyms])
            7fffa98371c0 balance_pgdat ([kernel.kallsyms])
            7fffa98376b4 kswapd ([kernel.kallsyms])
            7fffa972d941 kthread ([kernel.kallsyms])
            7fffa9e132b7 ret_from_fork_nospec_end ([kernel.kallsyms])


Another use-case for reserves is oom-killed tasks which need to allocate some memory to finish process and free it's resources (see TIF_MEMDIE thread flag).

> Tracing showed the only
> function ever doing ALLOC_NO_WATERMARK used
> to be dev_alloc_pages.
> 

I've did a little testing myself and managed to trigger only the trace from above.
However there are many different ->writepage() and ->scan_objects() methods, I'm pretty
sure that some of them, besides swap_writepage() allocate memory.



More information about the Devel mailing list