Re: [PATCH v6 00/24] Speculative page faults
Hi Kirill, Thanks for reviewing this series. On 16/01/2018 16:11, Kirill A. Shutemov wrote: > On Fri, Jan 12, 2018 at 06:25:44PM +0100, Laurent Dufour wrote: >> -- >> Benchmarks results >> >> Base kernel is 4.15-rc6-mmotm-2018-01-04-16-19 >> SPF is BASE + this series > > Do you have THP=always here? Lack of THP support worries me. Yes my kernel is built with THP=always. For the record, I wrote all the code to support THP, but when I was about to plug it into the speculative page fault handler, I was wondering about the pmd_none() check and this raises the issue with khugepaged and the way it is invalidating the pmd before collapsing the underlying pages. Currently, there is no easy way to detect when such a collapsing operation is occurring. > What is performance in the worst case scenario? Like when we go far enough > into > speculative code path on every page fault and then fallback to normal page > fault? I did further tests focusing on the THP with a patched ebizzy (to use posix_memalign() and MADV_HUGEPAGE) to force the use of the transparent huge pages. I double checked that use through /proc/#/smaps. Here is the result I got on a 16 CPUs x86 VM (higher the best): BASESPF mean276.83 276.93 record/s max 280 280 record/s The run was done 100 times using a large enough size records (128 MB). Here is also the event I recorded when running ebizzy during 60s: 275 records/s Performance counter stats for './ebizzy -HT -s 134217728': 182,470 faults 5,085 spf 176,634 pagefault:spf_vma_notsup 10.518504612 seconds time elapsed Most of the speculative page fault events were aborted because the VMA was not supported, which is matching the huge pages (pagefault:spf_vma_notsup). Only 5,000 were managed fully without holding the mmap_sem, I guess for other part of the memory's process. Running the same command on the Base kernel gave: 293 records/s Performance counter stats for './ebizzy -HT -s 134217728': 183,170 faults 10.660787623 seconds time elapsed So I'd say that aborting the speculative page fault handler when a THP is detected, has no visible impact. Cheers, Laurent.
Re: [PATCH v6 00/24] Speculative page faults
On Fri, Jan 12, 2018 at 06:25:44PM +0100, Laurent Dufour wrote: > -- > Benchmarks results > > Base kernel is 4.15-rc6-mmotm-2018-01-04-16-19 > SPF is BASE + this series Do you have THP=always here? Lack of THP support worries me. What is performance in the worst case scenario? Like when we go far enough into speculative code path on every page fault and then fallback to normal page fault? -- Kirill A. Shutemov
[PATCH v6 00/24] Speculative page faults
This is a port on kernel 4.15 of the work done by Peter Zijlstra to handle page fault without holding the mm semaphore [1]. The idea is to try to handle user space page faults without holding the mmap_sem. This should allow better concurrency for massively threaded process since the page fault handler will not wait for other threads memory layout change to be done, assuming that this change is done in another part of the process's memory space. This type page fault is named speculative page fault. If the speculative page fault fails because of a concurrency is detected or because underlying PMD or PTE tables are not yet allocating, it is failing its processing and a classic page fault is then tried. The speculative page fault (SPF) has to look for the VMA matching the fault address without holding the mmap_sem, this is done by introducing a rwlock which protects the access to the mm_rb tree. Previously this was done using SRCU but it was introducing a lot of scheduling to process the VMA's freeing operation which was hitting the performance by 20% as reported by Kemi Wang [2].Using a rwlock to protect access to the mm_rb tree is limiting the locking contention to these operations which are expected to be in a O(log n) order. In addition to ensure that the VMA is not freed in our back a reference count is added and 2 services (get_vma() and put_vma()) are introduced to handle the reference count. When a VMA is fetch from the RB tree using get_vma() is must be later freeed using put_vma(). Furthermore, to allow the VMA to be used again by the classic page fault handler a service is introduced can_reuse_spf_vma(). This service is expected to be called with the mmap_sem hold. It checked that the VMA is still matching the specified address and is releasing its reference count as the mmap_sem is hold it is ensure that it will not be freed in our back. In general, the VMA's reference count could be decremented when holding the mmap_sem but it should not be increased as holding the mmap_sem is ensuring that the VMA is stable. I can't see anymore the overhead I got while will-it-scale benchmark anymore. The VMA's attributes checked during the speculative page fault processing have to be protected against parallel changes. This is done by using a per VMA sequence lock. This sequence lock allows the speculative page fault handler to fast check for parallel changes in progress and to abort the speculative page fault in that case. Once the VMA is found, the speculative page fault handler would check for the VMA's attributes to verify that the page fault has to be handled correctly or not. Thus the VMA is protected through a sequence lock which allows fast detection of concurrent VMA changes. If such a change is detected, the speculative page fault is aborted and a *classic* page fault is tried. VMA sequence lockings are added when VMA attributes which are checked during the page fault are modified. When the PTE is fetched, the VMA is checked to see if it has been changed, so once the page table is locked, the VMA is valid, so any other changes leading to touching this PTE will need to lock the page table, so no parallel change is possible at this time. The locking of the PTE is done with interrupts disabled, this allows to check for the PMD to ensure that there is not an ongoing collapsing operation. Since khugepaged is firstly set the PMD to pmd_none and then is waiting for the other CPU to have catch the IPI interrupt, if the pmd is valid at the time the PTE is locked, we have the guarantee that the collapsing opertion will have to wait on the PTE lock to move foward. This allows the SPF handler to map the PTE safely. If the PMD value is different than the one recorded at the beginning of the SPF operation, the classic page fault handler will be called to handle the operation while holding the mmap_sem. As the PTE lock is done with the interrupts disabled, the lock is done using spin_trylock() to avoid dead lock when handling a page fault while a TLB invalidate is requested by an other CPU holding the PTE. Support for THP is not done because when checking for the PMD, we can be confused by an in progress collapsing operation done by khugepaged. The issue is that pmd_none() could be true either if the PMD is not already populate or if the underlying PTE are in the way to be collapsed. So we cannot safely allocate a PMD if pmd_none() is true. This series builds on top of v4.14-rc5 and is functional on x86 and PowerPC. -- Benchmarks results Base kernel is 4.15-rc6-mmotm-2018-01-04-16-19 SPF is BASE + this series Kernbench: -- Here are the results on a 16 CPUs X86 guest using kernbench on a 4.13-rc4 kernel (kernel is build 5 times): Average Optimal load -j 8 Base SPF Run (std deviation) Elapsed Time 148.04 (0.62446) 150.31 (0.940585) 1.53% UserTime 1017.27 (1.23567) 1029.14 (4.43995) 1.17% System