diff mbox series

mm: add warning if __vm_enough_memory fails

Message ID 20220726072451.142427-1-wangkefeng.wang@huawei.com (mailing list archive)
State New
Headers show
Series mm: add warning if __vm_enough_memory fails | expand

Commit Message

Kefeng Wang July 26, 2022, 7:24 a.m. UTC
If a process has no enough memory to allocate a new virtual mapping, we
may meet kinds of error, eg, fork cannot allocate memory, SIGBUS error
in shmem, but it is difficult to confirm them, let's add some debug
information to easy to check this scenario if __vm_enough_memory fails.

Reported-by: Yongqiang Liu <liuyongqiang13@huawei.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/util.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Hildenbrand July 26, 2022, 1:45 p.m. UTC | #1
On 26.07.22 09:24, Kefeng Wang wrote:
> If a process has no enough memory to allocate a new virtual mapping, we
> may meet kinds of error, eg, fork cannot allocate memory, SIGBUS error
> in shmem, but it is difficult to confirm them, let's add some debug
> information to easy to check this scenario if __vm_enough_memory fails.
> 
> Reported-by: Yongqiang Liu <liuyongqiang13@huawei.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>  mm/util.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/util.c b/mm/util.c
> index 1266a33a49ea..19bfff8a0ad6 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -1020,6 +1020,8 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
>  	if (percpu_counter_read_positive(&vm_committed_as) < allowed)
>  		return 0;
>  error:
> +	pr_warn("%s: pid: %d, comm: %s, no enough memory for the allocation\n",
> +		__func__, current->pid, current->comm);
>  	vm_unacct_memory(pages);
>  
>  	return -ENOMEM;

Users can easily spam the kernel log, no? Maybe at least ratelimit.
Kefeng Wang July 26, 2022, 2:42 p.m. UTC | #2
On 2022/7/26 21:45, David Hildenbrand wrote:
> On 26.07.22 09:24, Kefeng Wang wrote:
>> If a process has no enough memory to allocate a new virtual mapping, we
>> may meet kinds of error, eg, fork cannot allocate memory, SIGBUS error
>> in shmem, but it is difficult to confirm them, let's add some debug
>> information to easy to check this scenario if __vm_enough_memory fails.
>>
>> Reported-by: Yongqiang Liu <liuyongqiang13@huawei.com>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>>   mm/util.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/mm/util.c b/mm/util.c
>> index 1266a33a49ea..19bfff8a0ad6 100644
>> --- a/mm/util.c
>> +++ b/mm/util.c
>> @@ -1020,6 +1020,8 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
>>   	if (percpu_counter_read_positive(&vm_committed_as) < allowed)
>>   		return 0;
>>   error:
>> +	pr_warn("%s: pid: %d, comm: %s, no enough memory for the allocation\n",
>> +		__func__, current->pid, current->comm);
>>   	vm_unacct_memory(pages);
>>   
>>   	return -ENOMEM;
> Users can easily spam the kernel log, no? Maybe at least ratelimit.
pr_warn_ratelimited is better, will update, thanks.
>
diff mbox series

Patch

diff --git a/mm/util.c b/mm/util.c
index 1266a33a49ea..19bfff8a0ad6 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1020,6 +1020,8 @@  int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
 	if (percpu_counter_read_positive(&vm_committed_as) < allowed)
 		return 0;
 error:
+	pr_warn("%s: pid: %d, comm: %s, no enough memory for the allocation\n",
+		__func__, current->pid, current->comm);
 	vm_unacct_memory(pages);
 
 	return -ENOMEM;