In show_numa_map() we collect statistics into a numa_maps structure.Since the number of NUMA nodes can be very large, this structure is nota candidate for stack allocation.

Instead of going thru a kmalloc()+kfree() cycle each time show_numa_map()is invoked, perform the allocation just once when /proc/pid/numa_maps isopened.

Performing the allocation when numa_maps is opened, and thus before areference to the target tasks mm is taken, eliminates a potentialstalemate condition in the oom-killer as originally described by HughDickins:

... imagine what happens if the system is out of memory, and the mm we're looking at is selected for killing by the OOM killer: while we wait in __get_free_page for more memory, no memory is freed from the selected mm because it cannot reach exit_mmap while we hold that reference.