Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2520025lqo; Tue, 14 May 2024 00:43:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVWE+YTGhIBZFAeJRga396cYf6WgGGCDwEm+bRFbP3GEiTDjgYq6cKcpwG2JCbdypGUuRBVnwp2njZC0hq+lpuRXQ2YAOXfZCcObXrmAQ== X-Google-Smtp-Source: AGHT+IFzY57ajywNNBKmbIbbgU7SkOJ9CyFaz1HWlZtox0124ZTuaDcrc3yLcyBtne/GFhXo2hEe X-Received: by 2002:a05:6a20:914f:b0:1af:af89:ed71 with SMTP id adf61e73a8af0-1afde0d3affmr12761059637.19.1715672622573; Tue, 14 May 2024 00:43:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715672622; cv=pass; d=google.com; s=arc-20160816; b=w8eO2kgyQ4zRcKacvZx61IBiVtzJcawu37nKxX87AbD3g9agGt0x1e+x3VGL+ztZr5 8L53w0Vm5ZluVgqOeaLknnFkWqcPBnvYamho6PtPheowLkLW1/wh0lulaG4A39T1et5K JfPZGnm9dOddwYGlzryqnAbRfD0AO5eKqkLIYDlQBP4+Lz2UgJWs85r7VVoiksnRS9G5 70fcAGeRPrR4cyzkFbJt8T5av7AOSgWVkoYLmJUdGR7cfi8MmfNk5tPbGyn7b+fD7ZkL gbJRdacB/Fxc6FiIW43I8XfYxVXgRHJzWiYjUAbcBMbsi17ej7nS9rCVe0NdN11BMOhm GzFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=4/VccQWyT8Bx973VMOtP8EZFRmihEF3ZYyQtstggVOo=; fh=C2m4CDJY0WrRb44BBoMuSGbfeV6WqEuAvdX/ROhhLLQ=; b=yiWIzF8XYM66mYVfyKm0idqq4KHP9QrgAd27YKMUzso/GgDxxqGT701mZudaOudNbe LrA/fkYuKRDVB8Sg1a2NUrj55FrWV4md45vWXGk9v/PdCMCL+nIXfUsf/CdLHqHon2Tm UbqU62EttY9blfhNeRKvtOPxLv/5CYCrXRZEGTL2ZnhItoDI1RAF6FHSJzqfABDh/7Km WS771DK+FL9lePGCiAhNbaVseX8tyly1DYNk/4URG6tJfX4o+rTFjldkG+tbuI2Y0rku Ml/mCwE0s4JIXPrTSpb4pnLpy14nEzniEIgMfbSORI7SzkfxL+x41bY+iQOsoqV4JYo5 mwDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ToKtV0wL; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-178412-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178412-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c16096fsi106734995ad.546.2024.05.14.00.43.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:43:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178412-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ToKtV0wL; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-178412-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178412-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3034F283BDC for ; Tue, 14 May 2024 07:43:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E89BA171D2; Tue, 14 May 2024 07:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ToKtV0wL" Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CDEC1CFBE for ; Tue, 14 May 2024 07:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715672616; cv=none; b=sWhAKkCOK05edmJ6h2Ri9qnCj14/sPwamVG/rp6db1tklMtpKTLe3xAwidWo49Tmnfp0ftAkZTSNeA+8BWX20a8A2KsETdd02GPd2JaFnyv+BDX1B5Ou09XBNEbfeIZJW5edgb6hzYz967ElVvsqWXKpgFUxngE+xwsB5sYrSKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715672616; c=relaxed/simple; bh=0jkJlR9ATeBDrDLZcOfKD2f312tTo0MhL9TABgmCgvg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=AXSz5YcEqOquLxrR0TXq9Qwo3pMTN3tk7s4RyUd/JEjfIFDKdfUX6cIRG0f4yok1vxO8sefZ9qwbdB9/MHoEFo1/eh/Q+A4jbeSR0uqg0Tb6G+lj/nvlKjYk+zS7LxK6Y1zeyvJ4uKiGlC1vaDnmT1KmwWcGAUYCX+5b2QYCfFE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ToKtV0wL; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5231efd80f2so2577905e87.2 for ; Tue, 14 May 2024 00:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715672613; x=1716277413; 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=4/VccQWyT8Bx973VMOtP8EZFRmihEF3ZYyQtstggVOo=; b=ToKtV0wLuYnHzZAFt4k82RwVrY3jyk6lGpkAc0R+130f03bCNyPkSTpD+HMWooDumc rSsWyXn9xTzQmhuavkzgokYVylo5rCd+fe/DUbZSNIZR13ItnBm4SJvHTA5wgX3tOMTh nBbrQbaGuuNfm85trcuH/lcNayZmqZ5MybTrPzWa3JlMshswGua5libdk26aVj7f3AbK cGo3Yv0Bl3YCmobaPbOxI0CRpGzATQFxEGRaXJyrq+ywAoPhFMu2bUrAB9alQI2a/zPh jQ/+ofLFYnApjIGNuTuefyUwd7WUKUq7yZahAlntEa6GDGsYoFXFwG3oipX7qQlN7ADg 2XBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715672613; x=1716277413; 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=4/VccQWyT8Bx973VMOtP8EZFRmihEF3ZYyQtstggVOo=; b=TCbxyU7SYBJ2Rh3P627kG95qRDhjTdRjopJc/VYzduPJhnlEgJRsotOyGto7sTPOVr kimaOmhx0+F/E/bl8wXq029F3hzxPnk0Q2oXnhEMGvCO1LxyNKt0pZnKIdLFsh7fP9gU EV9mM/L41ePjr8Dm2t/jFgWF9H6JyiQEjuDhJrpolvp0Hkt2x5j2f71b2+Im+WEsxokk a8mCQyaPNMRDo2o5swJnz5es8Sxdwv6JKSV55fMMA63/1XMZk5tqXS25FQNwpEqB0bDT 2DenZK2TGi9WYn8c0uemGkTRjtDG+cNBXzTBLy8I9PGEn9tDuPiTSOB5cMD6kUzhlPXd ikKA== X-Forwarded-Encrypted: i=1; AJvYcCX+v7CMkTDdUliGg7jdYJYBiadxHh/q93ss1Qc19HchgpmzeXxuvJUitFAMbFNWqRARQEdUjOg/eH/PXMxWmuanGDgBRoLgKNdlLNT5 X-Gm-Message-State: AOJu0YxHEolgZ42gGoPC9fxvL+moIS0a1fp+OdOO292QXxiSBkMQeGnP W75ErGuXIu6Cxi8Tug33cO++hdJXDveOmLDXXFx+0SXcevJrFsM0y0IIKgY3se/jNVtO/M/UUWz 40PPoA0FN4bHREiBxUwSpmm/qzJY= X-Received: by 2002:a05:6512:158d:b0:519:5df9:d945 with SMTP id 2adb3069b0e04-5220fb77429mr10837058e87.4.1715672613267; Tue, 14 May 2024 00:43:33 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240513074712.7608-1-ioworker0@gmail.com> <20240513074712.7608-2-ioworker0@gmail.com> <2ec286a2-4620-4e6d-ad3d-9b4c0d9e1394@linux.alibaba.com> In-Reply-To: <2ec286a2-4620-4e6d-ad3d-9b4c0d9e1394@linux.alibaba.com> From: Lance Yang Date: Tue, 14 May 2024 15:43:21 +0800 Message-ID: Subject: Re: [PATCH RESEND v5 1/4] mm/rmap: remove duplicated exit code in pagewalk loop To: Baolin Wang Cc: akpm@linux-foundation.org, willy@infradead.org, sj@kernel.org, maskray@google.com, ziy@nvidia.com, ryan.roberts@arm.com, david@redhat.com, 21cnbao@gmail.com, mhocko@suse.com, fengwei.yin@intel.com, zokeefe@google.com, shy828301@gmail.com, xiehuan09@gmail.com, libang.li@antgroup.com, wangkefeng.wang@huawei.com, songmuchun@bytedance.com, peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Baolin, Thanks for taking time to review! Best, Lance On Tue, May 14, 2024 at 2:26=E2=80=AFPM Baolin Wang wrote: > > > > On 2024/5/13 15:47, Lance Yang wrote: > > Introduce the labels walk_done and walk_done_err as exit points to > > eliminate duplicated exit code in the pagewalk loop. > > > > Reviewed-by: Zi Yan > > Signed-off-by: Lance Yang > > LGTM. > Reviewed-by: Baolin Wang > > > --- > > mm/rmap.c | 40 +++++++++++++++------------------------- > > 1 file changed, 15 insertions(+), 25 deletions(-) > > > > diff --git a/mm/rmap.c b/mm/rmap.c > > index e8fc5ecb59b2..ddffa30c79fb 100644 > > --- a/mm/rmap.c > > +++ b/mm/rmap.c > > @@ -1679,9 +1679,7 @@ static bool try_to_unmap_one(struct folio *folio,= struct vm_area_struct *vma, > > /* Restore the mlock which got missed */ > > if (!folio_test_large(folio)) > > mlock_vma_folio(folio, vma); > > - page_vma_mapped_walk_done(&pvmw); > > - ret =3D false; > > - break; > > + goto walk_done_err; > > } > > > > pfn =3D pte_pfn(ptep_get(pvmw.pte)); > > @@ -1719,11 +1717,8 @@ static bool try_to_unmap_one(struct folio *folio= , struct vm_area_struct *vma, > > */ > > if (!anon) { > > VM_BUG_ON(!(flags & TTU_RMAP_LOCKED)); > > - if (!hugetlb_vma_trylock_write(vma)) { > > - page_vma_mapped_walk_done(&pvmw); > > - ret =3D false; > > - break; > > - } > > + if (!hugetlb_vma_trylock_write(vma)) > > + goto walk_done_err; > > if (huge_pmd_unshare(mm, vma, address, pv= mw.pte)) { > > hugetlb_vma_unlock_write(vma); > > flush_tlb_range(vma, > > @@ -1738,8 +1733,7 @@ static bool try_to_unmap_one(struct folio *folio,= struct vm_area_struct *vma, > > * actual page and drop map count > > * to zero. > > */ > > - page_vma_mapped_walk_done(&pvmw); > > - break; > > + goto walk_done; > > } > > hugetlb_vma_unlock_write(vma); > > } > > @@ -1811,9 +1805,7 @@ static bool try_to_unmap_one(struct folio *folio,= struct vm_area_struct *vma, > > if (unlikely(folio_test_swapbacked(folio) !=3D > > folio_test_swapcache(folio))) { > > WARN_ON_ONCE(1); > > - ret =3D false; > > - page_vma_mapped_walk_done(&pvmw); > > - break; > > + goto walk_done_err; > > } > > > > /* MADV_FREE page check */ > > @@ -1852,23 +1844,17 @@ static bool try_to_unmap_one(struct folio *foli= o, struct vm_area_struct *vma, > > */ > > set_pte_at(mm, address, pvmw.pte, pteval)= ; > > folio_set_swapbacked(folio); > > - ret =3D false; > > - page_vma_mapped_walk_done(&pvmw); > > - break; > > + goto walk_done_err; > > } > > > > if (swap_duplicate(entry) < 0) { > > set_pte_at(mm, address, pvmw.pte, pteval)= ; > > - ret =3D false; > > - page_vma_mapped_walk_done(&pvmw); > > - break; > > + goto walk_done_err; > > } > > if (arch_unmap_one(mm, vma, address, pteval) < 0)= { > > swap_free(entry); > > set_pte_at(mm, address, pvmw.pte, pteval)= ; > > - ret =3D false; > > - page_vma_mapped_walk_done(&pvmw); > > - break; > > + goto walk_done_err; > > } > > > > /* See folio_try_share_anon_rmap(): clear PTE fir= st. */ > > @@ -1876,9 +1862,7 @@ static bool try_to_unmap_one(struct folio *folio,= struct vm_area_struct *vma, > > folio_try_share_anon_rmap_pte(folio, subpage)= ) { > > swap_free(entry); > > set_pte_at(mm, address, pvmw.pte, pteval)= ; > > - ret =3D false; > > - page_vma_mapped_walk_done(&pvmw); > > - break; > > + goto walk_done_err; > > } > > if (list_empty(&mm->mmlist)) { > > spin_lock(&mmlist_lock); > > @@ -1918,6 +1902,12 @@ static bool try_to_unmap_one(struct folio *folio= , struct vm_area_struct *vma, > > if (vma->vm_flags & VM_LOCKED) > > mlock_drain_local(); > > folio_put(folio); > > + continue; > > +walk_done_err: > > + ret =3D false; > > +walk_done: > > + page_vma_mapped_walk_done(&pvmw); > > + break; > > } > > > > mmu_notifier_invalidate_range_end(&range);