• Sebastian Andrzej Siewior's avatar
    apparmor: Use a memory pool instead per-CPU caches · df323337
    Sebastian Andrzej Siewior authored
    The get_buffers() macro may provide one or two buffers to the caller.
    Those buffers are pre-allocated on init for each CPU. By default it
    allocates
    	2* 2 * MAX_PATH * POSSIBLE_CPU
    
    which equals 64KiB on a system with 4 CPUs or 1MiB with 64 CPUs and so
    on.
    
    Replace the per-CPU buffers with a common memory pool which is shared
    across all CPUs. The pool grows on demand and never shrinks. The pool
    starts with two (UP) or four (SMP) elements. By using this pool it is
    possible to request a buffer and keeping preemption enabled which avoids
    the hack in profile_transition().
    
    It has been pointed out by Tetsuo Handa that GFP_KERNEL allocations for
    small amount of memory do not fail. In order not to have an endless
    retry, __GFP_RETRY_MAYFAIL is passed (so the memory allocation is not
    repeated until success) and retried once hoping that in the meantime a
    buffer has been returned to the pool. Since now NULL is possible all
    allocation paths check the buffer pointer and return -ENOMEM on failure.
    Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
    df323337
lsm.c 48.6 KB