Re: [PATCH v3 0/2] net/sctp: Avoid allocating high order memory with kmalloc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Konstantin Khorenko <khorenko@xxxxxxxxxxxxx>
Date: Fri, 10 Aug 2018 20:11:41 +0300

> Each SCTP association can have up to 65535 input and output streams.
> For each stream type an array of sctp_stream_in or sctp_stream_out
> structures is allocated using kmalloc_array() function. This function
> allocates physically contiguous memory regions, so this can lead
> to allocation of memory regions of very high order, i.e.:
> 
>   sizeof(struct sctp_stream_out) == 24,
>   ((65535 * 24) / 4096) == 383 memory pages (4096 byte per page),
>   which means 9th memory order.
> 
> This can lead to a memory allocation failures on the systems
> under a memory stress.
> 
> We actually do not need these arrays of memory to be physically
> contiguous. Possible simple solution would be to use kvmalloc()
> instread of kmalloc() as kvmalloc() can allocate physically scattered
> pages if contiguous pages are not available. But the problem
> is that the allocation can happed in a softirq context with
> GFP_ATOMIC flag set, and kvmalloc() cannot be used in this scenario.
> 
> So the other possible solution is to use flexible arrays instead of
> contiguios arrays of memory so that the memory would be allocated
> on a per-page basis.
> 
> This patchset replaces kvmalloc() with flex_array usage.
> It consists of two parts:
> 
>   * First patch is preparatory - it mechanically wraps all direct
>     access to assoc->stream.out[] and assoc->stream.in[] arrays
>     with SCTP_SO() and SCTP_SI() wrappers so that later a direct
>     array access could be easily changed to an access to a
>     flex_array (or any other possible alternative).
>   * Second patch replaces kmalloc_array() with flex_array usage.

Looks good, series applied, thanks!



[Index of Archives]     [Linux Networking Development]     [Linux OMAP]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux