Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp58524rwn; Wed, 7 Sep 2022 20:02:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR6vVURprMJpKtKjjMSM+1RfsHeUqSTosy4jburC7UwPhORkAAYm5Qyo8wSEbjOWo2nkD6Tg X-Received: by 2002:a17:902:cecf:b0:174:8caa:247d with SMTP id d15-20020a170902cecf00b001748caa247dmr7264156plg.37.1662606163864; Wed, 07 Sep 2022 20:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662606163; cv=none; d=google.com; s=arc-20160816; b=rtKElQauJpWhqfkFDA6DvHDBm40lteotoejdtQ85VdX9Hy/dm1f+hOK3qPt/IxAH8p Wp7D0J+w158iE3T7hhNTeC2vVb/j6yNPOab5ZZaunYWarFgL6+mUO2QIXyvYYyhgiZ9O 6ffndtRYbVPLIfwQPlWD2GTQgVTnh83O5JY8x11Pf/cSMzKy8Fob/d7shkN8OvLCNSKG RWvNNhPB5ZuUTJJqySxSGuRqxNLgqDL2hM2yUHWUwA/MBmh9O83zYauMWEVOoFlrH8ro ZrhFxsD708MwA4y0+2r6X7XcniyMMN2rrlM4Xj+3SpSY+wQ4L9BExnxuBTp6/zj73l98 vRgQ== 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=iZBDwddYFapoyLqdqO2Ry77n6sAVtspbuIoCqaSfieM=; b=WgOQTxENFhGrn3LJ5EXySR3C0hJ4vQtI/3SeEXDu6wSknI9bKwPWUs4TJOFnLpU5Cu +8zqmAYOy9qhoNsvFH9apB/LHCcF+ngRUlT/u6wqJ6Ng0GtmgyAV6pGD3RJylTtFgTHK eWJw4tw9vTUwS6v3NvHoxkG9Ecu6/OeJWygbWPbkBOJFzOwEQqdZ9tkRqIwbWzKNOWvW k9vESOvVHfG8pCjQKA+tRJANOk4U4Vq4BsjmRMsx0RHlsrBHYIH6e06BXE31kRts/N3y 8hCwvJ136iAtao2fjZbymnR6TTHStSa9wl8rlKr4z5Gqq8sKgNSLx7dLs0m79BNb1fI0 l9qQ== 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 i2-20020a170902cf0200b001769fe091e1si13247639plg.82.2022.09.07.20.02.31; Wed, 07 Sep 2022 20:02:43 -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 S230226AbiIHC01 (ORCPT + 99 others); Wed, 7 Sep 2022 22:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230274AbiIHC0J (ORCPT ); Wed, 7 Sep 2022 22:26:09 -0400 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2776B56DA for ; Wed, 7 Sep 2022 19:25:59 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R951e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VP05YMT_1662603955; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VP05YMT_1662603955) by smtp.aliyun-inc.com; Thu, 08 Sep 2022 10:25:57 +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: Remove duplicate get_monitoring_region() definitions Date: Thu, 8 Sep 2022 10:25:53 +0800 Message-Id: <20220908022553.70745-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,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 defining get_monitoring_region() function, there is no need to define it separately. BTW, this patch removes two struct 'damon_lru_sort_ram_walk_arg' and 'damon_reclaim_ram_walk_arg', though the two structs are removed, if we want to add more fields to these structs 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 --- include/linux/damon.h | 1 + mm/damon/core.c | 28 ++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 37 ++----------------------------------- mm/damon/reclaim.c | 37 ++----------------------------------- 4 files changed, 33 insertions(+), 70 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 7b1f4a488230..f27b92e5afc2 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -500,6 +500,7 @@ void damon_add_region(struct damon_region *r, struct damon_target *t); void damon_destroy_region(struct damon_region *r, struct damon_target *t); int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, unsigned int nr_ranges); +bool damon_get_sram_monitoring_region(unsigned long *start, unsigned long *end); struct damos *damon_new_scheme( unsigned long min_sz_region, unsigned long max_sz_region, diff --git a/mm/damon/core.c b/mm/damon/core.c index 7d25dc582fe3..05a2d1b9d03d 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -276,6 +276,34 @@ struct damos *damon_new_scheme( return scheme; } +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 damon_get_sram_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; +} + void damon_add_scheme(struct damon_ctx *ctx, struct damos *s) { list_add_tail(&s->list, &ctx->schemes); diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 9de6f00a71c5..cbe7e865dc74 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -257,39 +257,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) { @@ -404,8 +371,8 @@ static int damon_lru_sort_apply_parameters(void) if (monitor_region_start > monitor_region_end) return -EINVAL; if (!monitor_region_start && !monitor_region_end && - !get_monitoring_region(&monitor_region_start, - &monitor_region_end)) + !damon_get_sram_monitoring_region(&monitor_region_start, + &monitor_region_end)) return -EINVAL; addr_range.start = monitor_region_start; addr_range.end = monitor_region_end; diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index a7faf51b4bd4..484bb802d249 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -229,39 +229,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 = { @@ -323,8 +290,8 @@ static int damon_reclaim_apply_parameters(void) if (monitor_region_start > monitor_region_end) return -EINVAL; if (!monitor_region_start && !monitor_region_end && - !get_monitoring_region(&monitor_region_start, - &monitor_region_end)) + !damon_get_sram_monitoring_region(&monitor_region_start, + &monitor_region_end)) return -EINVAL; addr_range.start = monitor_region_start; addr_range.end = monitor_region_end; -- 2.31.0