Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2160183rwd; Tue, 13 Jun 2023 21:39:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6xp1tYQa+4Voz6n2SDvq2gijws70phw4E6tfX55MwzBV6Kx4WeQ/1biWKc5HCBS6hDgMIV X-Received: by 2002:a17:907:3da3:b0:971:eb29:a086 with SMTP id he35-20020a1709073da300b00971eb29a086mr15021558ejc.75.1686717573107; Tue, 13 Jun 2023 21:39:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686717573; cv=none; d=google.com; s=arc-20160816; b=x6m9hWF0WB4+4/KuPU9acAsMc9j9WuvJ+1ZjtozQp6h2vo0vacwTy6nF0Ox7gt4MW9 HSH8suJdY+bQvWJp3Cd2jxPOHQr88/Z2S7EwUuZumC4bZc6H6kkaFyF4g6WlIOWs4qxE CbSUe1LWsb1cG79xe910MulmuuKxrpOAzKGpkgeO4UrGqVIVaZ22dQftFNlI6DiYsdUd fperlyEhN1FqCMoyoY7IZHlG+8eWDWCYVXmUttDM+8N/rbdccAXM7GgYJ6g0bZ5NGqO7 H1SncOHpewjrcWawZdiQ8y80jUv1/6m1qmrTQHva79j8ZUAXp0lku788L8xHfm3u9uZU 9YTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=32HdmVOewK5uBWcPqCzKK7B9PyAlOQ6MrudxZirB7g0=; b=apgxnR5hGywI+eq/n4M/DvcsGGhT1NT48tIV3RDk/byc/N6LNfIQAms8r2y54gb9vt 5Vb2JzEkQZqYiqdE5oGLD4WI2Q3c4S95HuSG1e2dEMFidl8JhC3s/iHErOUCY4Be98TC pVgPi0+CWI8scrqOivCdjWU3d0VGv3cKqLETwerxUzyyOVmqvhVIPQuxVdARn2Zc+TfM A3hNWaeUJhVjwqmV30+paXUL9a5PwLMiDw+0qPlzqxbKSNgMOoVVjek5JJ+M8cBmia/W 1obO/hOrbiDB7RNSEWNfE+rGqP3coh4wHcgyfqFYMi91d5igreHdgpfP4UTWD5E02+jm oH9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=y+wiz6YE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx22-20020a170906af1600b00973c1e1bc46si7302287ejb.616.2023.06.13.21.39.07; Tue, 13 Jun 2023 21:39:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=y+wiz6YE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242506AbjFND67 (ORCPT + 99 others); Tue, 13 Jun 2023 23:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242477AbjFND6m (ORCPT ); Tue, 13 Jun 2023 23:58:42 -0400 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A61211BD3 for ; Tue, 13 Jun 2023 20:58:38 -0700 (PDT) Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-bc5566538fdso255539276.0 for ; Tue, 13 Jun 2023 20:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686715118; x=1689307118; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=32HdmVOewK5uBWcPqCzKK7B9PyAlOQ6MrudxZirB7g0=; b=y+wiz6YEOG+gFWvGvLIELTfeOFEEjmj6VmaR4l5TEimPZrrRLWRSt67ByLkFBEMR+v bCP9oADXmuV0X+UBXpkPh4CBHLVb9CeP7vecSyHdtjJV2q0LIZM6RCX3/ZfE6OLeWFuI RiYBtFemg/LsWw9EhkVn/sj3pOi+OiGTz8E7ryhSTLpImY9d2aChiJnI96YcSsN8AOPd hjqxszOZWh9Q2sMO5YuVZzDVyhYrY/tnHRLv39XACFcZROvrM2V8a8bWDGtUlzxxP5x2 TRoeM13pnRcG1mCAxxo6J+bKVlILKRbVPh5FsuLuBv2UjtpOiUABzvEcJZliHrpOEVfZ D1FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686715118; x=1689307118; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=32HdmVOewK5uBWcPqCzKK7B9PyAlOQ6MrudxZirB7g0=; b=Ealp4TRVMK3/XDV9hFPeFvpRDnl4Tp+zoaLL7mZaewl7QhvxElaPG2bbJmskfxA1ME WOOnbJCRIFYc7aZO3ZavQxlX7Ve4MEgs5b6T1mejOnHDyKInacz/O5HpFGzWiDMGKtrF 8qQ5g3ct6aajklA6Q9MRctPH/pgeWcAIEJJXcmLJH9bOGSFLE25vNGQ4NxoFXUtRrN8q RRENIJH6r96TEWwW6OsvW0h89ygm8Y69Y4McdpRVgGwYvNe4u2NBe3FO6ovG6G8F9BMK JdnJOWhHkhP2/b6OQIAi5elkRrzeLT0vokMHIncOjinzPqnqy4kBt5iDN4s0dk95R+h2 L+yg== X-Gm-Message-State: AC+VfDzFZraejVzXdJrwvdbdmDwhNiZZLuE82ZLkKe25xaGpFn/bD5hJ 46+nOW6Xidu4djg/WKw1/52qww== X-Received: by 2002:a25:ec0d:0:b0:b9e:2b25:be56 with SMTP id j13-20020a25ec0d000000b00b9e2b25be56mr899743ybh.32.1686715117548; Tue, 13 Jun 2023 20:58:37 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id w188-20020a25dfc5000000b00b923b2935d9sm2143983ybg.20.2023.06.13.20.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 20:58:37 -0700 (PDT) Date: Tue, 13 Jun 2023 20:58:26 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: "Huang, Ying" cc: Hugh Dickins , Andrew Morton , Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Lorenzo Stoakes , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 31/32] mm/swap: swap_vma_readahead() do the pte_offset_map() In-Reply-To: <87legp6rax.fsf@yhuang6-desk2.ccr.corp.intel.com> Message-ID: References: <87legp6rax.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 > > --- > > 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" Great, thanks a lot. Hugh