From patchwork Wed Sep 14 11:38:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12976046 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 548F4ECAAD3 for ; Wed, 14 Sep 2022 11:39:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8ED5B6B0074; Wed, 14 Sep 2022 07:39:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89C178D0001; Wed, 14 Sep 2022 07:39:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78AF96B0078; Wed, 14 Sep 2022 07:39:08 -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 69C216B0074 for ; Wed, 14 Sep 2022 07:39:08 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4914E1409D4 for ; Wed, 14 Sep 2022 11:39:08 +0000 (UTC) X-FDA: 79910494776.10.E76F15A Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by imf24.hostedemail.com (Postfix) with ESMTP id BACC71800C9 for ; Wed, 14 Sep 2022 11:39:06 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;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_---0VPnAFuw_1663155541; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPnAFuw_1663155541) by smtp.aliyun-inc.com; Wed, 14 Sep 2022 19:39:03 +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 V2] mm/damon: simplify scheme create in lru_sort.c Date: Wed, 14 Sep 2022 19:38:59 +0800 Message-Id: <20220914113859.37637-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.44 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663155548; a=rsa-sha256; cv=none; b=URmJgGKa9j7JYKVt6iMZutbJG1BofXq8/b4EU+9jM+7Ybl9uJnJWV0d9vm7/ThqI9vVBnt TWwLNy2UkqW0x/xIEOWku/3RixjLydRSUrJVOOmAeyVn6Sfgx1xi5LajQG1ViTdKn+UJZM D5ZhsWSmQCR9o/U35JZiNUeeeNl4ThM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663155548; 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=US2TRRcB95TQg1XVCtLX8ccU4xD4eSe/d+2wqln8qOY=; b=PjOJuraqzzu7IdM9pKiAYj7LF/rukFndvIn00JVwZ2bGa96VOzZkqp+mCNj6hwIxRUtdVa hn8YLDTJYsBefLZigcRv1eO4tpMN5tUHqr6X7r3LM3WoW3AK4818wMXFLLvvbCkq0nxvcb sd3HxjN59gRzPq9KWatXKHCk4CkNxus= X-Stat-Signature: 483gze1e8je6x3crmqsgckdoszjskk9t X-Rspamd-Queue-Id: BACC71800C9 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.44 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspamd-Server: rspam12 X-HE-Tag: 1663155546-48719 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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. Signed-off-by: Xin Hao --- mm/damon/lru_sort.c | 57 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 07a0908963fd..2eac907e866d 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -135,17 +135,40 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat, static struct damon_ctx *ctx; static struct damon_target *target; -static struct damos *damon_lru_sort_new_scheme( - struct damos_access_pattern *pattern, enum damos_action action) +static struct damos *damon_lru_sort_new_scheme(unsigned int thres, + enum damos_action action) { + 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 = 0, + .max_nr_accesses = 0, + /* no matter its age */ + .min_age_region = 0, + .max_age_region = UINT_MAX, + }; struct damos_quota quota = damon_lru_sort_quota; /* Use half of total quota for hot/cold pages sorting */ quota.ms = quota.ms / 2; + switch (action) { + case DAMOS_LRU_PRIO: + pattern.min_nr_accesses = thres; + pattern.max_nr_accesses = UINT_MAX; + break; + case DAMOS_LRU_DEPRIO: + pattern.min_age_region = thres; + break; + default: + return NULL; + } + return damon_new_scheme( /* find the pattern, and */ - pattern, + &pattern, /* (de)prioritize on LRU-lists */ action, /* under the quota. */ @@ -157,37 +180,13 @@ 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, - }; - - return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_PRIO); + return damon_lru_sort_new_scheme(hot_thres, 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, - }; - - return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO); + return damon_lru_sort_new_scheme(cold_thres, DAMOS_LRU_DEPRIO); } static int damon_lru_sort_apply_parameters(void)