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

Was this helpful?

  1. linuxKernel

multi-gen-LRU

MGLRU 抛弃了 active、inactive 两种不同类型 list 的概念,取而代之的是 2个新概念:Generation 和 Tier。

MGLRU 最年轻的一代是 max_seq,其对于 anon 和 file 来说,总是相等的; 最老的一代,则区分为:min_seq[anon] 和 min_seq[file]。 因为内存回收的时候,允许 file 比 anon 更激进地多回收一代, 所以 anon 和 file 的 min_seq 不一定完全相等。

MGLRU 为 file 和 anon 页面维护了 4 代 LRU list,不再有 active 和 inactive 的“类2 代”概念。 通过 min_seq 和 max_seq 的增加来更新代。

MGLRU 可以限制 anon 和 file 的 min_seq 的代差,实际很好地平衡了 anon 和 file 的回收。

file page 首次通过 syscall read 进入的话,会进入 min_seq。 而任何时候,基于 page fault 进入的 file 页(也就是被 map 到 PTE),都会直接进入 max_seq。

Tier 是 generation 内部的概念。代表文件页的访问频度, 如果文件页被访问 n 次(通过 syscall),则其 tier 为 log2(n)。 注意这个次数只在 sys_read、sys_write 的时候统计, 故通过 system call 只被 read() 了一次的 page、只 map 访问的page,tier 都是 0; 通过 syscall 读写 2 次的 page,tier 是1。

MGLRU 有一个非常有特色的地方,它在通过反向映射查看 PTE 的 reference bit时, 会利用空间局部性原理,look-around 特定 PTE 周围的几十个PTE,扫描目标PTE周围的PTE决定 aging 升代。 简单来说,我们既然通过反向映射好不容易找到了那个进程的 PTE,那么访问这个 PTE周围的 PTE 是比较快的, 我们就一起看,看完发现这个周围的 PTE 是 young 的,则升级它们到 max_seq。

PreviouslruNextpage_reclaim

Last updated 1 year ago

Was this helpful?