vlib: mmap process stacks

Instead of allocating stack from the main heap, this patch mmaps stack
memory together with guard page.

This aproach reduces main heap usage, and stack memory is prefaulted
on demand, so bigger process stacks will have zero impact on memory
usage as long as stack memory is not needed for real.

In addition, it fixes issue with systems which have bigger default page
size (observed with 65536).

Type: improvement
Change-Id: I593365c603d4702e428967d80fd425fdee2c4a21
Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:
Damjan Marion
2020-05-20 22:01:44 +02:00
parent ca86c95a34
commit ef58758286
4 changed files with 43 additions and 60 deletions

View File

@ -552,6 +552,7 @@ typedef struct
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
/* Node runtime for this process. */
vlib_node_runtime_t node_runtime;
@ -613,32 +614,10 @@ typedef struct
vlib_cli_output_function_t *output_function;
uword output_function_arg;
#ifdef CLIB_UNIX
/* Pad to a multiple of the page size so we can mprotect process stacks */
#define PAGE_SIZE_MULTIPLE 0x1000
#define ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT __attribute__ ((aligned (PAGE_SIZE_MULTIPLE)))
#else
#define ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT
#endif
/* Process stack. Starts here and extends 2^log2_n_stack_bytes
bytes. */
/* Process stack */
#define VLIB_PROCESS_STACK_MAGIC (0xdead7ead)
u32 stack[0] ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT;
} vlib_process_t __attribute__ ((aligned (CLIB_CACHE_LINE_BYTES)));
#ifdef CLIB_UNIX
/* Ensure that the stack is aligned on the multiple of the page size */
typedef char
assert_process_stack_must_be_aligned_exactly_to_page_size_multiple[(sizeof
(vlib_process_t)
-
PAGE_SIZE_MULTIPLE)
==
0 ? 0 :
-1];
#endif
u32 *stack;
} vlib_process_t;
typedef struct
{