On Fri, 6 Mar 2020 15:16:22 +0900 Jaewon Kim <jaewon31.kim@xxxxxxxxxxx> wrote: > > Even on 64 bit kernel, the mmap failure can happen for a 32 bit task. > Virtual memory space shortage of a task on mmap is reported to userspace > as -ENOMEM. It can be confused as physical memory shortage of overall > system. > > The vm_unmapped_area can be called to by some drivers or other kernel > core system like filesystem. It can be hard to know which code layer > returns the -ENOMEM. > > Print error log of vm_unmapped_area with rate limited. Without rate > limited, soft lockup ocurrs on infinite mmap sytem call. > > i.e.) > <4>[ 68.556470] [2: mmap_infinite:12363] mmap: vm_unmapped_area err:-12 total_vm:0xf4c08 flags:0x1 len:0x100000 low:0x8000 high:0xf4583000 mask:0x0 offset:0x0 > > ... > > --- a/include/linux/mm.h > +++ b/include/linux/mm.h This patch was messed up by your email client (tabs expanded to spaces). > @@ -27,6 +27,7 @@ > #include <linux/memremap.h> > #include <linux/overflow.h> > #include <linux/sizes.h> > +#include <linux/ratelimit.h> > > struct mempolicy; > struct anon_vma; > @@ -2379,10 +2380,20 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info); > static inline unsigned long > vm_unmapped_area(struct vm_unmapped_area_info *info) > { > + unsigned long addr; > + > if (info->flags & VM_UNMAPPED_AREA_TOPDOWN) > - return unmapped_area_topdown(info); > + addr = unmapped_area_topdown(info); > else > - return unmapped_area(info); > + addr = unmapped_area(info); > + > + if (IS_ERR_VALUE(addr)) { > + pr_warn_ratelimited("%s err:%ld total_vm:0x%lx flags:0x%lx len:0x%lx low:0x%lx high:0x%lx mask:0x%lx offset:0x%lx\n", > + __func__, addr, current->mm->total_vm, info->flags, > + info->length, info->low_limit, info->high_limit, > + info->align_mask, info->align_offset); > + } > + return addr; > } pr_warn_ratelimited() contains static state. Using it in an inlined function means that each callsite gets its own copy of that state, so we're ratelimiting the vm_unmapped_area() output on a per-callsite basis, not on a kernelwide basis. Maybe that's what we want, maybe it's not. But I think vm_unmapped_area() has become too large to be inlined anyway, so I suggest making it a regular out-of-line function in mmap.c. I don't believe that function needs to be exported to modules.