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
  • page cache
  • free命令的详细解释
  • file-backed pages和anonymous pages
  • swap与zRAW

Was this helpful?

  1. memory_management

mm4

page cache

在linux读写文件时,page cache用于缓存文件的逻辑内容,从而加快对磁盘映射和数据的访问,应用程序可以通过read/write()、mmap()来访问

page cache的两种形式:

  • 以文件系统中的文件为背景:cached

    如mount /dev/sda1 /mnt,/mnt中文件内容的page cache叫cached

  • 以裸分区/dev/sdax等为背景:buffers

    如dd id=/dev/sd1 of=xxx,xxx的page cache叫buffers

free命令的详细解释

## ubuntu10.04, 老版free命令
## 
## 2058052 = 267360 + 1790692
## 126116  = 267360 - 29364 - 111880
## 1931936 = 1790692 + 29364 + 111880
## 
## buffers and cached is page cache
$ free
             total       used       free     shared    buffers     cached
Mem:       2058052     267360    1790692          0      29364     111880
-/+ buffers/cache:     126116    1931936
Swap:      2187256          0    2187256

## ubuntu18.045,  新版free命令
## 
## 8153096 = 962580 + 6053780 + 1136736
$ free
              total        used        free      shared  buff/cache   available
Mem:        8153096      962580     6053780       12192     1136736     6900224
Swap:       2097148           0     2097148

file-backed pages和anonymous pages

  1. file-backed映射,把进程虚拟地址空间映射到files

    如 代码段等

    当内存不够时,在内存的file-backed pages被删除,等待需要时,重新从磁盘文件将file-backed pages加载到内存中

  2. anonymous映射,进程虚拟地址空间没有映射到任何file

    如 stack, heap, CoW pages等

    当内存不够时,在内存的anonymous pages被保存到swapfile文件或swap分区,等待需要时,重新从swapfile文件或swap分区将anonymous pages加载到内存中;用LRU算法来进行swap和page cache的页面替换

swap与zRAW

嵌入式的存储设备(如 nand flash, nor flash...)的存取速度很慢且读写次数有限制,所以不可以直接申请swapfile文件或者一个swap分区为anonymous pages作交换动作。

此时就出现存储设备zRAW,zRAW是通过申请一小块内存作为swap分区使用,会将数据解压缩后进出swap分区。这样swap访问速度可以提高很多,因解压缩数据,zRAW申请的内存对应的存储数据变多,但是解压缩会占用CPU时间。

如何使用zRAW?

## 1. linux kernel使能zRAW功能
## 2. 应用层指定zRAW大小
$ echo $((48*1024*1024)) > /sys/block/zram0/disksize
## 3. 应用层使能zRAW
$ swapon -p 10 /dev/zram0


## 查看swap分区
$ cat /pro/swaps
## 失能所有swap分区
$ swapoff -a
Previousmm3Nextmm5

Last updated 4 years ago

Was this helpful?