From patchwork Wed May 1 04:26:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Yang X-Patchwork-Id: 13650206 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 79DBEC4345F for ; Wed, 1 May 2024 04:27:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05EF36B0085; Wed, 1 May 2024 00:27:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F287A6B0087; Wed, 1 May 2024 00:27:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D79D86B0088; Wed, 1 May 2024 00:27:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B814F6B0085 for ; Wed, 1 May 2024 00:27:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 25D3B1406B3 for ; Wed, 1 May 2024 04:27:18 +0000 (UTC) X-FDA: 82068542556.06.03A4048 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by imf11.hostedemail.com (Postfix) with ESMTP id 7D2F840006 for ; Wed, 1 May 2024 04:27:16 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UuDOiPQW; spf=pass (imf11.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.167.180 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714537636; 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=qxwHmPfQRT1njG/0ZnhsAAHKQR4nWB4DSExpUtfTagU=; b=3vGyKgVS5V5AnNw/gaL38fqcvHBDGvvESVvEAk43/Dc5O1a4/Z6VkT88GLdO66Nk2vYbsC JG4BOHjzsq6XhqKp3yQCesIMKE1LYqe6reMRJ//2m44J+iqz5Z8hIZEDxd824joY/uG2ZV IV2BDeC97YSnzftgOKq5YWRqyk+BQs0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UuDOiPQW; spf=pass (imf11.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.167.180 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714537636; a=rsa-sha256; cv=none; b=IuPDBGvnD8p+1/k5W5yhfU+sea/ZMXsSc7kdWdQrmM0LiYSDWzUK3fyuddTHCeuDFC4q/q PFtBVVG1U/fYdG1X73DYu8miDxe4bRWOuB6mtaY3UGikwd3esqM3iomCT4ytP2PTWmKIWR vBRSh7Yx/F8M5h0J+1dECoKdW+2oi+4= Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3c70999ff96so3357603b6e.2 for ; Tue, 30 Apr 2024 21:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714537635; x=1715142435; 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=qxwHmPfQRT1njG/0ZnhsAAHKQR4nWB4DSExpUtfTagU=; b=UuDOiPQWgwNl57LWtzzM5uqVWhySwbevLElw66l0ROfvvVdxwyNgGjooVJJf54Pznr tEiPqcxGkj1VI1y4odah9B7LvI0k0Y4wDBqLoyO8DLDu6hBjrrWIMS/TpYwoRBx//zsS 2qNjWWWruE6POs04fxQtgiAdjranOgZOAxuBLCZlz+4FOi6E6LiUXwED9TS7wGdmq32H CMoRyqqQC5GRzcD9vtCF9f3DnoFPAExT+nBWURwdBKajW+vs/kfVnTKuNF1hDdLR/RFL UnenfEzuRqyQaJ/+uK5P2LvdzbeimPTH/vh126Q0TAUv0rCp4nd7x10mn8QN3T8URb6W rLtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714537635; x=1715142435; 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=qxwHmPfQRT1njG/0ZnhsAAHKQR4nWB4DSExpUtfTagU=; b=vLRLKWYOeif3SeAnuaZ2sgSWetQVTVhyHw2qyUV1swO+CM+JiZVcH3jAsIUf7DSv// Ko21yGJYCryY43TX84km1B0BkSSob3GHKzkwMhbe4T+wIJt5i7NUdmcB2uEpDweJXMfL 5lKUC7pFGxppLzhG0OqxxR/R8vOCRafTO/rxB/+08W2B1DAqJKoMfGx5VgSjWRx+qZJZ BIYbFlSlVy21s2OUNKy9lZ/AiONQuUEozqd7GQBxa2ufrg5q96qM3wP1dJCRA77kMu21 NLSTNUiV2Qnr9PR0tgmnXtrYs1hlJDG2liKx+qQLa0q5PMbQa7kjKkOpdoMOlTGDKSql 50Tw== X-Forwarded-Encrypted: i=1; AJvYcCXjRYlR9eLqz8VsLv5Bd4pfqtu00NlwWOoRqIx9/s7fj8gU5JrBkM8ZeWUprxRVUWgrNu8HRFT736cTbT4lvWohaEw= X-Gm-Message-State: AOJu0Yy1aSFE6B3jq+kLEdv4jVcVH2hoRkuSlwxzXCEQJLcag+hTo5Bu 6Lfsnjhqgx9qswhnul/EHK0Fp8nC5DDoMfmM6SsYv5dsfiYDbLCA X-Google-Smtp-Source: AGHT+IEl+/L1ituyaJTnk0BjJi3vRmGfqMR+zcexC0PXTPj0xeHACJfp1bfVqYeei+6Mig3AUi1xRg== X-Received: by 2002:a05:6808:1813:b0:3c9:147c:bd22 with SMTP id bh19-20020a056808181300b003c9147cbd22mr1266333oib.29.1714537635509; Tue, 30 Apr 2024 21:27:15 -0700 (PDT) Received: from LancedeMBP.lan ([112.10.225.242]) by smtp.gmail.com with ESMTPSA id m15-20020a656a0f000000b005dc4806ad7dsm19165970pgu.40.2024.04.30.21.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 21:27:15 -0700 (PDT) From: Lance Yang To: akpm@linux-foundation.org Cc: 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, Lance Yang Subject: [PATCH v4 1/3] mm/rmap: remove duplicated exit code in pagewalk loop Date: Wed, 1 May 2024 12:26:58 +0800 Message-Id: <20240501042700.83974-2-ioworker0@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20240501042700.83974-1-ioworker0@gmail.com> References: <20240501042700.83974-1-ioworker0@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 7D2F840006 X-Rspamd-Server: rspam06 X-Stat-Signature: tohoyzfi8yqwp6amarr4r3etaqzoycex X-HE-Tag: 1714537636-28642 X-HE-Meta: U2FsdGVkX19UPTdnlhAWxSzMwzGTdmWxBiEmmicz/SaejSw2qybUF2HBYbd1QNnItkTS3nwxL9VvVN1bDAtIkjANygF0ew3WQIFIk8n8/H1nkdSGi5gfDQzutIXDkgcHF0GR2cSWNLFP5sJjSGfQ1kpS2ZwmNcB7Wy1bpRAW/ESiiWCCagYCIaRSUKM3bB00TEls4GHZvc5K/34/bnPkHHQ88N1uiwXQb1/wxbvk1YR3Dhsn2mUNyLFx1F10iOb5wJpl3x1g8nSrIYr0oGjAkuwHkejT577kldOrx/Ec8WOXyMe05v/MkFeC99kS9uhbTA/OimE3QLde2xdU70VXcF3SmZ+vZRfUsFcgriQ/EFjyAbBRpWqZAieXZ6uKN9AOdrlLg9LULQI2vWGndgFLpOD13OybdFe8PyRZTTtaJ+Ci9Zgh43dKRHNJBNqNioqzdLms0o4ITWjQxJbaPhcrd/FzsqLqzG+5J1IIgjhiFro8/PmHZO8OqxpRy1boksH079ngpisODu9DMmuTYtLKvu1xRK2iucE1gOvfhmdmQbvXVlw7/bZdVRZapJPijccXS9tWqj/LYAmLLkTFE8IZL3daxa4qKG2+4Wh5gHpxq5CQ8SVVyJSh3KCJ7/xXi9wa0Ds0bJavB1bpdEp+4ZbsVYSF58oyPy//GtxTdlzMoiPJgMyr2mWxZbU4DLfFKzVKezLGJN3qwZevbFxLVnybf40Dzyh1waC09eDv0n3zXh7kyP8F6+EWTUiWei7pYlWiOStqChPC8hi+Q/lgNuihsFaxniQzJ/QKWJ+XSJsaPxhKO/RsgicWnjsuntMNOJ3rCfhFFJjYKkrOXXKqG+QjBlRiH0EiHIbkDPpiNyt0RtzDbVzkqlNjBefH8WBDDllfFl6JDoeWDEqHnTp6ucsOuhzGSZvsOp2fVlWGC4bJcbeJgcaVuLFd9hp5SrUr1AjVi9ktM1t6C8a1JzC3gqn 6JENLkzJ 07QryO0QtiNp0EDM8kMZM9VcRzPMZ36RAtZik5PgwMb+aNc6cNYqi8pkMJ1/skZLC6+Go0SxSkcDceWcuYqr/zhWxsW9/9ONyNmDo+wN0xJHhTqXm0AYUrbXj/A== 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. Signed-off-by: Lance Yang --- mm/rmap.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 7faa60bc3e4d..7e2575d669a9 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1675,9 +1675,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)); @@ -1715,11 +1713,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, @@ -1734,8 +1729,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); } @@ -1807,9 +1801,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 */ @@ -1848,23 +1840,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. */ @@ -1872,9 +1858,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); @@ -1914,6 +1898,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);