From patchwork Mon Jun 10 12:02:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Yang X-Patchwork-Id: 13691944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D05CC27C55 for ; Mon, 10 Jun 2024 12:02:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B03456B0093; Mon, 10 Jun 2024 08:02:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8B376B0095; Mon, 10 Jun 2024 08:02:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DF766B0096; Mon, 10 Jun 2024 08:02:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 68D996B0093 for ; Mon, 10 Jun 2024 08:02:32 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ECC8CA203C for ; Mon, 10 Jun 2024 12:02:31 +0000 (UTC) X-FDA: 82214841702.28.F7C6938 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf13.hostedemail.com (Postfix) with ESMTP id 14BE62000F for ; Mon, 10 Jun 2024 12:02:28 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EOdxQZQj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=ioworker0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718020949; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lBEr8X48gppOS9Pq+Sw4WgX0PyIHU3keRQ8aF5ykbn0=; b=ZllF4KrK9fDhf67sbTetw+disDNuSNzUKzAdVK1qNiZsNPl2GwUHmTE6hC6LUKBoYVbN5M T/BxEgnEqjLfFmj64j0okm9+yX1aBxAaCcH1S80RrgqTSX9bpygGcqpbinarXahoOEaLbc bv/OM5UTUJA4tFhnCG9mgxiv0Exaq6M= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EOdxQZQj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=ioworker0@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718020949; a=rsa-sha256; cv=none; b=imp538xHkwrMMfKpLQvXsMqDORfOw887UYCKYbmvzHjaoK4zAkHt1VWOU48qop8QBMC0lq Ff22Y5XGKTnNRDH8cCPhd/fEZrkQoeUVHi270lWF4gEfFDArArEj8O+ohJKuODir8TT3og SAMC0V9DsVjAlLaNgH19eMJDIOpkgxg= Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2c2eb98a64fso1242295a91.2 for ; Mon, 10 Jun 2024 05:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718020948; x=1718625748; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lBEr8X48gppOS9Pq+Sw4WgX0PyIHU3keRQ8aF5ykbn0=; b=EOdxQZQj8qxxe3DkgUPccHN6FF3Um6LrCJqw+AAzgWflDEXz2VyhDgUhZ0nrW9yFNJ GI/6mpXtxdKKeJqGRNnHvD0JzsRc7z5hMLh6wzW18ON49HnTz1sx1/CEeEGTvKDmm/9f 8HOtU6DyT5NpoIVC3Ma32kbn/WwS6gfI2lOJuIYhayIJdRh1jgHcYXZetaYsqMC0CdSZ b70PW+Wo8shH6ebnRBXcpfRX1PQc/bTuLVlt3+t+ucUrJ/EDXS5RyZaQfzCXGRtzcvV0 5nDf4r9VztB/6Uv7U3IJQnH2YtZNnMQYQJ58VuHIfTgvNY4dFVoSDYCjpxzk/axAdW7X 5cYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718020948; x=1718625748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lBEr8X48gppOS9Pq+Sw4WgX0PyIHU3keRQ8aF5ykbn0=; b=ur4CKxzLPmcOgLw+i9NaUwmUjj3g5MLAwJu4YCT9IlXvLJxypq2tL6jEZno13/aAuz ckjrKuLr/4BrSjbVfoKcnCEqSnEnFFcD3PBom0o4pMCYH3xT4iKoHareB/4mriLF6Gha dif7ZG4ILQwKwr3n8Z6NdAITF1t3l/t7L8H075ACpl+naWG/R/82/J5smjNxiYxmNIHs pCSbUeTNx87F/b54ojDv9EXyCyVwOBNG5pR/qn1esbbyu/+jw8HG5hlGByvglyNjIOmp KBu3BnZav25FYjab8Pa4WeLe2bp50MYdOQr9/U2H+qteFyz9C9sqktG55j64+GQfcm9u kA/Q== X-Forwarded-Encrypted: i=1; AJvYcCWYR9heBb6YxUFeV1E7Ax9y9NaE+uis0uoIsTXDSafRmll5CzWmJ122LrpF4akHcbrnsgt9OiNMIDkHWzQlm9Yxtik= X-Gm-Message-State: AOJu0Yy28r1KBMRzT9jRBUuSS9gDEATfNJgoYPhCKr0H1cJ6Y8qOAzz5 roZwmXbnzyNrnYZbpkgpxR0flulZ2kzv6QOetRuFPXgFbVDpPlwZ X-Google-Smtp-Source: AGHT+IFSTF5zRph+kFCZTrfNYOUKk6N+AfTH+6+XT32Q1zGJQ4AHy88EyqrdIXL9+OQ1MKB+a7QwUQ== X-Received: by 2002:a17:90a:5e43:b0:2bf:f248:3506 with SMTP id 98e67ed59e1d1-2c2bcaf984fmr8656864a91.12.1718020947621; Mon, 10 Jun 2024 05:02:27 -0700 (PDT) Received: from LancedeMBP.lan.lan ([2403:2c80:6::304c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c302f0ebdcsm2478478a91.23.2024.06.10.05.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 05:02:27 -0700 (PDT) From: Lance Yang To: akpm@linux-foundation.org Cc: willy@infradead.org, sj@kernel.org, baolin.wang@linux.alibaba.com, 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, Lance Yang Subject: [PATCH v7 1/4] mm/rmap: remove duplicated exit code in pagewalk loop Date: Mon, 10 Jun 2024 20:02:06 +0800 Message-Id: <20240610120209.66311-2-ioworker0@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20240610120209.66311-1-ioworker0@gmail.com> References: <20240610120209.66311-1-ioworker0@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 14BE62000F X-Stat-Signature: pk9mgkyh4wudyypmyi6gz55bmfgtk9rq X-HE-Tag: 1718020948-442163 X-HE-Meta: U2FsdGVkX1+e8FBUlZkKhyxOPZwnKHa3Ssps+sppsA7HPJfAqLtU+Tijc77Gr613RWrbyeKzKYVn/ADieg2maYyGVSrYr7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GUQ5Om3UtN3Ug4dHn88RX9Q4Jnvqt4JqusbTPDA5mjg6zEnHQda2fwBilwjotUUC973IdTrFonZTvoer6R/2zFRT/SWl7pTDIpVyw+RtpXuK7ntJ+f46ixT1exJpLyY9vCrPR4jkp+yP8UjECEDBYTVGV+VVws3Cmul95iaW2tmigl3T+YXcUV3vdjTkGmzadDLkB0r6qLMD6aQ3xk6qwrMvFpB9zq90ZQnbgQsiRT3baRhjhfWZfil7sJh5tnYl24MgX8Hb01pfKIUMUCxwHSTllV1GZ4c7g1dMBLmQBSuNie1plRJZjBQE5Sr5odBTq9YV9oGWl/B9qv6KTU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Reviewed-by: Baolin Wang Reviewed-by: David Hildenbrand Signed-off-by: Lance Yang Reviewed-by: Barry Song --- 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 = false; - break; + goto walk_done_err; } pfn = 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 = false; - break; - } + if (!hugetlb_vma_trylock_write(vma)) + goto walk_done_err; if (huge_pmd_unshare(mm, vma, address, pvmw.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) != folio_test_swapcache(folio))) { WARN_ON_ONCE(1); - ret = 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 *folio, struct vm_area_struct *vma, */ set_pte_at(mm, address, pvmw.pte, pteval); folio_set_swapbacked(folio); - ret = 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 = 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 = false; - page_vma_mapped_walk_done(&pvmw); - break; + goto walk_done_err; } /* See folio_try_share_anon_rmap(): clear PTE first. */ @@ -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 = 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 = false; +walk_done: + page_vma_mapped_walk_done(&pvmw); + break; } mmu_notifier_invalidate_range_end(&range);