From nobody Sat Apr 11 00:43:25 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBA92C32772 for ; Thu, 18 Aug 2022 10:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242917AbiHRK5y (ORCPT ); Thu, 18 Aug 2022 06:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244207AbiHRK5l (ORCPT ); Thu, 18 Aug 2022 06:57:41 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16FB391D30 for ; Thu, 18 Aug 2022 03:57:39 -0700 (PDT) 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=ay29a033018045176;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VMaUrGc_1660820256; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VMaUrGc_1660820256) by smtp.aliyun-inc.com; Thu, 18 Aug 2022 18:57:36 +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 1/2] mm/damon/lru_sort: Move target memory region check to head of func Date: Thu, 18 Aug 2022 18:57:31 +0800 Message-Id: <20220818105732.34492-2-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220818105732.34492-1-xhao@linux.alibaba.com> References: <20220818105732.34492-1-xhao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In damon_lru_sort_apply_parameters(), if "monitor_region_start" and "monitor_region_end" is not a valid physical address range, There no need to run the remainder codes in it. Signed-off-by: Xin Hao --- mm/damon/lru_sort.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 9de6f00a71c5..ac50dca026f9 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -378,6 +378,13 @@ static int damon_lru_sort_apply_parameters(void) unsigned int hot_thres, cold_thres; int err =3D 0; =20 + 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)) + return -EINVAL; + err =3D damon_set_attrs(ctx, sample_interval, aggr_interval, 0, min_nr_regions, max_nr_regions); if (err) @@ -401,12 +408,6 @@ static int damon_lru_sort_apply_parameters(void) return -ENOMEM; damon_add_scheme(ctx, scheme); =20 - 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)) - return -EINVAL; addr_range.start =3D monitor_region_start; addr_range.end =3D monitor_region_end; return damon_set_regions(target, &addr_range, 1); --=20 2.27.0 From nobody Sat Apr 11 00:43:25 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B8D4C00140 for ; Thu, 18 Aug 2022 10:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244098AbiHRK6E (ORCPT ); Thu, 18 Aug 2022 06:58:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244199AbiHRK5o (ORCPT ); Thu, 18 Aug 2022 06:57:44 -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 02C1590C50 for ; Thu, 18 Aug 2022 03:57:41 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;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_---0VMaUrGs_1660820256; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VMaUrGs_1660820256) by smtp.aliyun-inc.com; Thu, 18 Aug 2022 18:57:37 +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 2/2] mm/damon/lru_sort: Remove struct of damon_lru_sort_ram_walk_arg Date: Thu, 18 Aug 2022 18:57:32 +0800 Message-Id: <20220818105732.34492-3-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220818105732.34492-1-xhao@linux.alibaba.com> References: <20220818105732.34492-1-xhao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The struct of 'damon_lru_sort_ram_walk_arg' is the same with struct of 'damon_addr_range', so, there no need to redefine it, just use struct of 'damon_addr_range' instead. Signed-off-by: Xin Hao --- mm/damon/lru_sort.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index ac50dca026f9..a3674532fa67 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -257,18 +257,13 @@ 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 =3D arg; + struct damon_addr_range *r =3D arg; - if (a->end - a->start < resource_size(res)) { - a->start =3D res->start; - a->end =3D res->end; + if (r->end - r->start < resource_size(res)) { + r->start =3D res->start; + r->end =3D res->end; } return 0; } @@ -277,16 +272,12 @@ static int walk_system_ram(struct resource *res, void= *arg) * Find biggest 'System RAM' resource and store its start and end address = in * @start and @end, respectively. If no System RAM is found, returns fals= e. */ -static bool get_monitoring_region(unsigned long *start, unsigned long *end) +static bool get_monitoring_region(struct damon_addr_range *range) { - struct damon_lru_sort_ram_walk_arg arg =3D {}; - - walk_system_ram_res(0, ULONG_MAX, &arg, walk_system_ram); - if (arg.end <=3D arg.start) + walk_system_ram_res(0, ULONG_MAX, range, walk_system_ram); + if (range->end <=3D range->start) return false; - *start =3D arg.start; - *end =3D arg.end; return true; } @@ -380,9 +371,12 @@ 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)) + if (!monitor_region_end) + return -EINVAL; + + addr_range.start =3D monitor_region_start; + addr_range.end =3D monitor_region_end; + if (!get_monitoring_region(&addr_range)) return -EINVAL; err =3D damon_set_attrs(ctx, sample_interval, aggr_interval, 0, @@ -408,8 +402,6 @@ static int damon_lru_sort_apply_parameters(void) return -ENOMEM; damon_add_scheme(ctx, scheme); - addr_range.start =3D monitor_region_start; - addr_range.end =3D monitor_region_end; return damon_set_regions(target, &addr_range, 1); } -- 2.27.0