linux-sctp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net/sctp: Avoid allocating high order memory with kmalloc()
@ 2018-04-23 18:41 Oleg Babin
  2018-04-23 18:41 ` [PATCH net-next 1/2] net/sctp: Make wrappers for accessing in/out streams Oleg Babin
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: Oleg Babin @ 2018-04-23 18:41 UTC (permalink / raw)
  To: netdev, linux-sctp
  Cc: David S. Miller, Vlad Yasevich, Neil Horman, Xin Long,
	Marcelo Ricardo Leitner, Andrey Ryabinin

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.

Oleg Babin (2):
  net/sctp: Make wrappers for accessing in/out streams
  net/sctp: Replace in/out stream arrays with flex_array

 include/net/sctp/structs.h   |  31 +++++---
 net/sctp/chunk.c             |   6 +-
 net/sctp/outqueue.c          |  11 +--
 net/sctp/socket.c            |   4 +-
 net/sctp/stream.c            | 165 +++++++++++++++++++++++++++++--------------
 net/sctp/stream_interleave.c |   2 +-
 net/sctp/stream_sched.c      |  13 ++--
 net/sctp/stream_sched_prio.c |  22 +++---
 net/sctp/stream_sched_rr.c   |   8 +--
 9 files changed, 167 insertions(+), 95 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2018-08-11 19:36 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-23 18:41 [PATCH net-next 0/2] net/sctp: Avoid allocating high order memory with kmalloc() Oleg Babin
2018-04-23 18:41 ` [PATCH net-next 1/2] net/sctp: Make wrappers for accessing in/out streams Oleg Babin
2018-04-23 21:33   ` Marcelo Ricardo Leitner
2018-04-26 22:19     ` Oleg Babin
2018-04-23 18:41 ` [PATCH net-next 2/2] net/sctp: Replace in/out stream arrays with flex_array Oleg Babin
2018-04-23 21:33 ` [PATCH net-next 0/2] net/sctp: Avoid allocating high order memory with kmalloc() Marcelo Ricardo Leitner
2018-04-26 22:14   ` Oleg Babin
2018-04-26 22:28     ` Marcelo Ricardo Leitner
2018-04-26 22:45       ` Oleg Babin
2018-07-24 15:35       ` Konstantin Khorenko
2018-07-24 17:36         ` Marcelo Ricardo Leitner
2018-08-03 16:21           ` [PATCH v2 " Konstantin Khorenko
2018-08-03 16:21             ` [PATCH v2 1/2] net/sctp: Make wrappers for accessing in/out streams Konstantin Khorenko
2018-08-03 16:41               ` David Laight
2018-08-03 19:50               ` David Miller
2018-08-09  8:39                 ` Konstantin Khorenko
2018-08-03 20:40               ` Marcelo Ricardo Leitner
2018-08-09  8:40                 ` Konstantin Khorenko
2018-08-03 16:21             ` [PATCH v2 2/2] net/sctp: Replace in/out stream arrays with flex_array Konstantin Khorenko
2018-08-03 16:43             ` [PATCH v2 0/2] net/sctp: Avoid allocating high order memory with kmalloc() David Laight
2018-08-03 20:30               ` Marcelo Ricardo Leitner
2018-08-03 20:56                 ` Michael Tuexen
2018-08-06  9:34                   ` David Laight
2018-08-08 14:48                     ` Marcelo Ricardo Leitner
2018-08-03 23:36             ` Marcelo Ricardo Leitner
2018-08-09  8:43               ` Konstantin Khorenko
2018-08-10 17:03                 ` Konstantin Khorenko
2018-08-10 17:11                   ` [PATCH v3 " Konstantin Khorenko
2018-08-10 17:11                     ` [PATCH v3 1/2] net/sctp: Make wrappers for accessing in/out streams Konstantin Khorenko
2018-08-10 17:11                     ` [PATCH v3 2/2] net/sctp: Replace in/out stream arrays with flex_array Konstantin Khorenko
2018-08-11 19:36                     ` [PATCH v3 0/2] net/sctp: Avoid allocating high order memory with kmalloc() David Miller
2018-08-10 17:41                   ` [PATCH v2 " Marcelo Ricardo Leitner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).