From patchwork Thu Sep 15 13:30:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12977380 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 08F0FECAAA1 for ; Thu, 15 Sep 2022 13:30:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5656B8D0001; Thu, 15 Sep 2022 09:30:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5151D6B007B; Thu, 15 Sep 2022 09:30:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 404338D0001; Thu, 15 Sep 2022 09:30:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 31F826B0078 for ; Thu, 15 Sep 2022 09:30:49 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EFCA6A0DED for ; Thu, 15 Sep 2022 13:30:48 +0000 (UTC) X-FDA: 79914404976.02.FF228D4 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf23.hostedemail.com (Postfix) with ESMTP id 29E931400BF for ; Thu, 15 Sep 2022 13:30:48 +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 ams.source.kernel.org (Postfix) with ESMTPS id 9F5FBB8204D; Thu, 15 Sep 2022 13:30:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDC60C433C1; Thu, 15 Sep 2022 13:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663248645; bh=h5IX1MKrcfUblY8yoekIagX32KlVYCASL/Rb+1FBFqM=; h=From:To:Cc:Subject:Date:From; b=LixP+DrQUxm+g9O13ts3MR4iOUlsbJOQFNVFmiypecGAC/BiHSpkxPJXS/iRueKme NixrvAdN+FznronfXGHhGCNiaFKyDEU7VGHZ7xQblaPWd358sqCgYrXM8gDjL4s27P REekv1RG2X8/vpVzBF7oCI+WWsUv7ZOI7gJp6WYcYSlI6yrzSlnHnrLA6ASN9OlUFu 8vfdzVyAo/h2d5TMqjYzbOwX4epvCjhgA8qJIB2BJ9NiBC5xF2VM1JGfkgF8/Mha6e r8DBVEKAgb9LOmyJAXBGyGST/xs9h/XanpKe4gdh2SOSd9I/zeEkhXMrsZSfeRc5p5 L+mmH1wGc3wVA== From: SeongJae Park To: akpm@linux-foundation.org Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xin Hao , SeongJae Park Subject: [PATCH v4] mm/damon: simplify scheme create in lru_sort.c Date: Thu, 15 Sep 2022 13:30:41 +0000 Message-Id: <20220915133041.71819-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663248648; 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:references:dkim-signature; bh=tx18abjo3mMb+BirjUjIOBflBErFZcLv6HOhOt7gqTI=; b=xVXGBtXT2U7wCAxQ+ZNWDgWWVIbY55F5LWy9lWkSiZJDCeetlkvNDn7ER2lJPS8yiakF1/ IOTLOXXH+LueS3WRXRYYS95eEwvq8Wq+aXNoBdlvaELP+m7yJo0s3wfiXvODrXM8wyybiU Qn5s6YyaxXqhOYSWdrMoutlQBBLliCg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LixP+DrQ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663248648; a=rsa-sha256; cv=none; b=xy/n4wA7BjBxyLcJoHco0UkudS7Rtd3LopsSPkZH4k0QJmNrN3R5S2NWj3Lgb+SpGwvLpb xguSAbEaQGSNJHoLo7wKuNU1UxXyEYsqv1sX22LfTP0Ji4G4/9JyvflYYPlaoO8Yg3oClt BJG/JeyhyQRjuijijpZ6AbzmvXX4K3w= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 29E931400BF X-Rspam-User: X-Stat-Signature: rb3yfu7bpn6tjrqwc9prsfgwz8s8rr4c Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LixP+DrQ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-HE-Tag: 1663248648-950596 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: From: Xin Hao In damon_lru_sort_new_hot_scheme() and damon_lru_sort_new_cold_scheme(), they have so much in common, so we can combine them into a single function, and we just need to distinguish their differences. Suggested-by: SeongJae Park Signed-off-by: Xin Hao Signed-off-by: SeongJae Park Reviewed-by: Xin Hao --- changes from v3 (https://lore.kernel.org/damon/20220915023655.41923-1-xhao@linux.alibaba.com/) - Cosmetic cleanups Changes from v2 (https://lore.kernel.org/linux-mm/20220914113859.37637-1-xhao@linux.alibaba.com/) - Add static global 'struct damos_access_pattern' stub variable mm/damon/lru_sort.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 46e7c0738bc5..abfaf471e3e9 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -132,6 +132,18 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat, lru_sort_tried_cold_regions, lru_sorted_cold_regions, cold_quota_exceeds); +struct damos_access_pattern damon_lru_sort_stub_pattern = { + /* Find regions having PAGE_SIZE or larger size */ + .min_sz_region = PAGE_SIZE, + .max_sz_region = ULONG_MAX, + /* no matter its access frequency */ + .min_nr_accesses = 0, + .max_nr_accesses = UINT_MAX, + /* no matter its age */ + .min_age_region = 0, + .max_age_region = UINT_MAX, +}; + static struct damon_ctx *ctx; static struct damon_target *target; @@ -157,36 +169,19 @@ static struct damos *damon_lru_sort_new_scheme( /* Create a DAMON-based operation scheme for hot memory regions */ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) { - struct damos_access_pattern pattern = { - /* Find regions having PAGE_SIZE or larger size */ - .min_sz_region = PAGE_SIZE, - .max_sz_region = ULONG_MAX, - /* and accessed for more than the threshold */ - .min_nr_accesses = hot_thres, - .max_nr_accesses = UINT_MAX, - /* no matter its age */ - .min_age_region = 0, - .max_age_region = UINT_MAX, - }; + struct damos_access_pattern pattern = damon_lru_sort_stub_pattern; + pattern.min_nr_accesses = hot_thres; return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO); } /* Create a DAMON-based operation scheme for cold memory regions */ static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres) { - struct damos_access_pattern pattern = { - /* Find regions having PAGE_SIZE or larger size */ - .min_sz_region = PAGE_SIZE, - .max_sz_region = ULONG_MAX, - /* and not accessed at all */ - .min_nr_accesses = 0, - .max_nr_accesses = 0, - /* for min_age or more micro-seconds */ - .min_age_region = cold_thres, - .max_age_region = UINT_MAX, - }; + struct damos_access_pattern pattern = damon_lru_sort_stub_pattern; + pattern.max_nr_accesses = 0; + pattern.min_age_region = cold_thres; return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO); }