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