Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp866971rdf; Tue, 21 Nov 2023 21:18:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQMfbIOxYq4X4mUkcoZ8l4uegtOr5QvILnDmxylP7seLEMJhc27+s21P7YcQyt4iCt7rAe X-Received: by 2002:a05:6a20:6a06:b0:18a:b5c3:55da with SMTP id p6-20020a056a206a0600b0018ab5c355damr1978033pzk.10.1700630322564; Tue, 21 Nov 2023 21:18:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700630322; cv=none; d=google.com; s=arc-20160816; b=V7m4Dl7XxUhSLyi8s5QCwGDYl9TmXhM8ePdbMPesp8QqwlGBUNBrv9qvoelRZk4YNP KenPVAolbG4gvcGNKCkY8KoobGkd11JQn5AcS608sUlMAWFqi0oq1Xk5Mpj5QCIbbm4n sGYYt2KZDe18WYoBL/pEqr5Gtsesing2LlaZXRuMrHbO/IBo8LUZsNivmLEBUMWevTO9 hpnFw93Evq12MaWXahWY9mcwFgW1igQtgSn61AaOjwYp3ChurkUAV91DZJlZ2VZLwRFT DqciAiwZBn5OMIAe+VcJv2WvaiQhhyVGzFMk9K3t0pXgS2oDnwkfnYJ6noVqN0P3mcA5 WQnA== 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=QFI87lWQwCU40XUe+S4f1ebQgdGXRNK6x+bzjOEYjmk=; fh=v/j7QEwtsj+94eMIzch1qbwAijHXRMR6IcasrHCGlTE=; b=N57ashqWJVxBvuWGwEcZu6SyeJIgxZio77gLP0WpDYLGIFweJTsHNg+qvYrDQqHPY/ fj34JzcOHkOLUIrGrsT/RKCso5W7oYpGa4BJ4CUkX9GEg018R2hTcjMRDBpBzaMWzDmA TD7cHbwPeoXTXTVR7+W+Nd24iKit/4X/8XSZ/sztIAsyhmf4YNaYoA6vVsSTz1YhnGi1 XhJGr/zdeuDUjHRf2JNWEm0Fk1o/QUaM2ONUbnq9ZyFs0Xtjoky6FvNB1LTs8I1q4Xaf +oEiJRM5hwCZd/pxXQpP0inAeQOU0FFuBeJZVmVBm/gootCcySQtWIXvdibUEk+GscpZ CWnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N8GUQTDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t34-20020a056a0013a200b006cb5009ac27si9319226pfg.353.2023.11.21.21.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 21:18:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N8GUQTDJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D44DB80755CD; Tue, 21 Nov 2023 21:15:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233158AbjKVFPl (ORCPT + 99 others); Wed, 22 Nov 2023 00:15:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbjKVFPi (ORCPT ); Wed, 22 Nov 2023 00:15:38 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F07185 for ; Tue, 21 Nov 2023 21:15:34 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3BF2C43391 for ; Wed, 22 Nov 2023 05:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700630133; bh=8yQOtqhJDbJqJorbHOFHuOJO2GdlJMbA2UvGLCtMCfw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=N8GUQTDJrBHnViR8kmwBc7GLdhYNNTLs6n0VJZrrLD2stFjGfiq16elnPlxnbQ1Is utHT21XjjdPT02HRZ1MRhJDnX+JE2TMOqCe54xcH86gjqfVGmATK97Dlne489i05ur QlImiXkNMESgHn54FB7OIYt7TH2trSdPbj1nr7fOS/PxInjzZyZqV6yeUOP6SYS6Y+ Ypb1SlQtLJBg4TSmRhaz0LC7gkKtPiuyDSfCRu3NJwVCVu8QonhIP7WQ/w7ZfaZ8eo H+woImxXZcMU9SaLo3PzrR+10LC6P1JrPvGW0kojsPr9X38lh8bDmzwFHD8jfZNJzo oHU6dF5uxiThQ== Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5be24d41bb8so369009a12.0 for ; Tue, 21 Nov 2023 21:15:33 -0800 (PST) X-Gm-Message-State: AOJu0YzojkKiphqTvPxLcZmSIIeQ+xPY/2dinAAZBCvYETWfoWqCmROo Fbr1FUza0ZbbKJcO2YlY/Wv64oDebYf55CfVTBzz2w== X-Received: by 2002:a17:90b:1bca:b0:27d:8a04:f964 with SMTP id oa10-20020a17090b1bca00b0027d8a04f964mr2097699pjb.24.1700630133034; Tue, 21 Nov 2023 21:15:33 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-22-ryncsn@gmail.com> In-Reply-To: <20231119194740.94101-22-ryncsn@gmail.com> From: Chris Li Date: Tue, 21 Nov 2023 21:15:22 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 21/24] swap: make swapin_readahead result checking argument mandatory To: Kairui Song 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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 21:15:49 -0800 (PST) On Sun, Nov 19, 2023 at 11:49=E2=80=AFAM Kairui Song wro= te: > > 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 e= ntry, gfp_t gfp_mask, > struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, > struct vm_fault *vmf, enum swap_cache_resul= t *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, gf= p_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, v= mf); > - cache_result =3D SWAP_CACHE_MISS; > } else { > - page =3D swap_cluster_readahead(entry, gfp_mask, mpol, il= x); > - 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, mpol= , 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 befo= re. 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. Chris