Skip to content

mm: Optimize list lru memory consumption

Waiman Long requested to merge llong1/centos-stream-9:bz2013413_lru_list into main

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2013413
MR: !690 (merged)
Omitted-fix: b9663a6ff828 ("tools: Add kmem_cache_alloc_lru()")
The tools/include/linux/slab.h and the radix-tree tests have not been merged into CS9 yet.

This MR backports the upstream patch series "Optimize list lru memory consumption" to reduce memory consumption of kmalloc-32 slab cache on systems with a large number of memory cgroups (containers). In the extreme case, this patch series can save GBs of memory.

Signed-off-by: Waiman Long longman@redhat.com

Waiman Long (26):
  Compiler Attributes: add __alloc_size() for better bounds checking
  slab: clean up function prototypes
  slab: add __alloc_size attributes for better bounds checking
  mm/list_lru.c: prefer struct_size over open coded arithmetic
  memcg, kmem: further deprecate kmem.limit_in_bytes
  mm: list_lru: remove holding lru lock
  mm: list_lru: fix the return value of list_lru_count_one()
  mm: list_lru: only add memcg-aware lrus to the global lru list
  memcg: add per-memcg vmalloc stat
  memcg: add per-memcg total kernel memory stat
  mm: list_lru: transpose the array of per-node per-memcg lru lists
  mm: introduce kmem_cache_alloc_lru
  fs: introduce alloc_inode_sb() to allocate filesystems specific inode
  fs: allocate inode by using alloc_inode_sb()
  mm: dcache: use kmem_cache_alloc_lru() to allocate dentry
  xarray: use kmem_cache_alloc_lru to allocate xa_node
  mm: memcontrol: move memcg_online_kmem() to mem_cgroup_css_online()
  mm: list_lru: allocate list_lru_one only when needed
  mm: list_lru: rename memcg_drain_all_list_lrus to
    memcg_reparent_list_lrus
  mm: list_lru: replace linear array with xarray
  mm: memcontrol: reuse memory cgroup ID for kmem ID
  mm: memcontrol: fix cannot alloc the maximum memcg ID
  mm: list_lru: rename list_lru_per_memcg to list_lru_memcg
  mm: memcontrol: rename memcg_cache_id to memcg_kmem_id
  slab: remove __alloc_size attribute from __kmalloc_track_caller
  NFSv4.2: Fix missing removal of SLAB_ACCOUNT on kmem_cache allocation

 .../admin-guide/cgroup-v1/memory.rst          |  11 +-
 Documentation/admin-guide/cgroup-v2.rst       |   8 +
 Documentation/filesystems/porting.rst         |   6 +
 Makefile                                      |  15 +
 block/bdev.c                                  |   2 +-
 drivers/dax/super.c                           |   2 +-
 fs/adfs/super.c                               |   2 +-
 fs/affs/super.c                               |   2 +-
 fs/afs/super.c                                |   2 +-
 fs/befs/linuxvfs.c                            |   2 +-
 fs/bfs/inode.c                                |   2 +-
 fs/btrfs/inode.c                              |   2 +-
 fs/ceph/inode.c                               |   2 +-
 fs/cifs/cifsfs.c                              |   2 +-
 fs/coda/inode.c                               |   2 +-
 fs/dcache.c                                   |   3 +-
 fs/ecryptfs/super.c                           |   2 +-
 fs/efs/super.c                                |   2 +-
 fs/erofs/super.c                              |   2 +-
 fs/exfat/super.c                              |   2 +-
 fs/ext2/super.c                               |   2 +-
 fs/ext4/super.c                               |   2 +-
 fs/fat/inode.c                                |   2 +-
 fs/freevxfs/vxfs_super.c                      |   2 +-
 fs/fuse/inode.c                               |   2 +-
 fs/gfs2/super.c                               |   2 +-
 fs/hfs/super.c                                |   2 +-
 fs/hfsplus/super.c                            |   2 +-
 fs/hostfs/hostfs_kern.c                       |   2 +-
 fs/hpfs/super.c                               |   2 +-
 fs/hugetlbfs/inode.c                          |   2 +-
 fs/inode.c                                    |   2 +-
 fs/isofs/inode.c                              |   2 +-
 fs/jffs2/super.c                              |   2 +-
 fs/jfs/super.c                                |   2 +-
 fs/minix/inode.c                              |   2 +-
 fs/nfs/inode.c                                |   2 +-
 fs/nfs/nfs42xattr.c                           |   2 +-
 fs/nilfs2/super.c                             |   2 +-
 fs/ntfs/inode.c                               |   2 +-
 fs/ocfs2/dlmfs/dlmfs.c                        |   2 +-
 fs/ocfs2/super.c                              |   2 +-
 fs/openpromfs/inode.c                         |   2 +-
 fs/orangefs/super.c                           |   2 +-
 fs/overlayfs/super.c                          |   2 +-
 fs/proc/inode.c                               |   2 +-
 fs/qnx4/inode.c                               |   2 +-
 fs/qnx6/inode.c                               |   2 +-
 fs/reiserfs/super.c                           |   2 +-
 fs/romfs/super.c                              |   2 +-
 fs/squashfs/super.c                           |   2 +-
 fs/sysv/inode.c                               |   2 +-
 fs/ubifs/super.c                              |   2 +-
 fs/udf/super.c                                |   2 +-
 fs/ufs/super.c                                |   2 +-
 fs/vboxsf/super.c                             |   2 +-
 fs/xfs/xfs_icache.c                           |   2 +-
 fs/zonefs/super.c                             |   2 +-
 include/linux/compiler-gcc.h                  |   8 +
 include/linux/compiler_attributes.h           |  10 +
 include/linux/compiler_types.h                |  12 +
 include/linux/fs.h                            |  11 +
 include/linux/list_lru.h                      |  17 +-
 include/linux/memcontrol.h                    |  63 ++-
 include/linux/slab.h                          | 101 ++--
 include/linux/swap.h                          |   5 +-
 include/linux/xarray.h                        |   9 +-
 ipc/mqueue.c                                  |   2 +-
 lib/xarray.c                                  |  10 +-
 mm/list_lru.c                                 | 464 ++++++++----------
 mm/memcontrol.c                               | 213 ++------
 mm/shmem.c                                    |   2 +-
 mm/slab.c                                     |  39 +-
 mm/slab.h                                     |  25 +-
 mm/slob.c                                     |   6 +
 mm/slub.c                                     |  42 +-
 mm/vmalloc.c                                  |  13 +-
 mm/workingset.c                               |   2 +-
 net/socket.c                                  |   2 +-
 net/sunrpc/rpc_pipe.c                         |   2 +-
 scripts/checkpatch.pl                         |   3 +-
 81 files changed, 600 insertions(+), 610 deletions(-)
Edited by Waiman Long

Merge request reports