[Devel] [PATCH vz7] fs/ext4: Suppress false warnings in ext4_kv*alloc()

Andrey Ryabinin aryabinin at virtuozzo.com
Wed Mar 21 15:39:49 MSK 2018



On 03/21/2018 02:53 PM, Oleg Babin wrote:
> In the implementation of ext4_kvmalloc() and ext4_kvzalloc() functions
> a first attempt to allocate memory with kmalloc() can legitimately fail
> in which case we will try to allocate memory with __vmalloc() instead.
> Given this we do not want kmalloc() to generate any warning to dmesg
> on allocation failure and possibly on high order allocation, also we
> do not want kmalloc() to retry the allocation (possibly invoking
> out-of-memory killer). So we add __GFP_NORETRY and __GFP_NOWARN flags
> to kmalloc() invocation.
> 
> Implementation of ext4_kv*alloc() is similar to kv*alloc() but we can't
> just replace one with another as kv*alloc() requires GFP_KERNEL flag to
> be passed (implementation generates a warning if the flag is not passed)
> and the flag is not always used on ext4_kv*alloc() invocation.
> 

Which just means that those ext4_kv?alloc() callers are broken, since GFP_NO{FS,IO}
contexts are not vmalloc compatible. But that is separate issue.


> https://jira.sw.ru/browse/PSBM-82549
> Signed-off-by: Oleg Babin <obabin at virtuozzo.com>
> ---
>  fs/ext4/super.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index c1e7ad7..fff95d3 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -161,7 +161,7 @@ void *ext4_kvmalloc(size_t size, gfp_t flags)
>  {
>  	void *ret;
>  
> -	ret = kmalloc(size, flags);
> +	ret = kmalloc(size, flags | __GFP_NORETRY | __GFP_NOWARN);


I'd rather prefer to use kvmalloc() where it's possible, like upstream does.
See a7c3e901a46f ("mm: introduce kv[mz]alloc helpers")

>  	if (!ret)
>  		ret = __vmalloc(size, flags, PAGE_KERNEL);
>  	return ret;
> @@ -171,7 +171,7 @@ void *ext4_kvzalloc(size_t size, gfp_t flags)
>  {
>  	void *ret;
>  
> -	ret = kzalloc(size, flags);
> +	ret = kzalloc(size, flags | __GFP_NORETRY | __GFP_NOWARN);
>  	if (!ret)
>  		ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
>  	return ret;
> 


More information about the Devel mailing list