)]}'
{
  "commit": "f86b967300ef739dd8fc986a328a8a19e7f50484",
  "tree": "b4548e1307213b6d58f4cf0ca9f98c1b7af7652b",
  "parents": [
    "4a24bbabc826eaba6f94a9741712117b8e2b0587"
  ],
  "author": {
    "name": "Vlastimil Babka",
    "email": "vbabka@suse.cz",
    "time": "Tue Jul 02 17:11:47 2024 +0200"
  },
  "committer": {
    "name": "Vlastimil Babka",
    "email": "vbabka@suse.cz",
    "time": "Tue Jul 02 17:51:23 2024 +0200"
  },
  "message": "mm, slab: extend kmalloc() alignment for non power-of-two sizes\n\nSlab allocators have been guaranteeing natural alignment for\npower-of-two sizes since commit 59bb47985c1d (\"mm, sl[aou]b: guarantee\nnatural alignment for kmalloc(power-of-two)\"), while any other sizes are\naligned only to ARCH_KMALLOC_MINALIGN bytes.\n\nRust\u0027s allocator API specifies size and alignment per allocation, which\nhave to satisfy the following rules, per Alice Ryhl [1]:\n\n  1. The alignment is a power of two.\n  2. The size is non-zero.\n  3. When you round up the size to the next multiple of the alignment,\n     then it must not overflow the signed type isize / ssize_t.\n\nIn order to map this to kmalloc()\u0027s guarantees, some requested\nallocation sizes have to be enlarged to the next power-of-two size [2].\nFor example, an allocation of size 96 and alignment of 32 will be\nenlarged to an allocation of size 128, because the existing kmalloc-96\nbucket doesn\u0027t guarantee alignent above ARCH_KMALLOC_MINALIGN. Without\nslab debugging active, the layout of the kmalloc-96 slabs however\nnaturally aligns the objects to 32 bytes, so extending the size to 128\nbytes is wasteful.\n\nTo improve the situation we can extend the kmalloc() alignment\nguarantees in a way that\n\n1) doesn\u0027t change the current slab layout (and thus does not increase\n   internal fragmentation) when slab debugging is not active\n2) reduces waste in the Rust allocator use case\n3) is a superset of the current guarantee for power-of-two sizes.\n\nThe extended guarantee is that alignment is at least the largest\npower-of-two divisor of the requested size. For power-of-two sizes the\nlargest divisor is the size itself, but let\u0027s keep this case documented\nseparately for clarity.\n\nFor current kmalloc size buckets, it means kmalloc-96 will guarantee\nalignment of 32 bytes and kmalloc-196 will guarantee 64 bytes.\n\nThis covers the rules 1 and 2 above of Rust\u0027s API as long as the size is\na multiple of the alignment. The Rust layer should now only need to\nround up the size to the next multiple if it isn\u0027t, while enforcing the\nrule 3.\n\nImplementation-wise, this changes the alignment calculation in\ncreate_boot_cache(). While at it also do the calulation only for caches\nwith the SLAB_KMALLOC flag, because the function is also used to create\nthe initial kmem_cache and kmem_cache_node caches, where no alignment\nguarantee is necessary.\n\nLink: https://lore.kernel.org/all/CAH5fLggjrbdUuT-H-5vbQfMazjRDpp2%2Bk3%3DYhPyS17ezEqxwcw@mail.gmail.com/ [1]\nLink: https://lore.kernel.org/all/CAH5fLghsZRemYUwVvhk77o6y1foqnCeDzW4WZv6ScEWna2+_jw@mail.gmail.com/ [2]\nSigned-off-by: Vlastimil Babka \u003cvbabka@suse.cz\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "1c58d883b273065d2c054cc3d1a4f3d3e265b130",
      "old_mode": 33188,
      "old_path": "Documentation/core-api/memory-allocation.rst",
      "new_id": "8b84eb4bdae7fbb31b3b79368bdae62d40fe1612",
      "new_mode": 33188,
      "new_path": "Documentation/core-api/memory-allocation.rst"
    },
    {
      "type": "modify",
      "old_id": "ed6bee5ec2b6ecf4b9bb1a4a09635e2c981dff19",
      "old_mode": 33188,
      "old_path": "include/linux/slab.h",
      "new_id": "640cea6e6323487164d233fcedf08eb913750673",
      "new_mode": 33188,
      "new_path": "include/linux/slab.h"
    },
    {
      "type": "modify",
      "old_id": "1560a1546bb1c89122e6616fec228389981fb38d",
      "old_mode": 33188,
      "old_path": "mm/slab_common.c",
      "new_id": "7272ef7bc55f6da3f54aad00bbeef763b7965599",
      "new_mode": 33188,
      "new_path": "mm/slab_common.c"
    }
  ]
}
