Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp904338rdh; Fri, 24 Nov 2023 00:15:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpOYckVZs5ReV193si67zfPcd435+5iN/yMNvoXobjhzYAUnA1/jd2/GdMqWCZrlJMDH7Q X-Received: by 2002:a17:902:d346:b0:1cf:531c:f5ce with SMTP id l6-20020a170902d34600b001cf531cf5cemr1986934plk.4.1700813751737; Fri, 24 Nov 2023 00:15:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700813751; cv=none; d=google.com; s=arc-20160816; b=Y6sH8teisjHKEThAENsfrQmf0f20v2idqByGXap4CPXq4wDwD5r/3ZfIHzFasAlmsy hCOsl6sYDrPGYvIWiBgzoQjtNlrox8vOrYoWN+E84RZsD5ICkBp0yLDndf3knedXYBhg qkDxYi4V65VZ3fi6I8nOYVOHzXR7R/GT8p5LmzBuud0Ws+3tCdYsL4N2hFSvc0gXvs70 bieWpKa2NvLmV8aEKI7NQCsFQGWaL6WucHgLDLPGIlvuUO3dnI6k65XUplOfZ9CkcGHi 044rdbjr0W661xDgRQ04gJ4g11f158z6xzvwzuN+6hGkSsH0ooMzI+6HUuKKQfKu20Dl ECTg== 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=5EYwIkp2+JQBbwt8LYg5s9Pu8iHhOSMhe1Ch2bTUfS8=; fh=mxM+iyYud2eqLtG0pkLKi0uG+kielFRY+hhtqFHmhjA=; b=JS3OQtuRG2At+hDMEHM0A+meLTGmajg6q4i8M1C0pGkg8Aeb3JnWXq4MhDPnXplGv1 2QDLp+7BnWUoHatmEutKJirowj0pIhIDylnaH3pfKixJAqg1yQAQ/RW1Ga4KG5OSP6g2 b05+tKt1oq2RvE68fEssFqi6LxTqS1xJWvpj7CvqoFres4oNysSL5ZmLkV0ull++yMCU wvZzT22I8Rj2Gc7BJRqn8zzKoqhRCx1khUKZuNqOJMTtYH5hOkgnjylnSC/g0buwAu74 k6IoK8hToLW4hG0J9Wc8oeNqyGdx8ko4eq+VjxR5Q+12V8xqKmUiAV5Fh4iJXGF7gIg6 QORQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ScsPkB3Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id m7-20020a170902db0700b001cc4fbe9281si2893750plx.582.2023.11.24.00.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:15:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ScsPkB3Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 3767580ACFD1; Fri, 24 Nov 2023 00:15:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344954AbjKXIPR (ORCPT + 99 others); Fri, 24 Nov 2023 03:15:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232747AbjKXIPD (ORCPT ); Fri, 24 Nov 2023 03:15:03 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC3191702 for ; Fri, 24 Nov 2023 00:15:08 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c50fbc218bso19668581fa.3 for ; Fri, 24 Nov 2023 00:15:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700813707; x=1701418507; 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=5EYwIkp2+JQBbwt8LYg5s9Pu8iHhOSMhe1Ch2bTUfS8=; b=ScsPkB3QuOm4j8YMdBtHYMMuSKvWPwBFsTISzw1rJ1YeZiH6kWXMJrVWWiy+O97c2h q1jipEBmSJDfDdD0QhVFO1PSHBLgNFphq+59BiXRb6T1u8Zz+EzmUsxiOnKzUYUyYP9R Omt7WLbHWLGWKuuPFDq28hMKdl6cJxVU5JSz+wp/ErlZc0HBMmHQ5MxY28O9FeT53SK+ BxHRXt+i5jRYA8zQPb1gO6ATUgsxAUzXQIYAQgZXobzRKFK+7V5K/MQOA4E4mSJrHNkw ZPIojiTicSTK0cJ6hOuTkma+moaVRghdwziQfaThP1Xt14wke3OyLWNkE3wi6ed20kfa h32Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700813707; x=1701418507; 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=5EYwIkp2+JQBbwt8LYg5s9Pu8iHhOSMhe1Ch2bTUfS8=; b=As/genYMrLGIG4Qh3MG4aAyrShgtkD0rJvjJEa4mBAI42rkCYLharVFsU9AXwQTEcx 9u0ugA1fPIohShFDpSw24fzkENzvZaiilN3tjFqG2yPIdlXzHTX3eDWcRvRoiG43VRc+ 1YEStcVGwQe4v6xIt5Uw1V7m9eeAG5HE1oQxikHXE3C+rvKiFiXvzD3ps+ydM35kTFUs CVt01TwLOeFqIMm+e8Xi94/x6hTs9Zg9ofScMCuLADY1gw4cCiSqfNcTi0KJk2BcfNu3 2cN//Lx/kjch1SGh9MSRnMhotlmTJX4IdIMF8VObQxQcG2/L1yfTpbjxbKVYJeC7BhA8 ROyA== X-Gm-Message-State: AOJu0YzMvV+3vTzIEFBmc3tXc7EHF7figKjRK7H1TjH0TmraiMzogb2j b0Gv+/ThDIHnRzhf9qZ0jDMQ1cV4kh84lID8E6A= X-Received: by 2002:a2e:90c2:0:b0:2c8:8024:3447 with SMTP id o2-20020a2e90c2000000b002c880243447mr1378942ljg.44.1700813706787; Fri, 24 Nov 2023 00:15:06 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-22-ryncsn@gmail.com> In-Reply-To: From: Kairui Song Date: Fri, 24 Nov 2023 16:14:49 +0800 Message-ID: Subject: Re: [PATCH 21/24] swap: make swapin_readahead result checking argument mandatory 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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 24 Nov 2023 00:15:48 -0800 (PST) Chris Li =E4=BA=8E2023=E5=B9=B411=E6=9C=8822=E6=97=A5= =E5=91=A8=E4=B8=89 13:18=E5=86=99=E9=81=93=EF=BC=9A > > On Sun, Nov 19, 2023 at 11:49=E2=80=AFAM Kairui Song w= rote: > > > > From: Kairui Song > > > > This is only one caller now in page fault path, make the result return > > argument mandatory. > > > > Signed-off-by: Kairui Song > > --- > > mm/swap_state.c | 17 +++++++---------- > > 1 file changed, 7 insertions(+), 10 deletions(-) > > > > diff --git a/mm/swap_state.c b/mm/swap_state.c > > index 6f39aa8394f1..0433a2586c6d 100644 > > --- a/mm/swap_state.c > > +++ b/mm/swap_state.c > > @@ -913,7 +913,6 @@ static struct page *swapin_no_readahead(swp_entry_t= entry, gfp_t gfp_mask, > > struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, > > struct vm_fault *vmf, enum swap_cache_res= ult *result) > > { > > - enum swap_cache_result cache_result; > > struct swap_info_struct *si; > > struct mempolicy *mpol; > > void *shadow =3D NULL; > > @@ -928,29 +927,27 @@ struct page *swapin_readahead(swp_entry_t entry, = gfp_t gfp_mask, > > > > folio =3D swap_cache_get_folio(entry, vmf, &shadow); > > if (folio) { > > + *result =3D SWAP_CACHE_HIT; > > page =3D folio_file_page(folio, swp_offset(entry)); > > - cache_result =3D SWAP_CACHE_HIT; > > goto done; > > } > > > > mpol =3D get_vma_policy(vmf->vma, vmf->address, 0, &ilx); > > if (swap_use_no_readahead(si, swp_offset(entry))) { > > + *result =3D SWAP_CACHE_BYPASS; > > Each of this "*result" will compile into memory store instructions. > The compiler most likely can't optimize and combine them together > because the store can cause segfault from the compiler's point of > view. The multiple local variable assignment can be compiled into a > few registers assignment so it does not cost as much as multiple > memory stores. > > > 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); > > - } else if (swap_use_vma_readahead(si)) { > > - page =3D swap_vma_readahead(entry, gfp_mask, mpol, ilx,= vmf); > > - cache_result =3D SWAP_CACHE_MISS; > > } else { > > - page =3D swap_cluster_readahead(entry, gfp_mask, mpol, = ilx); > > - cache_result =3D SWAP_CACHE_MISS; > > + *result =3D SWAP_CACHE_MISS; > > + if (swap_use_vma_readahead(si)) > > + page =3D swap_vma_readahead(entry, gfp_mask, mp= ol, ilx, vmf); > > + else > > + page =3D swap_cluster_readahead(entry, gfp_mask= , mpol, ilx); > > I recall you introduce or heavy modify this function in previous patch be= fore. > Consider combine some of the patch and present the final version sooner. > From the reviewing point of view, don't need to review so many > internal version which get over written any way. > > > } > > mpol_cond_put(mpol); > > done: > > put_swap_device(si); > > - if (result) > > - *result =3D cache_result; > > The original version with check and assign it at one place is better. > Safer and produce better code. Yes, that's less error-prone indeed, saving a "if" seems doesn't worth all the potential trouble, will drop this.