From patchwork Tue May 21 04:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Yang X-Patchwork-Id: 13668893 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 09057C25B74 for ; Tue, 21 May 2024 04:03:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96DAA6B0089; Tue, 21 May 2024 00:03:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 91DBC6B008A; Tue, 21 May 2024 00:03:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BEB36B008C; Tue, 21 May 2024 00:03:28 -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 5E5636B0089 for ; Tue, 21 May 2024 00:03:28 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A42EA40ABB for ; Tue, 21 May 2024 04:03:27 +0000 (UTC) X-FDA: 82141058454.09.D30AFDC Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf30.hostedemail.com (Postfix) with ESMTP id C369580018 for ; Tue, 21 May 2024 04:03:25 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TQTqVnEr; spf=pass (imf30.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.214.177 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=1716264205; 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=SYO5X0diZdV5MQxI/s9TBFrpTwF5UWPwxcd05AKrshs=; b=FVTjk4l0l5swIWVyUBTHmar6yfqDDxjhUh/htF5KQD7ANZYv84AQNsONJsgZwwTOp7GuLf g3UIO5tTJ0xPoXrBxVqOeqYwcsNh4MmzsLaJM90Gjsr5WmwL/q/A43dS08U4nCwNWsklR6 UAWSGcp/1PsB8XANyUyvV/bLiWd1jG4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716264205; a=rsa-sha256; cv=none; b=2caTk3XyFr9ZHa0QBu3teSe7XnUwEOGHH12SwJBhBRX2YTe5ZsFrMnfg4Izqlebrs99e+P 1FRLZ2W9h9DnGl0V5MVQfYahOJf6JD+pjkaru1dtt8KYOGEGZ3KIPXQQM7KZbMlyAtXZzm CslwYbYXC/rhJ3zltI/eEYZwE0LN4z0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TQTqVnEr; spf=pass (imf30.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1ed835f3c3cso28335885ad.3 for ; Mon, 20 May 2024 21:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716264205; x=1716869005; 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=SYO5X0diZdV5MQxI/s9TBFrpTwF5UWPwxcd05AKrshs=; b=TQTqVnErmcL144l1jWEujv1nbZHQvB5OkHNfS9IbV25rvCrLLwE2q/MCaeRt1EJISs uf3YSbEUsRoUl/JkUSkje3me5zj1+wufLVvD9aqL0PZ4TiGuMwa+2vBkYx+hdDBWkstO LgHHk6eSPntFiG5znRBVZNCpIZh6hMvQ7B3NLm0QmYXcBNjzJsg+xlg1nBo4hHKlLEIM 3MTqOK3f889b1MjQBEYLba0ybdQ+LKRe8exeUjDu1xdYagCzC1wzeGjGBkcbAUpUJ0gO 6WjXoGNh9bI7X+o590hF3FCTznOkCidoxMwSdfTGfvpcuvM8g++IdJdJJcaomKGDeKb4 4ilQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716264205; x=1716869005; 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=SYO5X0diZdV5MQxI/s9TBFrpTwF5UWPwxcd05AKrshs=; b=Emh+hZBbIL63z0AAPbtBHl6rBkesNRZWKOZkDn1GLseIB4o/GZNRgQH+dk+JnFDI6P FIpjBFILtUqZg9Q3eqkAbUxbEFJfdlY6q3x9l4zYIsrFKaeeXqTzIwB+HyQSTQWzWGq7 xp3MwBgw9TbhidhNLwlTtIa+Yl5lGn7WaxH5Mx8zXdnLYSRGaYCFDIZbH0ItgY7zVBAM W8kbY/q0dhSra5GRNix2yjYvBG847oE5OdP0Rn5SwnznEn8K6l6GWcjkBnjpTNOcBuxq u9oZovhjU8QRI07wB70o5SoAGD5UluiuCkFkQSqsuMKTmqqWlNa2iWYvr/FE+2YCpTab 5tng== X-Forwarded-Encrypted: i=1; AJvYcCUYB57EnvMqI5zTpd2DcFeAgC+TTa62PE/FvOUtaBFJtfPV93l+jCmkwm/GvgRY95co9K+L6K7DJSdyIrOeK9/V7P8= X-Gm-Message-State: AOJu0YyVGk3iqf4tKb95xNooqVML6i3KpI6vb9AZr/ByWZqukPgiquL1 teYrT1Wh3ymFJ0BANYcyGJyyp9Up7DS+1eUAo6MZZE9hD0O68fPLQy+U1TIt X-Google-Smtp-Source: AGHT+IFHWJ8Khw4UYbDOUMggQ1QP0WPVAp1DDDpri8gSJPT7ekQdp3hNnE42q4+S2/k3OBjhL7AVhw== X-Received: by 2002:a05:6a21:1509:b0:1b1:c77f:56c3 with SMTP id adf61e73a8af0-1b1c77f59a0mr12895842637.7.1716264204618; Mon, 20 May 2024 21:03:24 -0700 (PDT) Received: from LancedeMBP.lan.lan ([2403:2c80:6::302d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bad62bfsm211683945ad.74.2024.05.20.21.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 21:03:24 -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 v6 1/3] mm/rmap: remove duplicated exit code in pagewalk loop Date: Tue, 21 May 2024 12:02:42 +0800 Message-Id: <20240521040244.48760-2-ioworker0@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20240521040244.48760-1-ioworker0@gmail.com> References: <20240521040244.48760-1-ioworker0@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C369580018 X-Rspam-User: X-Stat-Signature: 8bh5kwe9s5cknyi6tn7nn958b1g3gf1i X-HE-Tag: 1716264205-389397 X-HE-Meta: U2FsdGVkX19MST6qGZHA88rsjv/fgUw8wt0SbE5RrEVYfdXD6HCG92pKWc0KABeFDwt3k0BsgtIneddXNEtZi0mIq5O18k1OGD8Kj/j6ZRjP+OMmZ5MJ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n3KNvrN7cd2/aTPDyLeZpVDh4L4HfhhvZqpev7wTsm0LHs0fp0av8PDiVr420DLD2hlGrOxSMRrdQG2oTya/YT5LjKOR1/6JwOnxvpG5a2PJgXQY3Av5Hk7AtvTjfTZvB1j7NOAl58LSfpGndOMOs9baSZFsqQ1VEJUpTce12mRhvLH62rXCDdsCjTDMNrmwMJuW3XSPGsWrCCqp+2C3FwLc0/YC9gd3wDiqcY7eHQqOmt4OJajROHXnyN+fH/IfzCRcVHXeB8rP1uYcPMIIEEEHSkXdv59lWLih3xB+be2huEluF7U8Yw== 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 Signed-off-by: Lance Yang Reviewed-by: David Hildenbrand --- 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);