Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 0. 简介
  • 1. 用户层接口
  • 2. 内核层实现

Was this helpful?

  1. linuxKernel
  2. slub

proc_slabinfo

0. 简介

linux kernel通过slub分配器进行分配小内存时,需要struct kmem_cache组织所有同样大小的小内存块,同时通过链表list把struct kmem_cache链接起来

1. 用户层接口

如果用户层想要知道每一个struct kmem_cache的使用情况,可以通过读取/proc/slabinfo得到,如下:

$ uname -a
Linux (none) 2.6.34 #2 SMP Thu Mar 11 03:25:03 UTC 2021 x86_64 GNU/Linux

$ cat /proc/slabinfo
slabinfo - version: 2.1
# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
...
mm_struct             19     19    832   19    4 : tunables    0    0    0 : slabdata      1      1      0
files_cache           43     44    704   11    2 : tunables    0    0    0 : slabdata      4      4      0
task_struct           43     48   1936    8    4 : tunables    0    0    0 : slabdata      6      6      0
...
kmalloc-8192           4      4   8192    4    8 : tunables    0    0    0 : slabdata      1      1      0
kmalloc-4096          29     32   4096    8    8 : tunables    0    0    0 : slabdata      4      4      0
kmalloc-2048         120    120   2048    8    4 : tunables    0    0    0 : slabdata     15     15      0
kmalloc-1024         157    160   1024    8    2 : tunables    0    0    0 : slabdata     20     20      0
kmalloc-512          295    296    512    8    1 : tunables    0    0    0 : slabdata     37     37      0
kmalloc-256          144    144    256   16    1 : tunables    0    0    0 : slabdata      9      9      0
kmalloc-128          189    192    128   32    1 : tunables    0    0    0 : slabdata      6      6      0
kmalloc-64          1890   1920     64   64    1 : tunables    0    0    0 : slabdata     30     30      0
kmalloc-32          1012   1024     32  128    1 : tunables    0    0    0 : slabdata      8      8      0
kmalloc-16          2304   2304     16  256    1 : tunables    0    0    0 : slabdata      9      9      0
kmalloc-8           3072   3072      8  512    1 : tunables    0    0    0 : slabdata      6      6      0
kmalloc-192          741    756    192   21    1 : tunables    0    0    0 : slabdata     36     36      0
kmalloc-96           294    294     96   42    1 : tunables    0    0    0 : slabdata      7      7      0
kmem_cache_node        0      0     64   64    1 : tunables    0    0    0 : slabdata      0      0      0

对/proc/slabinfo每一列的详细解释,如下:

  • 第1列 name : kmem_cache名字,即 kmem_cache->name

  • 第2列 active_objs : 目前已经使用的object数量

  • 第3列 num_objs : 全部object数量

  • 第4列 objsize : 一个object的大小,包括meta数据

  • 第5列 objperslab : 每一个slab的object数量

  • 第6列 pagesperslab : 每一个slab的page数量

  • 第13列 num_slabs : slabs的数量

2. 内核层实现

在mm/slub.c通过slab_proc_init() --> proc_create(),来创建用户层接口/proc/slabinfo

当用户层读取/proc/slabinfo时,主要执行两个函数,如下:

  1. 执行s_start()打印每一列的文字说明

  2. 执行s_show()打印struct kmem_cache的使用情况

PreviousslubNextslub_theory

Last updated 2 years ago

Was this helpful?