From patchwork Tue Sep 13 15:22:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12974908 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 6BCB2C6FA82 for ; Tue, 13 Sep 2022 15:22:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D66216B0071; Tue, 13 Sep 2022 11:22:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D15EB6B0072; Tue, 13 Sep 2022 11:22:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDD388D0001; Tue, 13 Sep 2022 11:22:54 -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 ABF3B6B0071 for ; Tue, 13 Sep 2022 11:22:54 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 77DF680305 for ; Tue, 13 Sep 2022 15:22:54 +0000 (UTC) X-FDA: 79907429868.02.65DA7B5 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by imf18.hostedemail.com (Postfix) with ESMTP id 042341C0099 for ; Tue, 13 Sep 2022 15:22:52 +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=ay29a033018046050;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VPhRr.u_1663082568; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPhRr.u_1663082568) by smtp.aliyun-inc.com; Tue, 13 Sep 2022 23:22:49 +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] mm/damon: simplify scheme create in lru_sort.c Date: Tue, 13 Sep 2022 23:22:45 +0800 Message-Id: <20220913152245.25224-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663082574; 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=B5CgmGaFN+7C6dKadxeEy8bZYlsYmNdGjI4b9Ri/Ay8=; b=Ag0oxuwvyLEvCGxoMbbndWmlCXjOgsiJ8XYpuL52HjOi1c5YdpzG2Ge/J4HlA9CxIJHmMV HlPAlJxQKOJzlhqvA83UGP64YClEPbodpRtwEuiyjiUDiSUu/4/xgT4QiPWoePXuSaivS1 RuRTbNUIQMX3UuIrAP2cxNBI+uuQjF8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.57 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=1663082574; a=rsa-sha256; cv=none; b=8malrYFSSea0tkrr0s4IIYCciP+wxQkooBs44whdsVEmD2HvB6wLUsOyQYWqME4RzDzk0T 1USn0A7eINROErL55unuHAr5g1jkiSoklWAcINLYoAE4bNlUl12MEudgdKDVIPzTzjl0pu Bxss+4lqUH7oBSDRPQ+pZMdhXipUn3k= X-Stat-Signature: 8rgspympqe7r4jgtoc8cn6o7fhecsjjb X-Rspamd-Queue-Id: 042341C0099 Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.57 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1663082572-739390 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. Signed-off-by: Xin Hao --- mm/damon/lru_sort.c | 82 +++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 52 deletions(-) -- 2.31.0 diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 8415e18fcf0e..62063ed43224 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -257,15 +257,15 @@ module_param(nr_cold_quota_exceeds, ulong, 0400); static struct damon_ctx *ctx; static struct damon_target *target; -/* Create a DAMON-based operation scheme for hot memory regions */ -static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) +static inline 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 = hot_thres, + .min_nr_accesses = 0, .max_nr_accesses = UINT_MAX, /* no matter its age */ .min_age_region = 0, @@ -292,60 +292,38 @@ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) .weight_age = 0, }; - return damon_new_scheme( - &pattern, - /* prioritize those on LRU lists, as soon as found */ - DAMOS_LRU_PRIO, - /* under the quota. */ - "a, - /* (De)activate this according to the watermarks. */ - &wmarks); + switch (action) { + case DAMOS_LRU_PRIO: + pattern.min_nr_accesses = thres; + break; + case DAMOS_LRU_DEPRIO: + pattern.min_age_region = thres; + quota.weight_nr_accesses = 0; + quota.weight_age = 1; + break; + default: + return NULL; + } + + return damon_new_scheme(&pattern, + /* mark those as not accessed, as soon as found */ + action, + /* under the quota. */ + "a, + /* (De)activate this according to the watermarks. */ + &wmarks); +} + +/* Create a DAMON-based operation scheme for hot memory regions */ +static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) +{ + 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, - }; - struct damos_watermarks wmarks = { - .metric = DAMOS_WMARK_FREE_MEM_RATE, - .interval = wmarks_interval, - .high = wmarks_high, - .mid = wmarks_mid, - .low = wmarks_low, - }; - struct damos_quota quota = { - /* - * Do not try LRU-lists sorting of cold pages for more than - * half of quota_ms milliseconds within - * quota_reset_interval_ms. - */ - .ms = quota_ms / 2, - .sz = 0, - .reset_interval = quota_reset_interval_ms, - /* Within the quota, mark colder regions not accessed first. */ - .weight_sz = 0, - .weight_nr_accesses = 0, - .weight_age = 1, - }; - - return damon_new_scheme( - &pattern, - /* mark those as not accessed, as soon as found */ - DAMOS_LRU_DEPRIO, - /* under the quota. */ - "a, - /* (De)activate this according to the watermarks. */ - &wmarks); + return damon_lru_sort_new_scheme(cold_thres, DAMOS_LRU_DEPRIO); } static int damon_lru_sort_apply_parameters(void)