From patchwork Tue Sep 13 17:44:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12975081 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 47CD7ECAAD8 for ; Tue, 13 Sep 2022 17:45:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22CFD8000F; Tue, 13 Sep 2022 13:45:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 169698000E; Tue, 13 Sep 2022 13:45:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0F128000D; Tue, 13 Sep 2022 13:45:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CC0F58000A for ; Tue, 13 Sep 2022 13:45:05 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A50DEC0429 for ; Tue, 13 Sep 2022 17:45:05 +0000 (UTC) X-FDA: 79907788128.10.4F2F345 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id E05611C0097 for ; Tue, 13 Sep 2022 17:45:04 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 0D95DCE12E7; Tue, 13 Sep 2022 17:44:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57CE3C433C1; Tue, 13 Sep 2022 17:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663091096; bh=K7noZZXWc7OYsglqBcB0HhttVkm6j87iOZkQHk+Jwew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gjqjlZf4JKxlU1qngINKNjIQRI28bhKmxR92VUaRZcndWGVsHxTgjpcRt1D0Zuwi/ ePWweOxeH7mPuBSxxkL4zVMcsH4BEUV1NwoCQfXffHgIhxad80QCQ2qV008KHhn1Vv hoROFzflbLsBCI3TbtUudMRip+AD3zcKQc/WxZWvjH+kvUUrRZf1kgRbUHtIKUbl93 uDwfi6aqAsyDMGoFYTAiRhyXbFN6YYa4qhwczpJtNWzGb73RaAA7rnjEVaNxUf1bNf DphOwtdl5EriObrDYPtNfFlpiKLOUudJbjBdUgRbArSbBe91yejtE9j/5NCe9eevAu ls+6bACVYRRGw== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/22] mm/damon/paddr: deduplicate damon_pa_{mark_accessed,deactivate_pages}() Date: Tue, 13 Sep 2022 17:44:29 +0000 Message-Id: <20220913174449.50645-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220913174449.50645-1-sj@kernel.org> References: <20220913174449.50645-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663091105; 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=G8oEb3IR+ci6v5JYO1dDzR7cK18S2WRBCByqUFiYYeQ=; b=vV3oDXJWUYJt5Y1wGKqGIlJk9dlIj/j9nW0wTQgNyf+hUiqpfp8qBVhcFSV6eovE0zuVzB sHf2oHHuPHUHbcIPqeeEfs5zM0eHhQW08Imy7dpJqhtApw9+ir1oxSIf3Oc92lidBbl1u2 tZFhJIdaNvU6jzzEV2gm0BYoojRV5yo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gjqjlZf4; spf=pass (imf18.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663091105; a=rsa-sha256; cv=none; b=LCsWXmJNDHqU8d9/NUC0Q8NmPNav1EgVd7xYWhUtQ6NmliVP82JM8TEPns8F24+PVWnaJd f+UvzEnsxUJoWlGsgUPKDp3W9ddZQZ7V4mAqGwReP/4X+t3fMFkVvDRkSVZWFVA39fBjcA lJrS1nclF6bPC+S+63S2BZLKQoayqsE= X-Rspam-User: X-Stat-Signature: cabucxocu4hfos1ic8si8i3q6gu16uqi X-Rspamd-Queue-Id: E05611C0097 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gjqjlZf4; spf=pass (imf18.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam08 X-HE-Tag: 1663091104-770553 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: The bodies of damon_pa_{mark_accessed,deactivate_pages}() contains duplicates. This commit factors out the common part to a separate function and removes the duplicates. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 5eba09d50855..dfeebffe82f4 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -231,7 +231,8 @@ static unsigned long damon_pa_pageout(struct damon_region *r) return applied * PAGE_SIZE; } -static unsigned long damon_pa_mark_accessed(struct damon_region *r) +static inline unsigned long damon_pa_mark_accessed_or_deactivate( + struct damon_region *r, bool mark_accessed) { unsigned long addr, applied = 0; @@ -240,27 +241,24 @@ static unsigned long damon_pa_mark_accessed(struct damon_region *r) if (!page) continue; - mark_page_accessed(page); + if (mark_accessed) + mark_page_accessed(page); + else + deactivate_page(page); put_page(page); applied++; } return applied * PAGE_SIZE; } -static unsigned long damon_pa_deactivate_pages(struct damon_region *r) +static unsigned long damon_pa_mark_accessed(struct damon_region *r) { - unsigned long addr, applied = 0; - - for (addr = r->ar.start; addr < r->ar.end; addr += PAGE_SIZE) { - struct page *page = damon_get_page(PHYS_PFN(addr)); + return damon_pa_mark_accessed_or_deactivate(r, true); +} - if (!page) - continue; - deactivate_page(page); - put_page(page); - applied++; - } - return applied * PAGE_SIZE; +static unsigned long damon_pa_deactivate_pages(struct damon_region *r) +{ + return damon_pa_mark_accessed_or_deactivate(r, false); } static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx,