Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2039832rdb; Sun, 19 Nov 2023 23:12:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUcUrJla6BrerIxI+RgYmshBkXLdEiJU1x2uvac0dss9NiHqxwsAEJn9pXkSIovHfDiPPt X-Received: by 2002:a17:902:ec02:b0:1cc:4985:fc04 with SMTP id l2-20020a170902ec0200b001cc4985fc04mr5049029pld.66.1700464323852; Sun, 19 Nov 2023 23:12:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700464323; cv=none; d=google.com; s=arc-20160816; b=WVEB8oe4vwx6AC2A8cUzbNCCGQtWbuQuV6TozMtn2GLkpz/TPsRGmqub1dCu91xFuE ZxEhiSat0Uz0xGCf4oGiNrmkRTWNTez3tkf5hA9tbf20Hwl4Cz8d5VeCygpeZCCJ+hR3 HGHOF0s1KHkPmZyZ1oPEK4RNJVIyrxEdFQnGaxxkMuS8NwnD8uPfFYUZgwCLeg4ZD7pI y32C39dLGsULDjiyw2oF62K66LU7vi7iT80G9iDuRcWS5yg0YMIbrPQmPKXKbWBAUFFS X3WxjMcjwKNX6k2/gTyhvVoHGe1RcHdp3Efb6bUYpYeTLb7ng6RYVmuSGOyXmGkXH1KO GtUQ== 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=jCJ4dgFf2ZOyzGS5erWJFwdA6vG22X2QhbIW6nOjEoE=; fh=v/j7QEwtsj+94eMIzch1qbwAijHXRMR6IcasrHCGlTE=; b=igXP4r+1jf32P4GISMjOkcDrabodVuYqrfOhKH+Kx1NketM3IElnANk9Zm6CKQSo9l nlybHEa/iNK1fF0v6EgBhTT1gxjmqFttkY5Rj6/k+zDls/eoi3MqJXdOAVYXckykQROX PugHkl38lns0CUH1e3IiJp2xJCJalZIOcEFXso7cxVE5EKzDs5rrUjmdMnWvMdHp7d3j pKlyerO5TocyPNAOU1ITZRsaO8G0M5ZdDq+paVHy+aw89w0mj3Tx1D7gdlYy/+gXh+w1 GpEjxnXrMvMJvUzLrvlQkVNjhGBkk0QuxGTl72GjziL6VU/oxOu/iP1YFHs++Ct0CJ69 Tv1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l8aUn1Cy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f16-20020a170902ce9000b001cf67432a7csi168568plg.527.2023.11.19.23.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 23:12:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l8aUn1Cy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 3EB3C802C7EF; Sun, 19 Nov 2023 23:04:35 -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 S229785AbjKTHE3 (ORCPT + 99 others); Mon, 20 Nov 2023 02:04:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231948AbjKTHET (ORCPT ); Mon, 20 Nov 2023 02:04:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8D7B90 for ; Sun, 19 Nov 2023 23:04:14 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73AEFC433CC for ; Mon, 20 Nov 2023 07:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700463854; bh=qiloXOTVSC5/MXUHvVybdWbggFP8b1JfMoFufd+ahfo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=l8aUn1Cy0AIbLReZUlsmgeys4vb1gi+fl81kQ46N0jr4xZFuwI2Zcr5dVdgQoho8U BEJZCmAVMYkiV7PBp2M5Sgk5UZz4/XCDpRPZUl8KeodiydyD2HiAY7HzDVJnUldVQG qCOBEw5LUBjgh3mbChX+IByKygyx4iqTnQpXYxVQtlkZpnossgA+CyHRdYtmAA5Ght iWhoWD+7nV+xW2rKS9LGfliOB1BhrHWhhKJ2vO5trJr+s87nm/Hv0i+SgHKlCAVR0d OY6JqmGHElWrkljh9mdSk09ARNFp5n12UxPiG323WwutXQ+eaYaWYyHbpG1n3UG6gL xEv9UhjdnwSqw== Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-28041176e77so2690949a91.0 for ; Sun, 19 Nov 2023 23:04:14 -0800 (PST) X-Gm-Message-State: AOJu0YxpzaGecmjuLpM1MpGiqH98rGFkEWjjjoQqiYaXvC49oTgFEez7 KQkftslXR/+rmxw/y8et26FH2lV+1dqyVRd3tV5MkQ== X-Received: by 2002:a17:90b:4d09:b0:280:a68d:7a35 with SMTP id mw9-20020a17090b4d0900b00280a68d7a35mr4652404pjb.22.1700463853818; Sun, 19 Nov 2023 23:04:13 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-20-ryncsn@gmail.com> In-Reply-To: <20231119194740.94101-20-ryncsn@gmail.com> From: Chris Li Date: Sun, 19 Nov 2023 23:04:02 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 19/24] shmem, swap: refactor error check on OOM or race 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=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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]); Sun, 19 Nov 2023 23:04:35 -0800 (PST) Hi Kairui, On Sun, Nov 19, 2023 at 11:49=E2=80=AFAM Kairui Song wro= te: > > From: Kairui Song > > It should always check if a swap entry is already swaped in on error, > fix potential false error issue. > > Signed-off-by: Kairui Song > --- > mm/shmem.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 81d129aa66d1..6154b5b68b8f 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1857,13 +1857,11 @@ static int shmem_swapin_folio(struct inode *inode= , pgoff_t index, > page =3D swapin_page_non_fault(swap, gfp, mpol, ilx, fault_mm, &r= esult); > mpol_cond_put(mpol); > > - if (PTR_ERR(page) =3D=3D -EBUSY) { > - if (!shmem_confirm_swap(mapping, index, swap)) > - return -EEXIST; Do you intentionally remove checking shmem_confirm_swap()? I am not sure I am following. > + if (IS_ERR_OR_NULL(page)) { > + if (!page) > + error =3D -ENOMEM; > else > - return -EINVAL; > - } else if (!page) { > - error =3D -ENOMEM; > + error =3D -EINVAL; The resulting code is a bit hard to read in diff. In plan source it is like= : if (IS_ERR_OR_NULL(page)) { if (!page) error =3D -ENOMEM; else error =3D -EINVAL; goto failed; } else { folio =3D page_folio(page); if (fault_type && result !=3D SWAP_CACHE_HIT) { *fault_type |=3D VM_FAULT_MAJOR; count_vm_event(PGMAJFAULT); count_memcg_event_mm(fault_mm, PGMAJFAULT); } } First of all, if the first always "goto failed", the second else is not nee= ded. The whole else block can be flatten one indentation. if (IS_ERR_OR_NULL(page)) { if (!page) error =3D -ENOMEM; else error =3D -EINVAL; goto failed; } else { Can be rewrite as following with less indentation: if (!page) { error =3D -ENOMEM; goto failed; } if (IS_ERR(page)) { error =3D -EINVAL; goto failed; } /* else block */ Am I missing something and misreading your code? Chris