• Catalin Marinas's avatar
    mm: slab: only move management objects off-slab for sizes larger than KMALLOC_MIN_SIZE · d4322d88
    Catalin Marinas authored
    On systems with a KMALLOC_MIN_SIZE of 128 (arm64, some mips and powerpc
    configurations defining ARCH_DMA_MINALIGN to 128), the first
    kmalloc_caches[] entry to be initialised after slab_early_init = 0 is
    "kmalloc-128" with index 7.  Depending on the debug kernel configuration,
    sizeof(struct kmem_cache) can be larger than 128 resulting in an
    INDEX_NODE of 8.
    
    Commit 8fc9cf42 ("slab: make more slab management structure off the
    slab") enables off-slab management objects for sizes starting with
    PAGE_SIZE >> 5 (128 bytes for a 4KB page configuration) and the creation
    of the "kmalloc-128" cache would try to place the management objects
    off-slab.  However, since KMALLOC_MIN_SIZE is already 128 and
    freelist_size == 32 in __kmem_cache_create(), kmalloc_slab(freelist_size)
    returns NULL (kmalloc_caches[7] not populated yet).  This triggers the
    following bug on arm64:
    
      kernel BUG at /work/Linux/linux-2.6-aarch64/mm/slab.c:2283!
      Internal error: Oops - BUG: 0 [#1] SMP
      Modules linked in:
      CPU: 0 PID: 0 Comm: swapper Not tainted 4.3.0-rc4+ #540
      Hardware name: Juno (DT)
      PC is at __kmem_cache_create+0x21c/0x280
      LR is at __kmem_cache_create+0x210/0x280
      [...]
      Call trace:
        __kmem_cache_create+0x21c/0x280
        create_boot_cache+0x48/0x80
        create_kmalloc_cache+0x50/0x88
        create_kmalloc_caches+0x4c/0xf4
        kmem_cache_init+0x100/0x118
        start_kernel+0x214/0x33c
    
    This patch introduces an OFF_SLAB_MIN_SIZE definition to avoid off-slab
    management objects for sizes equal to or smaller than KMALLOC_MIN_SIZE.
    
    Fixes: 8fc9cf42 ("slab: make more slab management structure off the slab")
    Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
    Reported-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
    Acked-by: default avatarChristoph Lameter <cl@linux.com>
    Cc: Pekka Enberg <penberg@kernel.org>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Cc: <stable@vger.kernel.org>	[3.15+]
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    d4322d88
slab.c 108 KB