Re: [PATCH 2] mm/kvmalloc: do not call kmalloc for size > KMALLOC_MAX_SIZE

Michal Hocko
2018-11-05T16:57:33Z

On Mon 05-11-18 19:19:28, Konstantin Khlebnikov wrote:
>
>
> On 05.11.2018 16:03, Vlastimil Babka wrote:
> > On 11/1/18 11:09 AM, Konstantin Khlebnikov wrote:
> > > Allocations over KMALLOC_MAX_SIZE could be served only by vmalloc.
> > >
> > > Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> >
> > Makes sense regardless of warnings stuff.
> >
> > Acked-by: Vlastimil Babka <vbabka@suse.cz>
> >
> > But it must be moved below the GFP_KERNEL check!
>
> But kmalloc cannot handle it regardless of GFP.
>
> Ok maybe write something like this
>
> if (size > KMALLOC_MAX_SIZE) {
> if (WARN_ON_ONCE((flags & GFP_KERNEL) != GFP_KERNEL)
> return NULL;
> goto do_vmalloc;
> }

Do we really have to be so defensive? I agree with Vlastimil that the
check should be done after GFP_KERNEL check (I should have noticed that).
kmalloc should already complain on the allocation size request.

> or fix that uncertainty right in vmalloc
>
> For now comment in vmalloc declares
>
> * Any use of gfp flags outside of GFP_KERNEL should be consulted
> * with mm people.

Which is what we want. There are some exceptional cases where using a
subset of GFP_KERNEL works fine (e.g. scope nofs/noio context).

--
Michal Hocko
SUSE Labs