-10 +

page fault

关于 linux 内存管理的一些知识点。下面是缺页的各种情况

  1. /*
  2. * Different kinds of faults, as returned by handle_mm_fault().
  3. * Used to decide whether a process gets delivered SIGBUS or
  4. * just gets major/minor fault counters bumped up.
  5. */
  6. #define VM_FAULT_MINOR 0 /* For backwards compat. Remove me quickly. */
  7. #define VM_FAULT_OOM 0x0001
  8. #define VM_FAULT_SIGBUS 0x0002
  9. #define VM_FAULT_MAJOR 0x0004
  10. #define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */
  11. #define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned small page */
  12. #define VM_FAULT_HWPOISON_LARGE 0x0020 /* Hit poisoned large page. Index encoded in upper bits */
  13. #define VM_FAULT_SIGSEGV 0x0040
  14. #define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */
  15. #define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */
  16. #define VM_FAULT_RETRY 0x0400 /* ->fault blocked, must retry */
  17. #define VM_FAULT_FALLBACK 0x0800 /* huge page fault failed, fall back to small */
  18. #define VM_FAULT_HWPOISON_LARGE_MASK 0xf000 /* encodes hpage index for large hwpoison */
  19. #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
  20. VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
  21. VM_FAULT_FALLBACK)

提供一个 systemtap 脚本

  1. [root@docker221 memory]# pwd
  2. /usr/share/systemtap-2.9-3823/share/doc/systemtap/examples/memory
  3. [root@docker221 memory]# cat pfaults.stp
  4. #! /usr/bin/env stap
  5. global fault_entry_time, fault_address, fault_access
  6. global time_offset
  7. probe begin { time_offset = gettimeofday_us() }
  8. probe vm.pagefault {
  9. t = gettimeofday_us()
  10. fault_entry_time[tid()] = t
  11. fault_address[tid()] = address
  12. fault_access[tid()] = write_access ? "w" : "r"
  13. }
  14. probe vm.pagefault.return {
  15. t=gettimeofday_us()
  16. if (!(tid() in fault_entry_time)) next
  17. e = t - fault_entry_time[id]
  18. if (vm_fault_contains(fault_type,VM_FAULT_MINOR)) {
  19. ftype="minor"
  20. } else if (vm_fault_contains(fault_type,VM_FAULT_MAJOR)) {
  21. ftype="major"
  22. } else {
  23. next #only want to deal with minor and major page faults
  24. }
  25. printf("%d:%d:%id:%s:%s:%d\n",
  26. t - time_offset, tid(), fault_address[tid()], fault_access[tid()], ftype, e)
  27. #free up memory
  28. delete fault_entry_time[tid()]
  29. delete fault_address[tid()]
  30. delete fault_access[tid()]
  31. }

参考

关于我

85 后程序员, 比较熟悉 Java,JVM,Golang 相关技术栈, 关注 Liunx kernel,目前痴迷于分布式系统的设计和实践。 研究包括但不限于 Docker Kubernetes eBPF 等相关技术。

Blog

Code

Life

Archive

0 comments
Anonymous
Markdown is supported

Be the first person to leave a comment!