split_page_table_lock 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Split page table lock
  2. =====================
  3. Originally, mm->page_table_lock spinlock protected all page tables of the
  4. mm_struct. But this approach leads to poor page fault scalability of
  5. multi-threaded applications due high contention on the lock. To improve
  6. scalability, split page table lock was introduced.
  7. With split page table lock we have separate per-table lock to serialize
  8. access to the table. At the moment we use split lock for PTE and PMD
  9. tables. Access to higher level tables protected by mm->page_table_lock.
  10. There are helpers to lock/unlock a table and other accessor functions:
  11. - pte_offset_map_lock()
  12. maps pte and takes PTE table lock, returns pointer to the taken
  13. lock;
  14. - pte_unmap_unlock()
  15. unlocks and unmaps PTE table;
  16. - pte_alloc_map_lock()
  17. allocates PTE table if needed and take the lock, returns pointer
  18. to taken lock or NULL if allocation failed;
  19. - pte_lockptr()
  20. returns pointer to PTE table lock;
  21. - pmd_lock()
  22. takes PMD table lock, returns pointer to taken lock;
  23. - pmd_lockptr()
  24. returns pointer to PMD table lock;
  25. Split page table lock for PTE tables is enabled compile-time if
  26. CONFIG_SPLIT_PTLOCK_CPUS (usually 4) is less or equal to NR_CPUS.
  27. If split lock is disabled, all tables guaded by mm->page_table_lock.
  28. Split page table lock for PMD tables is enabled, if it's enabled for PTE
  29. tables and the architecture supports it (see below).
  30. Hugetlb and split page table lock
  31. ---------------------------------
  32. Hugetlb can support several page sizes. We use split lock only for PMD
  33. level, but not for PUD.
  34. Hugetlb-specific helpers:
  35. - huge_pte_lock()
  36. takes pmd split lock for PMD_SIZE page, mm->page_table_lock
  37. otherwise;
  38. - huge_pte_lockptr()
  39. returns pointer to table lock;
  40. Support of split page table lock by an architecture
  41. ---------------------------------------------------
  42. There's no need in special enabling of PTE split page table lock:
  43. everything required is done by pgtable_page_ctor() and pgtable_page_dtor(),
  44. which must be called on PTE table allocation / freeing.
  45. Make sure the architecture doesn't use slab allocator for page table
  46. allocation: slab uses page->slab_cache for its pages.
  47. This field shares storage with page->ptl.
  48. PMD split lock only makes sense if you have more than two page table
  49. levels.
  50. PMD split lock enabling requires pgtable_pmd_page_ctor() call on PMD table
  51. allocation and pgtable_pmd_page_dtor() on freeing.
  52. Allocation usually happens in pmd_alloc_one(), freeing in pmd_free() and
  53. pmd_free_tlb(), but make sure you cover all PMD table allocation / freeing
  54. paths: i.e X86_PAE preallocate few PMDs on pgd_alloc().
  55. With everything in place you can set CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK.
  56. NOTE: pgtable_page_ctor() and pgtable_pmd_page_ctor() can fail -- it must
  57. be handled properly.
  58. page->ptl
  59. ---------
  60. page->ptl is used to access split page table lock, where 'page' is struct
  61. page of page containing the table. It shares storage with page->private
  62. (and few other fields in union).
  63. To avoid increasing size of struct page and have best performance, we use a
  64. trick:
  65. - if spinlock_t fits into long, we use page->ptr as spinlock, so we
  66. can avoid indirect access and save a cache line.
  67. - if size of spinlock_t is bigger then size of long, we use page->ptl as
  68. pointer to spinlock_t and allocate it dynamically. This allows to use
  69. split lock with enabled DEBUG_SPINLOCK or DEBUG_LOCK_ALLOC, but costs
  70. one more cache line for indirect access;
  71. The spinlock_t allocated in pgtable_page_ctor() for PTE table and in
  72. pgtable_pmd_page_ctor() for PMD table.
  73. Please, never access page->ptl directly -- use appropriate helper.