Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5593516rwb; Wed, 7 Sep 2022 05:22:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR53oZCNA8MEHQJ6t0GAkGZay/nVViGXnc5yq1Y/vnXLT/2lKpWgWBHGnBzKwXWO+sfdg99I X-Received: by 2002:a17:90b:30d0:b0:200:22a4:bfcf with SMTP id hi16-20020a17090b30d000b0020022a4bfcfmr22185352pjb.181.1662553319988; Wed, 07 Sep 2022 05:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662553319; cv=none; d=google.com; s=arc-20160816; b=KqAxdiFQ4U879al8wNa+4b/pOUGNY65RzxxThp3C1CMOWiHhaYN86MfuJ4/JgtWm+t TYID9I3ik02D3YFZwTnuvjauDj0bgPSQUbE7Z71hpf/Ku7KX5BZr0l1GpC+2p0UIVvAX Cl1OFE6/OkvV13G58Fp3ZbJ0LgtJcgNAb8OkaoX6O89ziFrXnIIkP1+ms90Juvj8IBji DKIpkAvdS5bLZ/g8XCaJDiX+nxqQPN/AtxKxfRgSBgvuipPRt9tKwvkOMmuJavE5iEB3 9uwF4Y+bZ7GV3pce3ZAh6xx1ae1nIsPomrcGqMIfWKLTYJHx5lBtpKDH46GUCFQuleBc ajhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=dzr6S3v7M2RPPtMn+jCxYSpEoZss44ZE1eGfnU9oMcc=; b=HnwK5Gxfx4izIRQIgmK5/sOoaTtPhu94TBX+utJR64vbWLKsxl5uzo18vbkalgCQ4r CziiZOpnbsr8RZQaPcHYJW0/rVq81yddlMrHZDz+pct3iwcAIj2Y/aKBBeOR66V+VbZF +gM0CvEjmMVk4XKjgm3nUIYdauXEaeGlMt9IglvP7w8S0YKgiy5GQDUNSkv6izV9eLkg 13i0SXGZX2+cSBp7vogGFD+pVItAzSfb8cTScweU7T9imXkM0VmaWowFG0+UAn2BXorW 5f5VjKWQ91Uy0bbDLGmUggPFkUXX4F9l4sNvsIcDSgyD1c7XLRZDyvWtxJ96ApXd+X0L Mw+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a63de0a000000b0043038765e87si17597793pgg.600.2022.09.07.05.21.48; Wed, 07 Sep 2022 05:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbiIGL3t (ORCPT + 99 others); Wed, 7 Sep 2022 07:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbiIGL3g (ORCPT ); Wed, 7 Sep 2022 07:29:36 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D68532BB1 for ; Wed, 7 Sep 2022 04:29:30 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R831e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VOy9MDS_1662550166; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VOy9MDS_1662550166) by smtp.aliyun-inc.com; Wed, 07 Sep 2022 19:29:28 +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: Remove duplicate get_monitoring_region() definitions Date: Wed, 7 Sep 2022 19:29:24 +0800 Message-Id: <20220907112924.65546-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In lru_sort.c and reclaim.c, they are all define get_monitoring_region() function, there is no need to define it separately. BTW, this patch remove tow struct 'damon_lru_sort_ram_walk_arg' and 'damon_reclaim_ram_walk_arg', though the two struct are removed, if we want to add more fields to these struct for other purposes later, it will not too late for us to use them again. For example: struct damon_reclaim_ram_walk_arg { struct damon_addr_range raw_walk; xxx A; xxx B; } struct damon_lru_sort_ram_walk_arg { struct damon_addr_range raw_walk; xxx A; xxx B; } Signed-off-by: Xin Hao --- mm/damon/lru_sort.c | 35 ++--------------------------------- mm/damon/ops-common.c | 28 ++++++++++++++++++++++++++++ mm/damon/ops-common.h | 1 + mm/damon/reclaim.c | 35 ++--------------------------------- 4 files changed, 33 insertions(+), 66 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 9de6f00a71c5..5032d59d46e4 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -13,6 +13,8 @@ #include #include +#include "ops-common.h" + #ifdef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX #endif @@ -257,39 +259,6 @@ module_param(nr_cold_quota_exceeds, ulong, 0400); static struct damon_ctx *ctx; static struct damon_target *target; -struct damon_lru_sort_ram_walk_arg { - unsigned long start; - unsigned long end; -}; - -static int walk_system_ram(struct resource *res, void *arg) -{ - struct damon_lru_sort_ram_walk_arg *a = arg; - - if (a->end - a->start < resource_size(res)) { - a->start = res->start; - a->end = res->end; - } - return 0; -} - -/* - * Find biggest 'System RAM' resource and store its start and end address in - * @start and @end, respectively. If no System RAM is found, returns false. - */ -static bool get_monitoring_region(unsigned long *start, unsigned long *end) -{ - struct damon_lru_sort_ram_walk_arg arg = {}; - - walk_system_ram_res(0, ULONG_MAX, &arg, walk_system_ram); - if (arg.end <= arg.start) - return false; - - *start = arg.start; - *end = arg.end; - return true; -} - /* Create a DAMON-based operation scheme for hot memory regions */ static struct damos *damon_lru_sort_new_hot_scheme(unsigned int hot_thres) { diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index b1335de200e7..01938f33038d 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -172,3 +172,31 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r, return hotness; } + +static inline int walk_system_ram(struct resource *res, void *arg) +{ + struct damon_addr_range *a = arg; + + if (a->end - a->start < resource_size(res)) { + a->start = res->start; + a->end = res->end; + } + return 0; +} + +/* + * Find biggest 'System RAM' resource and store its start and end address in + * @start and @end, respectively. If no System RAM is found, returns false. + */ +bool get_monitoring_region(unsigned long *start, unsigned long *end) +{ + struct damon_addr_range arg = {}; + + walk_system_ram_res(0, ULONG_MAX, &arg, walk_system_ram); + if (arg.end <= arg.start) + return false; + + *start = arg.start; + *end = arg.end; + return true; +} diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h index 52329ff361cd..e6f1c9b48042 100644 --- a/mm/damon/ops-common.h +++ b/mm/damon/ops-common.h @@ -16,3 +16,4 @@ int damon_pageout_score(struct damon_ctx *c, struct damon_region *r, struct damos *s); int damon_hot_score(struct damon_ctx *c, struct damon_region *r, struct damos *s); +bool get_monitoring_region(unsigned long *start, unsigned long *end); diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index a7faf51b4bd4..20e83eee3c7d 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -13,6 +13,8 @@ #include #include +#include "ops-common.h" + #ifdef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX #endif @@ -229,39 +231,6 @@ module_param(nr_quota_exceeds, ulong, 0400); static struct damon_ctx *ctx; static struct damon_target *target; -struct damon_reclaim_ram_walk_arg { - unsigned long start; - unsigned long end; -}; - -static int walk_system_ram(struct resource *res, void *arg) -{ - struct damon_reclaim_ram_walk_arg *a = arg; - - if (a->end - a->start < resource_size(res)) { - a->start = res->start; - a->end = res->end; - } - return 0; -} - -/* - * Find biggest 'System RAM' resource and store its start and end address in - * @start and @end, respectively. If no System RAM is found, returns false. - */ -static bool get_monitoring_region(unsigned long *start, unsigned long *end) -{ - struct damon_reclaim_ram_walk_arg arg = {}; - - walk_system_ram_res(0, ULONG_MAX, &arg, walk_system_ram); - if (arg.end <= arg.start) - return false; - - *start = arg.start; - *end = arg.end; - return true; -} - static struct damos *damon_reclaim_new_scheme(void) { struct damos_watermarks wmarks = { -- 2.31.0