From patchwork Mon Sep 26 07:10:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12988297 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 97F9BC07E9D for ; Mon, 26 Sep 2022 07:11:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEBCB6B0073; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B75B56B0075; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BAE9900002; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8CEC56B0073 for ; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 687A4140199 for ; Mon, 26 Sep 2022 07:11:10 +0000 (UTC) X-FDA: 79953365100.26.17A1C2B Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf10.hostedemail.com (Postfix) with ESMTP id D7D07C0003 for ; Mon, 26 Sep 2022 07:11:08 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R311e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VQhSYSJ_1664176262; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VQhSYSJ_1664176262) by smtp.aliyun-inc.com; Mon, 26 Sep 2022 15:11:04 +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 v1 1/2] mm/damon: rename sz_damon_region to damon_region_size Date: Mon, 26 Sep 2022 15:10:59 +0800 Message-Id: <20220926071100.76379-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 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=1664176270; a=rsa-sha256; cv=none; b=BeFx2lG7pH+Vr4uY9s+v2RTnDdhgLZAX+8LkYARgPWT9YGJWk44XU6PMwVL9jPi41kIxQf 1VE2ZRRIo+mjjpXuBfbPLNP5+q06afAJ2nkHbBNE1ntpvcvHFRZLQEc0QHqRsDgEEIMxkT 3YpjGbxux6i/Zc5ReQU34Xxmhfy8Liw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664176270; 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=kR56Tq8+SKQ0+NZARRcdHg+lieMEOtjDI3CMArRpzM8=; b=Lk6HOF5mzLBuhKneHL2nIcoWiFLNBSjZj8sPI1m7ufVOcVpyCYsXIePYh/xtZbMj9bNh57 dasAckCVpB0I2ij2GJ3AFzmZBpwq7LUDF1GYZr7IIqff9HZK2wvCvxDLV+99+wAmCEgtT6 PYvd/sctG3bkM5MosZt1my/dVQKGn90= Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Stat-Signature: qdue8a3oxkaasfrt9tcqahema183hjfw X-Rspamd-Queue-Id: D7D07C0003 X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1664176268-675314 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: Here, i rename sz_damon_region() to damon_region_size(), and move it to "include/linux/damon.h", because in many places, we can to use this func. Signed-off-by: Xin Hao --- include/linux/damon.h | 1 + mm/damon/core.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) -- 2.31.0 diff --git a/include/linux/damon.h b/include/linux/damon.h index ed5470f50bab..21f4bfd0f41f 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -524,6 +524,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); +unsigned long damon_region_size(struct damon_region *r); struct damos *damon_new_scheme(struct damos_access_pattern *pattern, enum damos_action action, struct damos_quota *quota, diff --git a/mm/damon/core.c b/mm/damon/core.c index 4de8c7c52979..74ab45b2c2f1 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -864,7 +864,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) } } -static inline unsigned long sz_damon_region(struct damon_region *r) +unsigned long damon_region_size(struct damon_region *r) { return r->ar.end - r->ar.start; } @@ -875,7 +875,7 @@ static inline unsigned long sz_damon_region(struct damon_region *r) static void damon_merge_two_regions(struct damon_target *t, struct damon_region *l, struct damon_region *r) { - unsigned long sz_l = sz_damon_region(l), sz_r = sz_damon_region(r); + unsigned long sz_l = damon_region_size(l), sz_r = damon_region_size(r); l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) / (sz_l + sz_r); @@ -904,7 +904,7 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, if (prev && prev->ar.end == r->ar.start && abs(prev->nr_accesses - r->nr_accesses) <= thres && - sz_damon_region(prev) + sz_damon_region(r) <= sz_limit) + damon_region_size(prev) + damon_region_size(r) <= sz_limit) damon_merge_two_regions(t, prev, r); else prev = r; From patchwork Mon Sep 26 07:11:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12988298 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 67F4DC32771 for ; Mon, 26 Sep 2022 07:11:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3C106B0074; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEC706B0075; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6790900002; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B2F146B0074 for ; Mon, 26 Sep 2022 03:11:10 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 87F61160208 for ; Mon, 26 Sep 2022 07:11:10 +0000 (UTC) X-FDA: 79953365100.22.33DE71A Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf22.hostedemail.com (Postfix) with ESMTP id D6068C0011 for ; Mon, 26 Sep 2022 07:11:08 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;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_---0VQhSYSs_1664176264; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VQhSYSs_1664176264) by smtp.aliyun-inc.com; Mon, 26 Sep 2022 15:11:05 +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 v1 2/2] mm/damon: use damon_region_size() in appropriate place Date: Mon, 26 Sep 2022 15:11:00 +0800 Message-Id: <20220926071100.76379-2-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220926071100.76379-1-xhao@linux.alibaba.com> References: <20220926071100.76379-1-xhao@linux.alibaba.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.131 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=1664176270; a=rsa-sha256; cv=none; b=teXCutPctWhNJ8nPH4KPRJcOvwhfazkOVqeRibrN3Lbk8uGE/t0siFLmxxtR9szHWKrUCn dm5sUNEXz+DNd05a86dr67vMp4nxZQezH16P4CQ8s2zsMMXru0+4trffiCzlUZdSW1PlTB 6KyfXPq2DZHA0z+qnQhjzq7joE7A6qI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664176270; 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:in-reply-to:references:references; bh=7g1SK73q7mOZzSouV3/Tbfi5EhwUassvCOKud5HgAIQ=; b=PFaZnnFZjEm+0UnUdSqcBqDJw9Q1Xip+fb6aavlk756nHwqQGOX20MqSj9vbpz1Ek2AaHt 9alRzSs+icL1aRGmbx9OuQHqdwGp4A7kNVkfLNGyoqwa6+uVFIFPMLeG33R3Q5t2PlhX8I nVp5JnIbmijB5AyA/plWnOqQxws9Ox8= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D6068C0011 Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Stat-Signature: ng63kxps9dpqb7j1gde3faw3fxkrwnaw X-Rspam-User: X-HE-Tag: 1664176268-612878 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 many place, we can use damon_region_size() to instead of "r->ar.end - r->ar.start". Signed-off-by: Xin Hao --- mm/damon/core.c | 17 ++++++++--------- mm/damon/vaddr.c | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) -- 2.31.0 diff --git a/mm/damon/core.c b/mm/damon/core.c index 74ab45b2c2f1..0368551c5a8b 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -490,7 +490,7 @@ static unsigned long damon_region_sz_limit(struct damon_ctx *ctx) damon_for_each_target(t, ctx) { damon_for_each_region(r, t) - sz += r->ar.end - r->ar.start; + sz += damon_region_size(r); } if (ctx->attrs.min_nr_regions) @@ -673,7 +673,7 @@ static bool __damos_valid_target(struct damon_region *r, struct damos *s) { unsigned long sz; - sz = r->ar.end - r->ar.start; + sz = damon_region_size(r); return s->pattern.min_sz_region <= sz && sz <= s->pattern.max_sz_region && s->pattern.min_nr_accesses <= r->nr_accesses && @@ -701,7 +701,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c, damon_for_each_scheme(s, c) { struct damos_quota *quota = &s->quota; - unsigned long sz = r->ar.end - r->ar.start; + unsigned long sz = damon_region_size(r); struct timespec64 begin, end; unsigned long sz_applied = 0; @@ -730,14 +730,14 @@ static void damon_do_apply_schemes(struct damon_ctx *c, sz = ALIGN_DOWN(quota->charge_addr_from - r->ar.start, DAMON_MIN_REGION); if (!sz) { - if (r->ar.end - r->ar.start <= - DAMON_MIN_REGION) + if (damon_region_size(r) <= + DAMON_MIN_REGION) continue; sz = DAMON_MIN_REGION; } damon_split_region_at(t, r, sz); r = damon_next_region(r); - sz = r->ar.end - r->ar.start; + sz = damon_region_size(r); } quota->charge_target_from = NULL; quota->charge_addr_from = 0; @@ -842,8 +842,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) continue; score = c->ops.get_scheme_score( c, t, r, s); - quota->histogram[score] += - r->ar.end - r->ar.start; + quota->histogram[score] += damon_region_size(r); if (score > max_score) max_score = score; } @@ -962,7 +961,7 @@ static void damon_split_regions_of(struct damon_target *t, int nr_subs) int i; damon_for_each_region_safe(r, next, t) { - sz_region = r->ar.end - r->ar.start; + sz_region = damon_region_size(r); for (i = 0; i < nr_subs - 1 && sz_region > 2 * DAMON_MIN_REGION; i++) { diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index ea94e0b2c311..bd1ac9db0f49 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -72,7 +72,7 @@ static int damon_va_evenly_split_region(struct damon_target *t, return -EINVAL; orig_end = r->ar.end; - sz_orig = r->ar.end - r->ar.start; + sz_orig = damon_region_size(r); sz_piece = ALIGN_DOWN(sz_orig / nr_pieces, DAMON_MIN_REGION); if (!sz_piece) @@ -618,7 +618,7 @@ static unsigned long damos_madvise(struct damon_target *target, { struct mm_struct *mm; unsigned long start = PAGE_ALIGN(r->ar.start); - unsigned long len = PAGE_ALIGN(r->ar.end - r->ar.start); + unsigned long len = PAGE_ALIGN(damon_region_size(r)); unsigned long applied; mm = damon_get_mm(target);