From patchwork Thu Sep 15 02:36:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12976785 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 52B55ECAAD8 for ; Thu, 15 Sep 2022 02:37:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7564F6B0071; Wed, 14 Sep 2022 22:37:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7053A6B0073; Wed, 14 Sep 2022 22:37:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F4E38D0001; Wed, 14 Sep 2022 22:37:04 -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 4D6936B0071 for ; Wed, 14 Sep 2022 22:37:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 21C1DA074A for ; Thu, 15 Sep 2022 02:37:04 +0000 (UTC) X-FDA: 79912757568.24.A98BE38 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf02.hostedemail.com (Postfix) with ESMTP id 65D56800AF for ; Thu, 15 Sep 2022 02:37:02 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R631e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VPqc0wr_1663209417; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPqc0wr_1663209417) by smtp.aliyun-inc.com; Thu, 15 Sep 2022 10:36:58 +0800 From: Xin Hao To: sj@kernel.org Cc: akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xhao@linux.alibaba.com Subject: [PATCH V3] mm/damon: simplify scheme create in lru_sort.c Date: Thu, 15 Sep 2022 10:36:55 +0800 Message-Id: <20220915023655.41923-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663209423; a=rsa-sha256; cv=none; b=bPbKOQwcB52p00tZcJYfL6bnAAI9aO++iIVrwIL+KihY+IonfLPeZ7A9o8+r2WXPXzrzN5 iT5C4G0k6/Eogib85MV0l5PO9hoANECs0tdLr3jJi0VsgO2uhe7oeSHWeEYNTVVy7emzUE 7quhueTcO4mYMOYddQoHtOMmdWd+2RE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf02.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663209423; 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; bh=8v5UJ5gntnkzxtROwwY5OhFcu9IAYI1ggfSsvNDSV8c=; b=YbrNS9vvvJl3MAZqyB5o1E9k8odeL+/ikPFKI+bnQPfOXSlPaAZhpzWgCMEG+PfkJcHG3y nrKOQ2l4umMKhpurkVBb8/46hojUQOrnQ69ZQnwlRlKTh9sG4l2GvIdoYb7H43zhJ/ogzW gEfgUisCMKzpUmw/Omgeg2puegqutas= X-Stat-Signature: hfnu6d98r4jd85skp8tpdzyshagbo969 X-Rspamd-Queue-Id: 65D56800AF X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf02.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-Rspamd-Server: rspam02 X-HE-Tag: 1663209422-933063 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: 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 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 | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) -- 2.31.0 diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 07a0908963fd..6a26c5822286 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_access_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 = 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,17 +169,9 @@ 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_access_pattern; + + pattern.min_nr_accesses = hot_thres; return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO); } @@ -175,17 +179,10 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) /* 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_access_pattern; + + pattern.max_nr_accesses = 0; + pattern.min_age_region = cold_thres; return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO); }