Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp91558rdd; Wed, 22 Nov 2023 10:08:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWpnWumLZDfb7iMCE6OoBuuyBV4zAhtRtnDGJWUgui7eP046kzeNA1MJHWOjVwK11dFypL X-Received: by 2002:a05:6a21:1485:b0:18b:251d:d6f8 with SMTP id od5-20020a056a21148500b0018b251dd6f8mr2635259pzb.55.1700676525158; Wed, 22 Nov 2023 10:08:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700676525; cv=none; d=google.com; s=arc-20160816; b=SINVx2wqhIHYZ8uWVE9p5ava9pko/Pr4bFRnVfzsNbblPFzQAHwgUObtD8B3tgbhIu Kx8iOg0HGltpMcaWmiwxXlOT/MjndlNKdq3V2BEwdgyu8maZKdkOSDgDw34OxU8I5n9D y/FHXAwukXxKWumRqwl9b15LiyrtzmnZ2GgnnAUfb1Br8TnnB5LW2cprmWC8k5958BvX Vjo1j757aMgfeDmUW5hynoeRxV8LtiLUVPNvRge/SDNQ9NGgwEogNN1ePABS+BchWL4U zS4BFREdGLVLN88p2NjYN2PRho8qTpXVktQ6k3sHz2Duy0TeEu64Kp+17zE9RmJCpU0o e8sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=z//RucA8tE1/CYD6Q8FXMQUzE3udbcwedLzht1PJJU0=; fh=mxM+iyYud2eqLtG0pkLKi0uG+kielFRY+hhtqFHmhjA=; b=thfK65DCpQO0YnuCngQC8BQsh2IaOnHD9AYWW4WRvoAVNBAIqZE/yCSUGcUfTE0O81 nax7D5044cYWlg3XfEHLk1HoSOMgmaCu02r3ZBREhDh3LrrKFjxu+w+8iUBEtn3XRpw5 JqgLMRp/lHIi938JP1g8nFrBFwxJK297S5yPiz1y+vVak3gRaFhf4bB5AJXSfhxUrGaf a5ZCtSZ7LXvXesaKZ9fSXJRwK+NcteBN/jBt+Rf/AhM3mq+iKtubCHf1YH9Qa6Be1Cpp CFuG7enJAoj1lbuK/E+N6/W9VU7+u36Azsgx4sKf+Eoz2DVJvZwcm6NM/sdOTqV9z9n+ cDTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LyVy+TXa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id p38-20020a056a000a2600b006b69f056508si34519pfh.149.2023.11.22.10.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 10:08:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LyVy+TXa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4BEF681EA720; Wed, 22 Nov 2023 10:08:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231478AbjKVSIc (ORCPT + 99 others); Wed, 22 Nov 2023 13:08:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbjKVSIa (ORCPT ); Wed, 22 Nov 2023 13:08:30 -0500 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 371511B6 for ; Wed, 22 Nov 2023 10:08:23 -0800 (PST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2c50fbc218bso661241fa.3 for ; Wed, 22 Nov 2023 10:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700676501; x=1701281301; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=z//RucA8tE1/CYD6Q8FXMQUzE3udbcwedLzht1PJJU0=; b=LyVy+TXamX5b4XO/UjHuY5l/ksKHva9nFIl7bnT/ar9v0b0DdRg0j4FbSZbspcudNq 2YUh41d3IEdlNZY1/FF4nPPp/WmqDjs3YiFcmXNQXLvso3G+w03kMIUKb0eDl9XIylcv y3BVauTwsnuoN5KjFIJd/LEgGreyszLDd0rhTiH6+ZGya4lKgsOfiTI6gvEJ2es0IZ1q ACcCofU9Xh1VGTPyH6u8bBKULwMq8my66L7jl5qpO571toBeE4r3AW5kCuBe0e3vEYzA ji3g/XFkLvzq4c6W9wBE8xB1sLI6qJ2+w9mHcyXCcwqW2TRMAgRyODrg47sG+FvAf8Oe nH+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700676501; x=1701281301; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z//RucA8tE1/CYD6Q8FXMQUzE3udbcwedLzht1PJJU0=; b=TvO7ZOsicXpCw49Gd9T/IN2hdegXk5vaIJ8QHlI1xupMkVgFOTb8xjWRZZY4Xpy4J9 Ype8RoUo+I2IbyHOB8PPbqfII2deMmTenDw1rD3YZoJE2u4WAArcEt1YqYOMPfRu91LF 8K8XpenTm7x0JIpv1r7aUc0L7qIm2InrGTv3rvNG6IGJDI0X6fgEhXOi4y5EH7ggatfO GbmHwg/3+bSPUGbjlQIEY0R/l76rJaWSCbsAKaS7wmc5nJoUpQm1dRsVKayAHomK4RQs cgj4yWpvEt5B1LNQqemXToGY3qukG1kwRqojJ2Lz+u5m7b2OhGTvWT17k3w5Sc70JQDC fKsQ== X-Gm-Message-State: AOJu0YxDeY0E5YmcixXjv/t4b98yi6LLSjDNzM7Vj3zd/kTYimoqb0nH wbwYwnIhrAjTydtJsKGD6F6RbNj4zLwuufKkAsA= X-Received: by 2002:a2e:824f:0:b0:2c5:9e2:ed14 with SMTP id j15-20020a2e824f000000b002c509e2ed14mr2225732ljh.39.1700676501254; Wed, 22 Nov 2023 10:08:21 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-16-ryncsn@gmail.com> In-Reply-To: From: Kairui Song Date: Thu, 23 Nov 2023 02:08:03 +0800 Message-ID: Subject: Re: [PATCH 15/24] mm/swap: avoid an duplicated swap cache lookup for SYNCHRONOUS_IO device To: Chris Li Cc: linux-mm@kvack.org, Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 22 Nov 2023 10:08:39 -0800 (PST) Chris Li =E4=BA=8E2023=E5=B9=B411=E6=9C=8822=E6=97=A5= =E5=91=A8=E4=B8=89 01:18=E5=86=99=E9=81=93=EF=BC=9A > > On Sun, Nov 19, 2023 at 11:48=E2=80=AFAM Kairui Song w= rote: > > > > From: Kairui Song > > > > When a xa_value is returned by the cache lookup, keep it to be used > > later for workingset refault check instead of doing the looking up agai= n > > in swapin_no_readahead. > > > > This does have a side effect of making swapoff also triggers workingset > > check, but should be fine since swapoff does effect the workload in man= y > > ways already. > > I need to sleep on it a bit to see if this will create another problem or= not. > > > > > Signed-off-by: Kairui Song > > --- > > mm/swap_state.c | 10 ++++------ > > 1 file changed, 4 insertions(+), 6 deletions(-) > > > > diff --git a/mm/swap_state.c b/mm/swap_state.c > > index e057c79fb06f..51de2a0412df 100644 > > --- a/mm/swap_state.c > > +++ b/mm/swap_state.c > > @@ -872,7 +872,6 @@ static struct page *swapin_no_readahead(swp_entry_t= entry, gfp_t gfp_mask, > > { > > struct folio *folio; > > struct page *page; > > - void *shadow =3D NULL; > > > > page =3D alloc_pages_mpol(gfp_mask, 0, mpol, ilx, numa_node_id(= )); > > folio =3D (struct folio *)page; > > @@ -888,10 +887,6 @@ static struct page *swapin_no_readahead(swp_entry_= t entry, gfp_t gfp_mask, > > > > mem_cgroup_swapin_uncharge_swap(entry); > > > > - shadow =3D get_shadow_from_swap_cache(entry); > > - if (shadow) > > - workingset_refault(folio, shadow); > > - > > folio_add_lru(folio); > > > > /* To provide entry to swap_readpage() */ > > @@ -922,11 +917,12 @@ struct page *swapin_readahead(swp_entry_t entry, = gfp_t gfp_mask, > > enum swap_cache_result cache_result; > > struct swap_info_struct *si; > > struct mempolicy *mpol; > > + void *shadow =3D NULL; > > struct folio *folio; > > struct page *page; > > pgoff_t ilx; > > > > - folio =3D swap_cache_get_folio(entry, vmf, NULL); > > + folio =3D swap_cache_get_folio(entry, vmf, &shadow); > > if (folio) { > > page =3D folio_file_page(folio, swp_offset(entry)); > > cache_result =3D SWAP_CACHE_HIT; > > @@ -938,6 +934,8 @@ struct page *swapin_readahead(swp_entry_t entry, gf= p_t gfp_mask, > > if (swap_use_no_readahead(si, swp_offset(entry))) { > > page =3D swapin_no_readahead(entry, gfp_mask, mpol, ilx= , vmf->vma->vm_mm); > > cache_result =3D SWAP_CACHE_BYPASS; > > + if (shadow) > > + workingset_refault(page_folio(page), shadow); > > It is inconsistent why other flavors of readahead do not do the > workingset_refault here. Because of the readaheads and swapcache. Every readahead pages need to be checked by workingset_refault with a different shadow (and so a different xarray entry search is needed). And since other swapin path need to insert page into swapcache, they will do extra xarray search/insert anyway so this optimization won't work. > I suggest keeping the workingset_refault in swapin_no_readahead() and > pass the shadow argument in. That sounds good to me.