Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2143452rdb; Mon, 20 Nov 2023 03:21:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGv1qOsBLFyQhEc1n7b+BONOloksV40uU0v8HoTUQ9MGEfMYeHEGrEY9cgk1gHqRwqDiJ7+ X-Received: by 2002:a17:902:7d84:b0:1ce:33b2:a1e0 with SMTP id a4-20020a1709027d8400b001ce33b2a1e0mr7865189plm.33.1700479286531; Mon, 20 Nov 2023 03:21:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700479286; cv=none; d=google.com; s=arc-20160816; b=VGKy7mrEahNsVXXG6L92n2F8smxwrgS83wNVvnX/MDTBMFia8tiw/Or15quSBtmMOt Tp7xcpfIOsFpSF+l9LeHb56vVWe6I+02ZXPFVT2HsF84cWJl+H1rSIK9+OFdAceLhGug Mj1iioxHu8RucoYFeS3QI5Tno+1ATYqmEe+lTL9K0DoLLkRGzRZ+tFMUn+0Kg4oxMp1Q 4OyB+CXpjnlcNaeuSh82+A+W5q5dRx3aI2WhvpbC5Hveb9nCo+NQJp3S9q7qCup+hC/S cOb8z3u0AaxqEFh+Oyuz05DcRzL5V5D2p8nlol5eRZEGNkogA+RwsFsBIqxdDawu0Yud EEgQ== 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=HlAzsIeNdJrrb0PCgVXBwtQkX4AXQb5hB3gxR/EMw3M=; fh=mxM+iyYud2eqLtG0pkLKi0uG+kielFRY+hhtqFHmhjA=; b=u9bR7RA9Z9HMpDR1gPv4yGkynrb5QoBAyCET+NgNv9Sm/XWHlRvrunL2HuG3u9O/5M hasraytO1+FhmZ6idwzanzi6XI0SID0o1Z3qDdm9EvnX5J3rnkHey6SarGlAYZ5buk1s nY1VD9jd2ybIkLKRZs4ypST5QeMieBaCwQzdz28/eP3iB93pJyPiumVhtb2NWCcfgmki JwYXZzD5KkvuiFGafp+2gLbPRJhaA5EbACCrcxXHfJmy7bmNfFwwojbLGvFwrrjXb5DM dsB+fyf90X7jAwDyGiBlon6eNeA6ay1xHcmHdvr7uacSWQ8Wpr7oztOzHMHcbVJTcHT3 xtfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="ZaPA/nPp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id m11-20020a170902768b00b001c9af07788csi7539871pll.76.2023.11.20.03.21.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:21:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="ZaPA/nPp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id E3D168051A31; Mon, 20 Nov 2023 03:21:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233478AbjKTLTg (ORCPT + 99 others); Mon, 20 Nov 2023 06:19:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233406AbjKTLTH (ORCPT ); Mon, 20 Nov 2023 06:19:07 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32557CA for ; Mon, 20 Nov 2023 03:17:45 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c88750e7d1so2560361fa.3 for ; Mon, 20 Nov 2023 03:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700479063; x=1701083863; 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=HlAzsIeNdJrrb0PCgVXBwtQkX4AXQb5hB3gxR/EMw3M=; b=ZaPA/nPp4qE7iQaLfkgxZCixN7xBwiEZbL+iniiLjmmRymsP35FRb9JOhr8ovrIRph LBD7dov7E3Uuy+OZKsUq6WUErfjgb8Tsvxet9W/tu828FlvA3JOjFgE/lm0SR3xuQdJe e7jX1/XS/SyZ/Bp/xl7eFGxuWJF6cddLtJq+RNegC69b2QsSDnlvVk4yQy/jFTc9/CkJ cV/Gv5YOu4eieOPBybvWkwTwID29lC1zVa4dL88jabOq+BdnX8xfCzNz0wGanz2gXPST 9DQcH+2GgSz4gYpd1GZQY4PtqaOsQNUybRm5aHZYMQp1urMkpdO+ajadd35OfkR1gESl jUaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700479063; x=1701083863; 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=HlAzsIeNdJrrb0PCgVXBwtQkX4AXQb5hB3gxR/EMw3M=; b=LkiDlrBG3D2D9TMPR0phxZUw8hUs4/0faSb7UXKC1Jr8YPUX6KMQ3dxG3F3/b+q6uX bb7Xi2tiYo7L0+0we6E4jZjw2d0rCQeJOX1gj6hAdwz/ODUsSPVywdh4Gk1XopfU/mI6 wJNR6R6M1+pBQ7EMfefust+9adWpZSdWM/Vx7wKwB+x0IKmN+7bZ/golVNbpTLDSytED vI7Cm+93bGErZzILSHio6W9g1sPxI6j1vWLB0Ue6NapPsT33QV0wDVk7GVq2C5pEZTFk havjAy/UpAtWcimclVURymLbpieJ3G8wJUX2JOBZZEVZBsY4QBtMJoh0r1mjEoF/QSfN mVIw== X-Gm-Message-State: AOJu0Yz7J8PsjTmWblFO4pD0Zzr+mNasl/PQgjqYG5iltTMoH0ZtSGNg qywSC2YZ0+u64gAxqDWyBLzrFh6OzpIzlpURnf+dQEAJoJMdVA== X-Received: by 2002:a2e:9008:0:b0:2c8:7176:1727 with SMTP id h8-20020a2e9008000000b002c871761727mr4568048ljg.5.1700479062869; Mon, 20 Nov 2023 03:17:42 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-20-ryncsn@gmail.com> In-Reply-To: From: Kairui Song Date: Mon, 20 Nov 2023 19:17:24 +0800 Message-ID: Subject: Re: [PATCH 19/24] shmem, swap: refactor error check on OOM or race 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:21:07 -0800 (PST) Chris Li =E4=BA=8E2023=E5=B9=B411=E6=9C=8820=E6=97=A5= =E5=91=A8=E4=B8=80 15:12=E5=86=99=E9=81=93=EF=BC=9A > > Hi Kairui, > > On Sun, Nov 19, 2023 at 11:49=E2=80=AFAM Kairui Song w= rote: > > > > 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 *ino= de, pgoff_t index, > > page =3D swapin_page_non_fault(swap, gfp, mpol, ilx, fault_mm, = &result); > > 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. Hi, Chris, thanks for the review. This was also called under failed: label so I think there is no need to keep it here. > > > + 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 li= ke: > > 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 n= eeded. > The whole else block can be flatten one indentation. Yes, thanks for the suggestion. > > 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? Your code looks cleaner :) This patch is trying to clean up the error path after the helper refactor, and your suggestions are very helpful, thanks! > > Chris