On Mon, 12 Jun 2023, Huang, Ying wrote: > Hi, Hugh, > > Sorry for late reply. Never apologize to *me* for being "late" or "slow" or "unresponsive". Thanks for looking, yes, it was indeed for this one that I particularly added you to the Cc. > > Hugh Dickins <hughd@xxxxxxxxxx> writes: > > > swap_vma_readahead() has been proceeding in an unconventional way, its > > preliminary swap_ra_info() doing the pte_offset_map() and pte_unmap(), > > then relying on that pte pointer even after the pte_unmap() - in its > > CONFIG_64BIT case (I think !CONFIG_HIGHPTE was intended; whereas 32-bit > > copied ptes to stack while they were mapped, but had to limit how many). > > > > Though it would be difficult to construct a failing testcase, accessing > > page table after pte_unmap() will become bad practice, even on 64-bit: > > an rcu_read_unlock() in pte_unmap() will allow page table to be freed. > > > > Move relevant definitions from include/linux/swap.h to mm/swap_state.c, > > nothing else used them. Delete the CONFIG_64BIT distinction and buffer, > > delete all reference to ptes from swap_ra_info(), use pte_offset_map() > > repeatedly in swap_vma_readahead(), breaking from the loop if it fails. > > > > (Will the repeated "map" and "unmap" show up as a slowdown anywhere? > > If so, maybe modify __read_swap_cache_async() to do the pte_unmap() > > only when it does not find the page already in the swapcache.) > > > > Use ptep_get_lockless(), mainly for its READ_ONCE(). Correctly advance > > the address passed down to each call of __read__swap_cache_async(). > > > > Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx> > > --- > > include/linux/swap.h | 19 ------------------- > > mm/swap_state.c | 45 +++++++++++++++++++++++--------------------- > > 2 files changed, 24 insertions(+), 40 deletions(-) ... > Because we don't deal with PTEs in struct vma_swap_readahead anymore, it > appears simpler to record addresses directly, for example, > > struct vma_swap_readahead { > unsigned long start; > unsigned long end; > }; > > we can make ra_info.win to be the return value of swap_ra_info(). > > Anyway, this can be a separate cleanup patch based on this patch. Ooh, that would have required me to think, rather than just delete lines. Mmm, if you see a cleaner way forward, yes, please do add some cleanup on top. > > For the patch itself, feel free to add, > > Reviewed-by: "Huang, Ying" <ying.huang@xxxxxxxxx> Great, thanks a lot. Hugh