From patchwork Mon Oct 24 20:49:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018122 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 9AE1DC38A2D for ; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A3BE940008; Mon, 24 Oct 2022 16:49:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 353B4940007; Mon, 24 Oct 2022 16:49:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21BF4940008; Mon, 24 Oct 2022 16:49:28 -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 1213B940007 for ; Mon, 24 Oct 2022 16:49:28 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DFC4B120658 for ; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) X-FDA: 80057033574.03.D48BC96 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 6B37F14000A for ; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2A62361573; Mon, 24 Oct 2022 20:49:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 310FFC43470; Mon, 24 Oct 2022 20:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644565; bh=oUwwKx4MXojkoEQqGNX/HEaiCbrgYpcKgdZZJ/EkGWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uKMGy0G6jcaGd0zTpR25Gix/DSt03DjhqKeRS6R6ysGdjXdWs+7H8xeUlFIeCJL0h 1ZxJ0p4nufcgHwt0jkA1sdbhlmfhB8o9N7kOr7bjj4DkqYvDkvg5crypPti+m4h56x oF0ltzUpLlBpduDIF+VhIqEuEq5nCMFUJaEYGAIIdhdAt8LrvPpr7NjW6q+mFA5/Hy Nw3fO5k/IHl+lF7taJMHNRKazCaOw/prWaaR9srfa4y9bed5HaKoN+8Wian6/QXFlz wPeboMDnqzyY/Yul8HhGh+0cM5fGMK0fr43YGRhBHZlPVPlVPuY/PTj5SfIkl7G+7T XFkTH3jGPpLdw== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/11] mm/damon/core: split out DAMOS-charged region skip logic into a new function Date: Mon, 24 Oct 2022 20:49:09 +0000 Message-Id: <20221024204919.18524-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644567; a=rsa-sha256; cv=none; b=n4cz2YmQbdpFoSDZZsVoesvtnhq5a43qF0Hrht7yNXahDkTXH75vqi7Yizm9DcO/j21qSM r2FCysaOFffsFOOg4o8Nr/tMgzQQjpWzJ3XYfbU7sqoIDIANqZHAeL4VQVk2DmKuPjEwlC XT7FLL+ni6y3AXhDsKLg71AEo4mOthY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uKMGy0G6; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644567; 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:dkim-signature; bh=LvMHpXZEdN3oQBqUmWsHlEJHre7AMc1kY7dAqIHInM8=; b=6hJBxfCGck9Pc6LZ2y10wyy4RCd4+XcW7Ycwoc163wiVgIVE1llQYTh72ibklDWTduIU2u JzMufY24UyaAeINE+8c9Lke7yyisaU7xiN0QvRFMtUVLS5ViUZimyLqdgjq6NPf7tE7zTa b9ONCPObr6ux1zF8J3SK9TtwrAgUXDw= X-Rspamd-Queue-Id: 6B37F14000A Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uKMGy0G6; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: pxhm1ugz64ujw7dp6cknwxopqenie3pa X-HE-Tag: 1666644567-253680 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: The DAMOS action applying function, 'damon_do_apply_schemes()', is quite long and not so simple. Split out the already quota-charged region skip code, which is not a small amount of simple code, into a new function with some comments for better readability. Signed-off-by: SeongJae Park --- mm/damon/core.c | 96 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 36d098d06c55..06b50ede9cc6 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -694,6 +694,67 @@ static bool damos_valid_target(struct damon_ctx *c, struct damon_target *t, return c->ops.get_scheme_score(c, t, r, s) >= s->quota.min_score; } +/* + * damos_skip_charged_region() - Check if the given region or starting part of + * it is already charged for the DAMOS quota. + * @t: The target of the region. + * @rp: The pointer to the region. + * @s: The scheme to be applied. + * + * If a quota of a scheme has exceeded in a quota charge window, the scheme's + * action would applied to only a part of the target access pattern fulfilling + * regions. To avoid applying the scheme action to only already applied + * regions, DAMON skips applying the scheme action to the regions that charged + * in the previous charge window. + * + * This function checks if a given region should be skipped or not for the + * reason. If only the starting part of the region has previously charged, + * this function splits the region into two so that the second one covers the + * area that not charged in the previous charge widnow and saves the second + * region in *rp and returns false, so that the caller can apply DAMON action + * to the second one. + * + * Return: true if the region should be entirely skipped, false otherwise. + */ +static bool damos_skip_charged_region(struct damon_target *t, + struct damon_region **rp, struct damos *s) +{ + struct damon_region *r = *rp; + struct damos_quota *quota = &s->quota; + unsigned long sz_to_skip; + + /* Skip previously charged regions */ + if (quota->charge_target_from) { + if (t != quota->charge_target_from) + return true; + if (r == damon_last_region(t)) { + quota->charge_target_from = NULL; + quota->charge_addr_from = 0; + return true; + } + if (quota->charge_addr_from && + r->ar.end <= quota->charge_addr_from) + return true; + + if (quota->charge_addr_from && r->ar.start < + quota->charge_addr_from) { + sz_to_skip = ALIGN_DOWN(quota->charge_addr_from - + r->ar.start, DAMON_MIN_REGION); + if (!sz_to_skip) { + if (damon_sz_region(r) <= DAMON_MIN_REGION) + return true; + sz_to_skip = DAMON_MIN_REGION; + } + damon_split_region_at(t, r, sz_to_skip); + r = damon_next_region(r); + *rp = r; + } + quota->charge_target_from = NULL; + quota->charge_addr_from = 0; + } + return false; +} + static void damon_do_apply_schemes(struct damon_ctx *c, struct damon_target *t, struct damon_region *r) @@ -702,7 +763,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 = damon_sz_region(r); + unsigned long sz; struct timespec64 begin, end; unsigned long sz_applied = 0; @@ -713,41 +774,14 @@ static void damon_do_apply_schemes(struct damon_ctx *c, if (quota->esz && quota->charged_sz >= quota->esz) continue; - /* Skip previously charged regions */ - if (quota->charge_target_from) { - if (t != quota->charge_target_from) - continue; - if (r == damon_last_region(t)) { - quota->charge_target_from = NULL; - quota->charge_addr_from = 0; - continue; - } - if (quota->charge_addr_from && - r->ar.end <= quota->charge_addr_from) - continue; - - if (quota->charge_addr_from && r->ar.start < - quota->charge_addr_from) { - sz = ALIGN_DOWN(quota->charge_addr_from - - r->ar.start, DAMON_MIN_REGION); - if (!sz) { - if (damon_sz_region(r) <= - DAMON_MIN_REGION) - continue; - sz = DAMON_MIN_REGION; - } - damon_split_region_at(t, r, sz); - r = damon_next_region(r); - sz = damon_sz_region(r); - } - quota->charge_target_from = NULL; - quota->charge_addr_from = 0; - } + if (damos_skip_charged_region(t, &r, s)) + continue; if (!damos_valid_target(c, t, r, s)) continue; /* Apply the scheme */ + sz = damon_sz_region(r); if (c->ops.apply_scheme) { if (quota->esz && quota->charged_sz + sz > quota->esz) { From patchwork Mon Oct 24 20:49:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018123 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 375F6C67871 for ; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81104940007; Mon, 24 Oct 2022 16:49:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 799A9940009; Mon, 24 Oct 2022 16:49:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 639C2940007; Mon, 24 Oct 2022 16:49:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 498BD940009 for ; Mon, 24 Oct 2022 16:49:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 27B1DC071C for ; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) X-FDA: 80057033616.30.2349FDC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id A9F1A140036 for ; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C27CE615AD; Mon, 24 Oct 2022 20:49:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C64AEC433B5; Mon, 24 Oct 2022 20:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644566; bh=6gkbB+R8KOY+SdO75f4hZZPeo2cZLZlMbp4Q5xwVX/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k2JE8BUc9CDzQp8FHIo00S+bYyfg76YGiWY77fybUWWKCKCkKvkBlapFcVAkJdT21 OyxQuZehDJkhV+fP/ZKHNJWb13Rey5FR6GVzdWCAY4xyrPPAIW+b80ttkTMwmpK2xu ke0PoM0FOADZxag6l+3amaoXlIviMs5WIcrJORGgk4VIXyAPBnphiALkNMpTOg1Oo1 LJ7U8LoA3eQ7peUhonZAUQAYxYnDw6fU1OyOyV89AaLor7qP2Vd/lbkd2ph5hYdjfZ 1dTpra6wHkod4UAhw4OzrSI5lszp2jrdqOeLeUDl0EsiTc9F1Y1kBZ+49hmQp5zuPH y7FhKrdRFSINg== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/11] mm/damon/core: split damos application logic into a new function Date: Mon, 24 Oct 2022 20:49:10 +0000 Message-Id: <20221024204919.18524-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644567; 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:dkim-signature; bh=6IDw96NAPiqSJva+D9kDbJFGy3oGiwtYEJtWrgb2Vxw=; b=uVOFyPOmg5QidjHHKvfOhZcQky/bPxcOTt6kkxTJh6i9pwkmshjaQGfg87JaAXwIogVAtN h3FadgGlvU6FyiJDhaPMWWIIH9cZNIUXVsYtCzDvke00uHYd3FIoM00TQKB3khRJ43U9PB pph7E+BU86I1hj3CnDbmZanC8/tx/mA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=k2JE8BUc; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644567; a=rsa-sha256; cv=none; b=f99GTfqP8RRDZSb+kClca6HaZVJZGQAHNrGvZ8RasbD/tmjE1XidpExhriYdK9v/Hih6RO obTGWJkuJNo8/tJtNN7re1FSwOcSEXBwt6pvc8YedhHdRO1UsqtiNZLAota9EVypqWtz1Q SEod4emb6ugLX4AW0FLE4VqUcUpOOac= X-Rspamd-Queue-Id: A9F1A140036 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=k2JE8BUc; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam10 X-Stat-Signature: 97u6cni5zjkmezrjbzmocnzpruyyqrdc X-HE-Tag: 1666644567-620511 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: The DAMOS action applying function, 'damon_do_apply_schemes()', is still long and not easy to read. Split out the code for applying a single action to a single region into a new function for better readability. Signed-off-by: SeongJae Park --- mm/damon/core.c | 73 ++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 06b50ede9cc6..c1a912bc46ae 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -755,6 +755,44 @@ static bool damos_skip_charged_region(struct damon_target *t, return false; } +static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, + struct damon_region *r, struct damos *s) +{ + struct damos_quota *quota = &s->quota; + unsigned long sz = damon_sz_region(r); + struct timespec64 begin, end; + unsigned long sz_applied = 0; + + if (c->ops.apply_scheme) { + if (quota->esz && quota->charged_sz + sz > quota->esz) { + sz = ALIGN_DOWN(quota->esz - quota->charged_sz, + DAMON_MIN_REGION); + if (!sz) + goto update_stat; + damon_split_region_at(t, r, sz); + } + ktime_get_coarse_ts64(&begin); + sz_applied = c->ops.apply_scheme(c, t, r, s); + ktime_get_coarse_ts64(&end); + quota->total_charged_ns += timespec64_to_ns(&end) - + timespec64_to_ns(&begin); + quota->charged_sz += sz; + if (quota->esz && quota->charged_sz >= quota->esz) { + quota->charge_target_from = t; + quota->charge_addr_from = r->ar.end + 1; + } + } + if (s->action != DAMOS_STAT) + r->age = 0; + +update_stat: + s->stat.nr_tried++; + s->stat.sz_tried += sz; + if (sz_applied) + s->stat.nr_applied++; + s->stat.sz_applied += sz_applied; +} + static void damon_do_apply_schemes(struct damon_ctx *c, struct damon_target *t, struct damon_region *r) @@ -763,9 +801,6 @@ 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; - struct timespec64 begin, end; - unsigned long sz_applied = 0; if (!s->wmarks.activated) continue; @@ -780,37 +815,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c, if (!damos_valid_target(c, t, r, s)) continue; - /* Apply the scheme */ - sz = damon_sz_region(r); - if (c->ops.apply_scheme) { - if (quota->esz && - quota->charged_sz + sz > quota->esz) { - sz = ALIGN_DOWN(quota->esz - quota->charged_sz, - DAMON_MIN_REGION); - if (!sz) - goto update_stat; - damon_split_region_at(t, r, sz); - } - ktime_get_coarse_ts64(&begin); - sz_applied = c->ops.apply_scheme(c, t, r, s); - ktime_get_coarse_ts64(&end); - quota->total_charged_ns += timespec64_to_ns(&end) - - timespec64_to_ns(&begin); - quota->charged_sz += sz; - if (quota->esz && quota->charged_sz >= quota->esz) { - quota->charge_target_from = t; - quota->charge_addr_from = r->ar.end + 1; - } - } - if (s->action != DAMOS_STAT) - r->age = 0; - -update_stat: - s->stat.nr_tried++; - s->stat.sz_tried += sz; - if (sz_applied) - s->stat.nr_applied++; - s->stat.sz_applied += sz_applied; + damos_apply_scheme(c, t, r, s); } } From patchwork Mon Oct 24 20:49:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018124 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 6F3DEFA373F for ; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 511C5940009; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 48E6394000D; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 247BA940009; Mon, 24 Oct 2022 16:49:29 -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 0C7BE940009 for ; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 79E4780841 for ; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) X-FDA: 80057033616.26.B8DCEF8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 29BA118001C for ; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 568C6615B3; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 675DBC433C1; Mon, 24 Oct 2022 20:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644566; bh=QMVnOfjAwBASqqnveYH7trvPbLLGctoJVzDXAjo2/8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FyrbHG8NuKtPFlidl5Tt0VxBwZ8AofU8nM31c9QRt1YL5zkER4eT2t+bWyQFKhWKT wgBvSYeXCu/SEO9HBwRLFHFnApLFi4fK3uolj7j1l3IYTVqMbJk9KgSUV3eycqs+4a KC2hn7UvUBfb8XgCKTXaMLzPZiQlY0bnvM9geXmAKP5qtIgFwfRH0WCeNUfMxxVou5 cwKA6edu910iaXY07Tg93RDb/xublLsnERZAR3rBuWGnbAN69bAVk9SIA7ZSVASkRu YFpx/0viFcOmQn1UAp4gY+geKqFA3VTlxr90CWiODhwqD/L8xsvKxyTks3Ye3twMom DLxObNmljhd7Q== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/11] mm/damon/core: split out scheme stat update logic into a new function Date: Mon, 24 Oct 2022 20:49:11 +0000 Message-Id: <20221024204919.18524-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644568; 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:dkim-signature; bh=yUphVaM1VYW9wh/A0/sAzOrAe+7BWF4145DldAvvZ7w=; b=rQQlK9WueOOBj3OlvrzQAaeRsU0XFsAhhMtCCFjodTcingA2aKscOjk5jnEfm0iF42XEEv 8bVSVsIPMUwQs1oPkQXkUU9i7GuieNOHhDnrY64rukoaDCDBD80jRbDMkmyWrn3DnUdVGG KQ06k7o8JLEkbg8VeXRajtpBkxpnsXc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FyrbHG8N; spf=pass (imf06.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644568; a=rsa-sha256; cv=none; b=DttWSobbuNXMLlzr5dTj6tB9wV4UMelrDHo1zmS1wCjJO0dw/95HMjsTuFkOq0BG9y4OkN csg80FwICz07s8P1HXSREDaRt+Hv1FnjijiBkFn31iXXbXc+8GlYimKQ4MEuYxSnk2UrRo sRF99+AyZZxfhnotbCSLpK/6uxXUaH8= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 29BA118001C X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FyrbHG8N; spf=pass (imf06.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: wr8b3kdau96o7jkp5px88s36sm6i9odn X-HE-Tag: 1666644567-602538 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: The function for applying a given DAMON scheme action to a given DAMON region, 'damos_apply_scheme()' is not quite short. Make it better to read by splitting out the stat update logic into a new function. Signed-off-by: SeongJae Park --- mm/damon/core.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index c1a912bc46ae..3a810c6e26bc 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -755,6 +755,16 @@ static bool damos_skip_charged_region(struct damon_target *t, return false; } +static void damos_update_stat(struct damos *s, + unsigned long sz_tried, unsigned long sz_applied) +{ + s->stat.nr_tried++; + s->stat.sz_tried += sz_tried; + if (sz_applied) + s->stat.nr_applied++; + s->stat.sz_applied += sz_applied; +} + static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, struct damon_region *r, struct damos *s) { @@ -786,11 +796,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, r->age = 0; update_stat: - s->stat.nr_tried++; - s->stat.sz_tried += sz; - if (sz_applied) - s->stat.nr_applied++; - s->stat.sz_applied += sz_applied; + damos_update_stat(s, sz, sz_applied); } static void damon_do_apply_schemes(struct damon_ctx *c, From patchwork Mon Oct 24 20:49:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018126 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 B9D2FC38A2D for ; Mon, 24 Oct 2022 20:49:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B227194000B; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7E3494000D; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DE0194000E; Mon, 24 Oct 2022 16:49:29 -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 3A20494000B for ; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 13F38140C4F for ; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) X-FDA: 80057033658.22.173F468 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id A516A100004 for ; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EE451615AD; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F11B0C4347C; Mon, 24 Oct 2022 20:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644567; bh=dahNXHHpseZsI9Nv09e0SATucdrpYMf1XoLkXw98+8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T00bDNA9EM4Dfry8euvfrqLlGlmknH7wo3tkSrHReFZBihrsinlKvK2L6eYULPQ71 CEhWRzbBenBjIaZ4xywgYNePssRTPlLGv/TTZf2YahCGZ60rbcYuw6AALjOMWfphHY HltEqsgeCd1Q2xSuMHVmc+QmHO8G4GK2irj3nbqXCjkypNOKBzV3T9OpuJJU2Qz4zs q/0wlkJgkK3VcA8eTX7mBjy1aVzt+LXhrDDU0SF4KiUt6htMt6fa0XPXmcPrsu5ma2 5ZXYR6syB+bRWAl1LEBPvVsA5Ld3jN8MhWF+d3+jxfZgkGEDDO1IGv+5OCvKqa7Wgq VD4zGhLaNXxtw== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/11] mm/damon/core: split out scheme quota adjustment logic into a new function Date: Mon, 24 Oct 2022 20:49:12 +0000 Message-Id: <20221024204919.18524-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644568; 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:dkim-signature; bh=VcTQr7jD9MTx+tgBKr2WrTJarvzJlUpBZKclONSTMuE=; b=qRY36m7MOLqzc/5bpL4NZ+L17YgHNaV4PlCf1UGC33fKb5uIcF7A6gHT1wWxEmvcIT2m0C lyCRAzFGbh8RZGp5Cst6JNOkrZOHr+2+8MaqBm5agEuvQbPrntc/JIkdFu3v3xrO3c/qKy Wk7EFYVQXoCsnLe5kpwByZd7LDq9Cls= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T00bDNA9; spf=pass (imf05.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644568; a=rsa-sha256; cv=none; b=Gc2XxyNdM9XXJh87OgSZfcDw+z1TLScNGWV+aya5/3d1tv6dMI+QgredCilPYZ38r8zn0I 16fkj8sMtezlvfPjYEEld78Ji+eqHZ2o+gW5QflIb4UnIQqnP8b6zAbW/rOW7Ff13+R1AI PLcSGFh8u/b1P0bD8IAkRSqhh76AIYY= X-Rspamd-Queue-Id: A516A100004 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T00bDNA9; spf=pass (imf05.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam10 X-Stat-Signature: djbp3q349kjuiurfhcjbaiiyxkeamqzs X-HE-Tag: 1666644568-80558 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: DAMOS quota adjustment logic in 'kdamond_apply_schemes()', has some amount of code, and the logic is not so straightforward. Split it out to a new function for better readability. Signed-off-by: SeongJae Park --- mm/damon/core.c | 91 ++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 3a810c6e26bc..80d5937fe337 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -848,59 +848,64 @@ static void damos_set_effective_quota(struct damos_quota *quota) quota->esz = esz; } -static void kdamond_apply_schemes(struct damon_ctx *c) +static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) { + struct damos_quota *quota = &s->quota; struct damon_target *t; - struct damon_region *r, *next_r; - struct damos *s; + struct damon_region *r; + unsigned long cumulated_sz; + unsigned int score, max_score = 0; - damon_for_each_scheme(s, c) { - struct damos_quota *quota = &s->quota; - unsigned long cumulated_sz; - unsigned int score, max_score = 0; + if (!quota->ms && !quota->sz) + return; - if (!s->wmarks.activated) - continue; + /* New charge window starts */ + if (time_after_eq(jiffies, quota->charged_from + + msecs_to_jiffies(quota->reset_interval))) { + if (quota->esz && quota->charged_sz >= quota->esz) + s->stat.qt_exceeds++; + quota->total_charged_sz += quota->charged_sz; + quota->charged_from = jiffies; + quota->charged_sz = 0; + damos_set_effective_quota(quota); + } - if (!quota->ms && !quota->sz) - continue; + if (!c->ops.get_scheme_score) + return; - /* New charge window starts */ - if (time_after_eq(jiffies, quota->charged_from + - msecs_to_jiffies( - quota->reset_interval))) { - if (quota->esz && quota->charged_sz >= quota->esz) - s->stat.qt_exceeds++; - quota->total_charged_sz += quota->charged_sz; - quota->charged_from = jiffies; - quota->charged_sz = 0; - damos_set_effective_quota(quota); + /* Fill up the score histogram */ + memset(quota->histogram, 0, sizeof(quota->histogram)); + damon_for_each_target(t, c) { + damon_for_each_region(r, t) { + if (!__damos_valid_target(r, s)) + continue; + score = c->ops.get_scheme_score(c, t, r, s); + quota->histogram[score] += damon_sz_region(r); + if (score > max_score) + max_score = score; } + } - if (!c->ops.get_scheme_score) - continue; + /* Set the min score limit */ + for (cumulated_sz = 0, score = max_score; ; score--) { + cumulated_sz += quota->histogram[score]; + if (cumulated_sz >= quota->esz || !score) + break; + } + quota->min_score = score; +} - /* Fill up the score histogram */ - memset(quota->histogram, 0, sizeof(quota->histogram)); - damon_for_each_target(t, c) { - damon_for_each_region(r, t) { - if (!__damos_valid_target(r, s)) - continue; - score = c->ops.get_scheme_score( - c, t, r, s); - quota->histogram[score] += damon_sz_region(r); - if (score > max_score) - max_score = score; - } - } +static void kdamond_apply_schemes(struct damon_ctx *c) +{ + struct damon_target *t; + struct damon_region *r, *next_r; + struct damos *s; - /* Set the min score limit */ - for (cumulated_sz = 0, score = max_score; ; score--) { - cumulated_sz += quota->histogram[score]; - if (cumulated_sz >= quota->esz || !score) - break; - } - quota->min_score = score; + damon_for_each_scheme(s, c) { + if (!s->wmarks.activated) + continue; + + damos_adjust_quota(c, s); } damon_for_each_target(t, c) { From patchwork Mon Oct 24 20:49:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018129 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 33F9FC38A2D for ; Mon, 24 Oct 2022 20:49:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD31D940010; Mon, 24 Oct 2022 16:49:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0D0994000F; Mon, 24 Oct 2022 16:49:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C1CE940010; Mon, 24 Oct 2022 16:49:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 68F4394000F for ; Mon, 24 Oct 2022 16:49:31 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 44C171205E6 for ; Mon, 24 Oct 2022 20:49:31 +0000 (UTC) X-FDA: 80057033742.01.9132F82 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf16.hostedemail.com (Postfix) with ESMTP id B2857180031 for ; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 39C83B81217; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94284C43470; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644568; bh=sv1BrnKGZiPaDlM88kZTZVyO+ljEIr4/QgXhQUY8YPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YDdPWy+hk/dA6bO1JvIxHQEsUadklBlUEuvRHSxp8TUizL8iK7lQE+1JK5yx3EiBJ DIY+QpAeB1tdtqIcxsIwmwDIWQjNvZ9nwue1mo4qgY/I5jWfHjH56yu7xsSaYmgGb4 PQiwORUnIyXxcyX7K9EGsZ5wIZaBqrDaXiTF4QTavo3eoUVdhk7sjt5c5jOTcvsTLC SMcKFOiF8eqBqt7LICtCoXlPK5r0ai0fjcWL/O+XsGrZI0Ytwmxk4HbEOAsDeeDQPt TRaZn2P/ZnGqu/bRmAxiTM+OvV6/f2fnCMfE6qG0nbrjgqs+H9ICKjlRuHQSNbYGwS 3I03m0XNVTL7w== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/11] mm/damon/sysfs: use damon_addr_range for regions' start and end values Date: Mon, 24 Oct 2022 20:49:13 +0000 Message-Id: <20221024204919.18524-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644571; 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:dkim-signature; bh=7n+YCXhSActcFsJQM+bMjwhqitqXcBT33KamBQXu4Hs=; b=Ca6j1VkXvK3Ygrt/9koRNkGRHBMI/MDb3fXP25T2eDpGC3qGbElSLvzvgaQVVQ62vXcSCO 75RHo2+jOXUuMVoVeDM/EA26HscKKVnmk2cvskk2JnReNg71eyYCL8Y6bOssLaqXaRnjfW bmIQZCpwLzTQiguKFQyK0ZMS/NURTug= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YDdPWy+h; spf=pass (imf16.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644571; a=rsa-sha256; cv=none; b=aB+5t/f2PFbL328Nn4iysRJeb9qYTanjIWfaxY/iUszpOUwyiku6UYmn5AiqHtS+/xCjxb 3Ojy/fKYXufdSImmbWSfYk6n+vHTALcGXo6VJn6DPXwWdPxprx++79hYcE+Eg8l6pxTUh0 HE7UJkIen1gI7nrEtf0urEPpUWiq2cM= Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YDdPWy+h; spf=pass (imf16.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: 74d1d6xc7jxicjcpz8xyeuumn6pxryfd X-Rspamd-Queue-Id: B2857180031 X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1666644570-720022 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: DAMON has a struct for each address range but DAMON sysfs interface is using the low type (unsigned long) for storing the start and end addresses of regions. Use the dedicated struct for better type safety. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 9f1219a67e3f..b9183063bfea 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1062,13 +1062,11 @@ static struct kobj_type damon_sysfs_schemes_ktype = { struct damon_sysfs_region { struct kobject kobj; - unsigned long start; - unsigned long end; + struct damon_addr_range ar; }; static struct damon_sysfs_region *damon_sysfs_region_alloc( - unsigned long start, - unsigned long end) + struct damon_addr_range ar) { struct damon_sysfs_region *region = kmalloc(sizeof(*region), GFP_KERNEL); @@ -1076,8 +1074,7 @@ static struct damon_sysfs_region *damon_sysfs_region_alloc( if (!region) return NULL; region->kobj = (struct kobject){}; - region->start = start; - region->end = end; + region->ar = ar; return region; } @@ -1087,7 +1084,7 @@ static ssize_t start_show(struct kobject *kobj, struct kobj_attribute *attr, struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - return sysfs_emit(buf, "%lu\n", region->start); + return sysfs_emit(buf, "%lu\n", region->ar.start); } static ssize_t start_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -1095,7 +1092,7 @@ static ssize_t start_store(struct kobject *kobj, struct kobj_attribute *attr, { struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - int err = kstrtoul(buf, 0, ®ion->start); + int err = kstrtoul(buf, 0, ®ion->ar.start); return err ? err : count; } @@ -1106,7 +1103,7 @@ static ssize_t end_show(struct kobject *kobj, struct kobj_attribute *attr, struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - return sysfs_emit(buf, "%lu\n", region->end); + return sysfs_emit(buf, "%lu\n", region->ar.end); } static ssize_t end_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -1114,7 +1111,7 @@ static ssize_t end_store(struct kobject *kobj, struct kobj_attribute *attr, { struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - int err = kstrtoul(buf, 0, ®ion->end); + int err = kstrtoul(buf, 0, ®ion->ar.end); return err ? err : count; } @@ -1187,7 +1184,7 @@ static int damon_sysfs_regions_add_dirs(struct damon_sysfs_regions *regions, regions->regions_arr = regions_arr; for (i = 0; i < nr_regions; i++) { - region = damon_sysfs_region_alloc(0, 0); + region = damon_sysfs_region_alloc((struct damon_addr_range){}); if (!region) { damon_sysfs_regions_rm_dirs(regions); return -ENOMEM; @@ -2147,11 +2144,11 @@ static int damon_sysfs_set_regions(struct damon_target *t, struct damon_sysfs_region *sys_region = sysfs_regions->regions_arr[i]; - if (sys_region->start > sys_region->end) + if (sys_region->ar.start > sys_region->ar.end) goto out; - ranges[i].start = sys_region->start; - ranges[i].end = sys_region->end; + ranges[i].start = sys_region->ar.start; + ranges[i].end = sys_region->ar.end; if (i == 0) continue; if (ranges[i - 1].end > ranges[i].start) From patchwork Mon Oct 24 20:49:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018127 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 F2009C67871 for ; Mon, 24 Oct 2022 20:49:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C60294000E; Mon, 24 Oct 2022 16:49:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7262694000D; Mon, 24 Oct 2022 16:49:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F10C94000E; Mon, 24 Oct 2022 16:49:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 27DA994000D for ; Mon, 24 Oct 2022 16:49:30 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0AC4C40A3E for ; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) X-FDA: 80057033700.11.58ECF7D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id A08CB8000D for ; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AD582615B3; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C5A2C433D6; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644568; bh=ujSci3Jr9yWO8XdHXzr/zi1RpAlYDD3yaad0xsGDwtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G0PNJwF7F8B6wDCT8U5OvUuUzVBgp8YQ/xYp56NtYF3J+apq8tV363lbDS/dAVE9x fmE1KhGzme+66U40xnPxhCiGER08YnmCVpFOOoXzMNwJdsHg9XkhE0h2IglBKku8Qk 0R3GZqSNZtFaMKpOjz9jv3aamgzvzty7b1BBMqBiUTBM5Z3QCKDU2LJ1lVnuJfzih4 YiMPbVNMnUXZTngRymS02lmsG8cD41erv/DtQA2mKokmw5y+4FXwKDV4hBH/tUKLJY 2YNKfkUPrm/R4hseLEskL/AinkQdMCyRdNeV3Gza0l5JxjrTscQ6MhU4BaaSFDNiXW zkY/9xpZ6LDRg== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/11] mm/damon/sysfs: remove parameters of damon_sysfs_region_alloc() Date: Mon, 24 Oct 2022 20:49:14 +0000 Message-Id: <20221024204919.18524-7-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644569; 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:dkim-signature; bh=03ly8U/KAwHOuI8XWF1KHkMMfsjMuz58ZNQJDMju10o=; b=O75pEQGk0JOVJmWAMYonSx0CmHGegWbJQMNOZ4qUwuSm8dy3gYdWQJauFGw5ZKELIT0Wp+ XMl/8qZD8kPOIjoD11Di6cwLCkuHVaKxcZj+gS3IAitaHldlASx8+Fx99uDk2bfheeRCdF q4ME+ilUj4NjhUSM0UHPympur27yf2E= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G0PNJwF7; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644569; a=rsa-sha256; cv=none; b=1KcQDF+yzKf39dRSEKCqG2HHrBVU5qChlIVHN7iEkB+yotXUBSgCRBF7YMyb2G+yAV/nPu NXPf8vL9C1c55aO61WGlwlC/HioBSeAIcUE6cgWphoQciHFkRm64g1+ItlFSb/Abb7nb/y VpxKirNXVebvmi/ZneUg1kCkVeyNr+g= X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A08CB8000D X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G0PNJwF7; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Stat-Signature: 3n9arpooip4wbukc699xqycf4pmsb76m X-HE-Tag: 1666644569-14120 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: 'damon_sysfs_region_alloc()' is always called with zero-filled 'struct damon_addr_range', because the start and end addresses should set by users. Remove unnecessary parameters of the function and simplify the body by using 'kzalloc()'. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index b9183063bfea..e8bd7367d15b 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1065,17 +1065,9 @@ struct damon_sysfs_region { struct damon_addr_range ar; }; -static struct damon_sysfs_region *damon_sysfs_region_alloc( - struct damon_addr_range ar) +static struct damon_sysfs_region *damon_sysfs_region_alloc(void) { - struct damon_sysfs_region *region = kmalloc(sizeof(*region), - GFP_KERNEL); - - if (!region) - return NULL; - region->kobj = (struct kobject){}; - region->ar = ar; - return region; + return kzalloc(sizeof(struct damon_sysfs_region), GFP_KERNEL); } static ssize_t start_show(struct kobject *kobj, struct kobj_attribute *attr, @@ -1184,7 +1176,7 @@ static int damon_sysfs_regions_add_dirs(struct damon_sysfs_regions *regions, regions->regions_arr = regions_arr; for (i = 0; i < nr_regions; i++) { - region = damon_sysfs_region_alloc((struct damon_addr_range){}); + region = damon_sysfs_region_alloc(); if (!region) { damon_sysfs_regions_rm_dirs(regions); return -ENOMEM; From patchwork Mon Oct 24 20:49:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018128 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 20AD4FA373F for ; Mon, 24 Oct 2022 20:49:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0975F94000D; Mon, 24 Oct 2022 16:49:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEF3594000F; Mon, 24 Oct 2022 16:49:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC98594000D; Mon, 24 Oct 2022 16:49:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 858A794000F for ; Mon, 24 Oct 2022 16:49:30 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 61384AB2CB for ; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) X-FDA: 80057033700.07.3D1F6AC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id ECCB84000A for ; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 465B1615B8; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5339C433B5; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644569; bh=ToGxVn5DgkZtjVMi4IGaA+ZXlJgYyh7RCq47o6e6Bdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSzy9SJ0dwZ69SDES5dYIVzSTUayn4yv8SDwn3IaJf/ABaUHGdh4f4jGjqv8cVWzD Yk1PyK4+OE9EJR8TcwLDAy5+nqT82hdT9S+/vCMlHuorkE+Y1Ns7qRd/qBDpGujUDI F4m5W5o4vy96+Q5vmBGLGAfpXnhWVfm+0CJBW3T1cuvf+PqqJEkNTUlgTj+FqjObDN 2GXiHaGWExkIdPnsJMCeyD6rEWMdOzlwdbs7G3neaoWXRWxUe/1ysjGra8pf1JbCl5 aRs/0AOYQpQSLSZHjsnUo/UYIkO/S5rSW4D0ELTlfXd2xzLORWwAqUEbhLfm8/jbPQ tUx0sed/3Olqw== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: linux-kernel@vger.kernel.org, damon@lists.linux.dev, linux-mm@kvack.org Subject: [PATCH 07/11] mm/damon/sysfs: move sysfs_lock to common module Date: Mon, 24 Oct 2022 20:49:15 +0000 Message-Id: <20221024204919.18524-8-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HSzy9SJ0; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644570; a=rsa-sha256; cv=none; b=8Q3Pja/NCJAEHaq/Pxaedczn8p7rKgfxcGVyjssBf2C70L61uvLNKsOYmQGfYtj7Uzpsag B7+fC9WJe76gOI1X8NzLtE1dtM91v0f8dFSe1kzvIqImVrT2fqbRFw7FbdHyUQ9aV0ibzH Opu1glJH5nu5IE/c5Dd/s9xTk9FSp94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644570; 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:dkim-signature; bh=8gnVqw+0ufpRZWu3rYTVACNYbATkDeUVVJn8K0t45/I=; b=uaIJVflk3iSSkmu94MvnvDftLyXJKu4gXlMiLm1l3v9yjKhjTggSP30hM4weEfQfJ7NTQJ 2DyRPit4yGDLDZ0V3X8RmVelzAJ24tWYQiFnJXnMxK+9gPBQ1yHFfzzq8te5UCMeaxOyh6 PdYFi8KgK7wTignc/CQM2GqhE3WaHMA= X-Rspamd-Queue-Id: ECCB84000A Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HSzy9SJ0; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam02 X-Rspam-User: X-Stat-Signature: wmb169fmmon4u7husjhmssyz8skuszxs X-HE-Tag: 1666644569-198276 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: DAMON sysfs interface is implemented in a single file, sysfs.c, which has about 2,800 lines of code. As the interface is hierarchical and some of the code can be reused by different hierarchies, it would make more sense to split out the implementation into common parts and different parts in multiple files. As the beginning of the work, create files for common code and move the global mutex for directories modifications protection into the new file. Signed-off-by: SeongJae Park --- mm/damon/Makefile | 2 +- mm/damon/sysfs-common.c | 11 +++++++++++ mm/damon/sysfs-common.h | 11 +++++++++++ mm/damon/sysfs.c | 4 +--- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 mm/damon/sysfs-common.c create mode 100644 mm/damon/sysfs-common.h diff --git a/mm/damon/Makefile b/mm/damon/Makefile index 3e6b8ad73858..f8d535a6253b 100644 --- a/mm/damon/Makefile +++ b/mm/damon/Makefile @@ -3,7 +3,7 @@ obj-y := core.o obj-$(CONFIG_DAMON_VADDR) += ops-common.o vaddr.o obj-$(CONFIG_DAMON_PADDR) += ops-common.o paddr.o -obj-$(CONFIG_DAMON_SYSFS) += sysfs.o +obj-$(CONFIG_DAMON_SYSFS) += sysfs-common.o sysfs.o obj-$(CONFIG_DAMON_DBGFS) += dbgfs.o obj-$(CONFIG_DAMON_RECLAIM) += reclaim.o obj-$(CONFIG_DAMON_LRU_SORT) += lru_sort.o diff --git a/mm/damon/sysfs-common.c b/mm/damon/sysfs-common.c new file mode 100644 index 000000000000..9dc743868d5b --- /dev/null +++ b/mm/damon/sysfs-common.c @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Common Primitives for DAMON Sysfs Interface + * + * Author: SeongJae Park + */ + +#include "sysfs-common.h" + +DEFINE_MUTEX(damon_sysfs_lock); + diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h new file mode 100644 index 000000000000..745a918b94f5 --- /dev/null +++ b/mm/damon/sysfs-common.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Common Primitives for DAMON Sysfs Interface + * + * Author: SeongJae Park + */ + +#include +#include + +extern struct mutex damon_sysfs_lock; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index e8bd7367d15b..0f3f06d8dae7 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -5,13 +5,11 @@ * Copyright (c) 2022 SeongJae Park */ -#include -#include #include #include #include -static DEFINE_MUTEX(damon_sysfs_lock); +#include "sysfs-common.h" /* * unsigned long range directory From patchwork Mon Oct 24 20:49:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018131 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 49165C38A2D for ; Mon, 24 Oct 2022 20:49:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57CDD940012; Mon, 24 Oct 2022 16:49:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4402A940013; Mon, 24 Oct 2022 16:49:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F729940012; Mon, 24 Oct 2022 16:49:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 05CBB94000F for ; Mon, 24 Oct 2022 16:49:33 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D47911C64F8 for ; Mon, 24 Oct 2022 20:49:32 +0000 (UTC) X-FDA: 80057033784.19.7177493 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf07.hostedemail.com (Postfix) with ESMTP id 4F3C440019 for ; Mon, 24 Oct 2022 20:49:32 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0FA82B81250; Mon, 24 Oct 2022 20:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E0F5C433C1; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644569; bh=zkSKxd+aFM4wLLzA3DhfvQt2mZE0FdxT9KFkAovv2q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G6WZBASYLD6LklC/+lqeZoDfG3dGQIzRLumccHTMO4T7Q5mINGCI4MIgGb2B0XqhT 1NFEYa+1n12cb74Dg3VHsDmrhWsQPW2QOb8aIS/NQ9qxx+vLNRqeyDN2xi75Omjov1 oToMe521lNjikNFXIh0rt82zJXngxjovF3SSWwZDJ8UzVuc8yIBdlOt8tgk3BiVeB9 ZCt2PNnfHBZqzAxrxHxb2bIa7JRuZA4O8gVk3m4FyTSyi7rH0uLhiLIu/+aN4igQlr Orb4Ju7MGgTATAU84n36nZY4tv4zqMrn8Rs76A+rg7UpvX7X2Wq2vKi93zy0khlsY+ 1m7BXfV5hTJzA== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/11] mm/damon/sysfs: move unsigned long range directory to common module Date: Mon, 24 Oct 2022 20:49:16 +0000 Message-Id: <20221024204919.18524-9-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644572; a=rsa-sha256; cv=none; b=czXXcobDPS/FizdqkTgWlULoPdrv8RHyCOR4pjPz0sgm9jtKL3yanCKPhRT1fa6YplE+z7 G2m1IMt1JqE5VRuP7RlAYKQQgHEQ+IfU4jstGYd7iT/SbtO655YAJ10BANfwsUxMmGUWrI eYWFP7hRO4iEnxmkyfeDQBJCpqSFltI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G6WZBASY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644572; 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:dkim-signature; bh=Bpp+mgs6T3vQx9VGv8u094mKTae+w/hydalOkPe08bM=; b=p6IYc5xpRt+xTJYwgRIRJt+bxWeXXroA/KP7WVIsvB7SIWDTlrv34Sgbtm4NCHjcajC607 jytcdQOqEbs6ndrOYZh3NTkshwyUlml7P9M3Ss6OgwZC04v8yhQ5LRD0uypwR5h12bgxEe klG/atMY/3xz/gH+v0l1F67mBxhKFq8= X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G6WZBASY; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspamd-Server: rspam11 X-Stat-Signature: xb7hn1mw3p5h49c5beeoicabqu3ja69z X-Rspamd-Queue-Id: 4F3C440019 X-HE-Tag: 1666644572-887062 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: The implementation of unsigned long type range directories can be reused by multiple DAMON sysfs directories including those for DAMON-based Operation Schemes and the range of number of monitoring regions. Move the code into the files for DAMON sysfs common logics. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.c | 96 ++++++++++++++++++++++++++++++++++++++ mm/damon/sysfs-common.h | 13 ++++++ mm/damon/sysfs.c | 100 ---------------------------------------- 3 files changed, 109 insertions(+), 100 deletions(-) diff --git a/mm/damon/sysfs-common.c b/mm/damon/sysfs-common.c index 9dc743868d5b..52bebf242f74 100644 --- a/mm/damon/sysfs-common.c +++ b/mm/damon/sysfs-common.c @@ -5,7 +5,103 @@ * Author: SeongJae Park */ +#include + #include "sysfs-common.h" DEFINE_MUTEX(damon_sysfs_lock); +/* + * unsigned long range directory + */ + +struct damon_sysfs_ul_range *damon_sysfs_ul_range_alloc( + unsigned long min, + unsigned long max) +{ + struct damon_sysfs_ul_range *range = kmalloc(sizeof(*range), + GFP_KERNEL); + + if (!range) + return NULL; + range->kobj = (struct kobject){}; + range->min = min; + range->max = max; + + return range; +} + +static ssize_t min_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_ul_range *range = container_of(kobj, + struct damon_sysfs_ul_range, kobj); + + return sysfs_emit(buf, "%lu\n", range->min); +} + +static ssize_t min_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct damon_sysfs_ul_range *range = container_of(kobj, + struct damon_sysfs_ul_range, kobj); + unsigned long min; + int err; + + err = kstrtoul(buf, 0, &min); + if (err) + return err; + + range->min = min; + return count; +} + +static ssize_t max_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_ul_range *range = container_of(kobj, + struct damon_sysfs_ul_range, kobj); + + return sysfs_emit(buf, "%lu\n", range->max); +} + +static ssize_t max_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct damon_sysfs_ul_range *range = container_of(kobj, + struct damon_sysfs_ul_range, kobj); + unsigned long max; + int err; + + err = kstrtoul(buf, 0, &max); + if (err) + return err; + + range->max = max; + return count; +} + +void damon_sysfs_ul_range_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damon_sysfs_ul_range, kobj)); +} + +static struct kobj_attribute damon_sysfs_ul_range_min_attr = + __ATTR_RW_MODE(min, 0600); + +static struct kobj_attribute damon_sysfs_ul_range_max_attr = + __ATTR_RW_MODE(max, 0600); + +static struct attribute *damon_sysfs_ul_range_attrs[] = { + &damon_sysfs_ul_range_min_attr.attr, + &damon_sysfs_ul_range_max_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_ul_range); + +struct kobj_type damon_sysfs_ul_range_ktype = { + .release = damon_sysfs_ul_range_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_ul_range_groups, +}; + diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 745a918b94f5..56e6a99e353b 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -9,3 +9,16 @@ #include extern struct mutex damon_sysfs_lock; + +struct damon_sysfs_ul_range { + struct kobject kobj; + unsigned long min; + unsigned long max; +}; + +struct damon_sysfs_ul_range *damon_sysfs_ul_range_alloc( + unsigned long min, + unsigned long max); +void damon_sysfs_ul_range_release(struct kobject *kobj); + +extern struct kobj_type damon_sysfs_ul_range_ktype; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 0f3f06d8dae7..129743292e17 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -11,106 +11,6 @@ #include "sysfs-common.h" -/* - * unsigned long range directory - */ - -struct damon_sysfs_ul_range { - struct kobject kobj; - unsigned long min; - unsigned long max; -}; - -static struct damon_sysfs_ul_range *damon_sysfs_ul_range_alloc( - unsigned long min, - unsigned long max) -{ - struct damon_sysfs_ul_range *range = kmalloc(sizeof(*range), - GFP_KERNEL); - - if (!range) - return NULL; - range->kobj = (struct kobject){}; - range->min = min; - range->max = max; - - return range; -} - -static ssize_t min_show(struct kobject *kobj, struct kobj_attribute *attr, - char *buf) -{ - struct damon_sysfs_ul_range *range = container_of(kobj, - struct damon_sysfs_ul_range, kobj); - - return sysfs_emit(buf, "%lu\n", range->min); -} - -static ssize_t min_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t count) -{ - struct damon_sysfs_ul_range *range = container_of(kobj, - struct damon_sysfs_ul_range, kobj); - unsigned long min; - int err; - - err = kstrtoul(buf, 0, &min); - if (err) - return err; - - range->min = min; - return count; -} - -static ssize_t max_show(struct kobject *kobj, struct kobj_attribute *attr, - char *buf) -{ - struct damon_sysfs_ul_range *range = container_of(kobj, - struct damon_sysfs_ul_range, kobj); - - return sysfs_emit(buf, "%lu\n", range->max); -} - -static ssize_t max_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t count) -{ - struct damon_sysfs_ul_range *range = container_of(kobj, - struct damon_sysfs_ul_range, kobj); - unsigned long max; - int err; - - err = kstrtoul(buf, 0, &max); - if (err) - return err; - - range->max = max; - return count; -} - -static void damon_sysfs_ul_range_release(struct kobject *kobj) -{ - kfree(container_of(kobj, struct damon_sysfs_ul_range, kobj)); -} - -static struct kobj_attribute damon_sysfs_ul_range_min_attr = - __ATTR_RW_MODE(min, 0600); - -static struct kobj_attribute damon_sysfs_ul_range_max_attr = - __ATTR_RW_MODE(max, 0600); - -static struct attribute *damon_sysfs_ul_range_attrs[] = { - &damon_sysfs_ul_range_min_attr.attr, - &damon_sysfs_ul_range_max_attr.attr, - NULL, -}; -ATTRIBUTE_GROUPS(damon_sysfs_ul_range); - -static struct kobj_type damon_sysfs_ul_range_ktype = { - .release = damon_sysfs_ul_range_release, - .sysfs_ops = &kobj_sysfs_ops, - .default_groups = damon_sysfs_ul_range_groups, -}; - /* * schemes/stats directory */ From patchwork Mon Oct 24 20:49:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018130 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 2CAF7FA3740 for ; Mon, 24 Oct 2022 20:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3327A940011; Mon, 24 Oct 2022 16:49:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2907694000F; Mon, 24 Oct 2022 16:49:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10B76940011; Mon, 24 Oct 2022 16:49:32 -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 E2DD294000F for ; Mon, 24 Oct 2022 16:49:31 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 777331A0BC7 for ; Mon, 24 Oct 2022 20:49:31 +0000 (UTC) X-FDA: 80057033742.27.21EBABE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 24D2440019 for ; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7AF4C615B8; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4913C4347C; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644570; bh=vYg+3rru4Qa0elGvOm6kAk7xSDdvfn1bfJkC8oPWZ2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQ1l016Hbl7kpxCKXRQ/Z3qblmevoS9Ww3RXT6D9e356Ljbw+lu0lL/Jhj5DbNpA/ BrtFYRBI8Tt9Xq5U6mi+Lt+Huq/Kuw7SELZlrHhN27rd5Pd03mWp131nTHhumzSqrc lq75y4ygY6OqQqqd24ZiW8gpiRBBjrvFjC80/9rWY7O35UT8k+OppQZ3CJyCkr8U+I lOuWldQy9QZrmPewVnpx1yqC71Lcp+bIFYAKNzjL6zjbVN1FrrZDBVDJa0CsfNl2s2 TVR0GDyYqdNPWVDPaOsnRdi9wspYXMFaeeq3vOyW0vGXLqbrbOQTTkDne78n0e7wST 8f1CP74FdBztQ== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/11] mm/damon/sysfs: split out kdamond-independent schemes stats update logic into a new function Date: Mon, 24 Oct 2022 20:49:17 +0000 Message-Id: <20221024204919.18524-10-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644571; a=rsa-sha256; cv=none; b=Z6KY8TwIPWS4Qhh82werdYmSgahprn372/WnfRTxEj0lRsGMyTmKPkqz3WhGKhDQdFTN2X YY3ckRk6oVgg+idruWPoHBl5Yl3SDtljIkgxIRDFUd8Xcvw1eZ27jK7r5p1Tbvv8XcSnAE O2QUYscqcYhaBH/uxtKbUtKOyNs+6iU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bQ1l016H; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644571; 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:dkim-signature; bh=teuLmkvrqYh7YfKqBTEJkBAA5R2vUCoFSJoNDkGPoso=; b=gJVG3aKUOFO8yacqxqfzFFRftF1O98Y+FolThAPK1dT6XRBHfXNH8xhy1Qhy4MuzgR3WgY p8ydyEQmyW04vHCv3WnG/mW4eGpfV7t7e6g8SY2eRiAyiujavE7OEB6G6TkN0yTCgXJOVG QgGy4+4v7vXUGSMLQxopJJFErnm1sHA= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 24D2440019 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bQ1l016H; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Stat-Signature: arsgn8461ed7oy6t5xwy46rnk4sk6w85 X-HE-Tag: 1666644570-912485 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: 'damon_sysfs_schemes_update_stats()' is coupled with both damon_sysfs_kdamond and damon_sysfs_schemes. It's a wide range of types dependency. It makes splitting the logics a little bit distracting. Split the function so that each function is coupled with smaller range of types. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 129743292e17..082c55e68e0e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2204,6 +2204,25 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) mutex_unlock(&ctx->kdamond_lock); } +static void damon_sysfs_schemes_update_stats( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + struct damos *scheme; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + struct damon_sysfs_stats *sysfs_stats; + + sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats; + sysfs_stats->nr_tried = scheme->stat.nr_tried; + sysfs_stats->sz_tried = scheme->stat.sz_tried; + sysfs_stats->nr_applied = scheme->stat.nr_applied; + sysfs_stats->sz_applied = scheme->stat.sz_applied; + sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds; + } +} + /* * damon_sysfs_upd_schemes_stats() - Update schemes stats sysfs files. * @kdamond: The kobject wrapper that associated to the kdamond thread. @@ -2216,23 +2235,11 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) { struct damon_ctx *ctx = kdamond->damon_ctx; - struct damon_sysfs_schemes *sysfs_schemes; - struct damos *scheme; - int schemes_idx = 0; if (!ctx) return -EINVAL; - sysfs_schemes = kdamond->contexts->contexts_arr[0]->schemes; - damon_for_each_scheme(scheme, ctx) { - struct damon_sysfs_stats *sysfs_stats; - - sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats; - sysfs_stats->nr_tried = scheme->stat.nr_tried; - sysfs_stats->sz_tried = scheme->stat.sz_tried; - sysfs_stats->nr_applied = scheme->stat.nr_applied; - sysfs_stats->sz_applied = scheme->stat.sz_applied; - sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds; - } + damon_sysfs_schemes_update_stats( + kdamond->contexts->contexts_arr[0]->schemes, ctx); return 0; } From patchwork Mon Oct 24 20:49:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018133 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 7F99FC38A2D for ; Mon, 24 Oct 2022 20:49:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0D0A940014; Mon, 24 Oct 2022 16:49:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 997DB940013; Mon, 24 Oct 2022 16:49:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C111940014; Mon, 24 Oct 2022 16:49:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4BB6D940013 for ; Mon, 24 Oct 2022 16:49:34 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1EFBA40C25 for ; Mon, 24 Oct 2022 20:49:34 +0000 (UTC) X-FDA: 80057033868.07.87938AF Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf09.hostedemail.com (Postfix) with ESMTP id 913D7140012 for ; Mon, 24 Oct 2022 20:49:33 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 24612B81257; Mon, 24 Oct 2022 20:49:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AE46C433D6; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644570; bh=EqlatpkaNdYuUEktVCI5+LntE+Uir1CgxHGN/I9sz6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gHf61vuVWHDO8jflm6XY+Xnsxloq4pNPWgLulXZi12E0FTxFwZ5mbV4f2/jbeowuj vMMni2x0nAF+ylHWMo951Se91nJtcwHhrMT3YpMI7XdcXaIlL11P8MUbyRaSTF1eNU 9AnOGD3NlNADWrh7eR54eB+1HcDJQqIVbFK/de/aiy2Y1hGFQ4kbQu/rbalsRQniwi zSYR0fidKYCo1ckoWcY3nqjqcswTLW71/GQj0bchQeVPQ4qsXA6+O5Njhv1aGc+peD O9/H5LUfUIpb3DGPKZsfBhDz36iSpEJ8SA8a+puS2/V5c67HD8pKyyTLVmpLNev0kr 9NKxolELy7w6A== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: linux-kernel@vger.kernel.org, damon@lists.linux.dev, linux-mm@kvack.org Subject: [PATCH 10/11] mm/damon/modules: deduplicate init steps for DAMON context setup Date: Mon, 24 Oct 2022 20:49:18 +0000 Message-Id: <20221024204919.18524-11-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644573; a=rsa-sha256; cv=none; b=lyKvXnLev2vp6wg/6niLuKrBXzRBm0TuoUC8jJOUo/x76xrAM8ZDYYUcufFQnDQMJ+/5bB V5Nc82ATPZfc8E5zIjvO3kUnfN21wevcFPkOZZLCPy+69fw29OLCbyH3B0P21VdCl0nQU4 G2JzHQB5BSR8iiYAOudF1odOp977RYQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gHf61vuV; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644573; 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:dkim-signature; bh=/psvwpgDunV61QtHA4+Z8aouaYxXpczLFew3kX5MTN0=; b=7CfSZKIxdMEupYHgQ/7KEUXXwZmzynD8WmKXhncKLV/Bh4iOt2+vVwvYUMGvYMq1+A7F/T lKUco/8ZN8+XMptOy8GXcgz6mqXTGYgG+5yX9RoCDFyCsfVhoCeqY6s6Kq66tHfaQmUkyP i/GvLlx6V7fUh0jid59eKvunKwhGseY= X-Stat-Signature: cqqrejtye9mj3m8k3fw9bsee3g718hp4 X-Rspamd-Queue-Id: 913D7140012 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gHf61vuV; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1666644573-438179 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: DAMON_RECLAIM and DAMON_LRU_SORT has duplicated code for DAMON context and target initializations. Deduplicate the part by implementing a function for the initialization in 'modules-common.c' and using it. Signed-off-by: SeongJae Park --- mm/damon/Makefile | 4 ++-- mm/damon/lru_sort.c | 17 +++------------- mm/damon/modules-common.c | 42 +++++++++++++++++++++++++++++++++++++++ mm/damon/modules-common.h | 3 +++ mm/damon/reclaim.c | 17 +++------------- 5 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 mm/damon/modules-common.c diff --git a/mm/damon/Makefile b/mm/damon/Makefile index f8d535a6253b..50d6b2ab3956 100644 --- a/mm/damon/Makefile +++ b/mm/damon/Makefile @@ -5,5 +5,5 @@ obj-$(CONFIG_DAMON_VADDR) += ops-common.o vaddr.o obj-$(CONFIG_DAMON_PADDR) += ops-common.o paddr.o obj-$(CONFIG_DAMON_SYSFS) += sysfs-common.o sysfs.o obj-$(CONFIG_DAMON_DBGFS) += dbgfs.o -obj-$(CONFIG_DAMON_RECLAIM) += reclaim.o -obj-$(CONFIG_DAMON_LRU_SORT) += lru_sort.o +obj-$(CONFIG_DAMON_RECLAIM) += modules-common.o reclaim.o +obj-$(CONFIG_DAMON_LRU_SORT) += modules-common.o lru_sort.o diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index efbc2bda8b9c..a1896c5acfe9 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -314,25 +314,14 @@ static int damon_lru_sort_after_wmarks_check(struct damon_ctx *c) static int __init damon_lru_sort_init(void) { - ctx = damon_new_ctx(); - if (!ctx) - return -ENOMEM; + int err = damon_modules_new_paddr_ctx_target(&ctx, &target); - if (damon_select_ops(ctx, DAMON_OPS_PADDR)) { - damon_destroy_ctx(ctx); - return -EINVAL; - } + if (err) + return err; ctx->callback.after_wmarks_check = damon_lru_sort_after_wmarks_check; ctx->callback.after_aggregation = damon_lru_sort_after_aggregation; - target = damon_new_target(); - if (!target) { - damon_destroy_ctx(ctx); - return -ENOMEM; - } - damon_add_target(ctx, target); - schedule_delayed_work(&damon_lru_sort_timer, 0); damon_lru_sort_initialized = true; diff --git a/mm/damon/modules-common.c b/mm/damon/modules-common.c new file mode 100644 index 000000000000..b2381a8466ec --- /dev/null +++ b/mm/damon/modules-common.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Common Primitives for DAMON Modules + * + * Author: SeongJae Park + */ + +#include + +#include "modules-common.h" + +/* + * Allocate, set, and return a DAMON context for the physical address space. + * @ctxp: Pointer to save the point to the newly created context + * @targetp: Pointer to save the point to the newly created target + */ +int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp, + struct damon_target **targetp) +{ + struct damon_ctx *ctx; + struct damon_target *target; + + ctx = damon_new_ctx(); + if (!ctx) + return -ENOMEM; + + if (damon_select_ops(ctx, DAMON_OPS_PADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target = damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + + *ctxp = ctx; + *targetp = target; + return 0; +} diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h index 5a4921851d32..f49cdb417005 100644 --- a/mm/damon/modules-common.h +++ b/mm/damon/modules-common.h @@ -44,3 +44,6 @@ 0400); \ module_param_named(nr_##qt_exceed_name, stat.qt_exceeds, ulong, \ 0400); + +int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp, + struct damon_target **targetp); diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 162c9b1ca00f..3173f373435c 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -256,25 +256,14 @@ static int damon_reclaim_after_wmarks_check(struct damon_ctx *c) static int __init damon_reclaim_init(void) { - ctx = damon_new_ctx(); - if (!ctx) - return -ENOMEM; + int err = damon_modules_new_paddr_ctx_target(&ctx, &target); - if (damon_select_ops(ctx, DAMON_OPS_PADDR)) { - damon_destroy_ctx(ctx); - return -EINVAL; - } + if (err) + return err; ctx->callback.after_wmarks_check = damon_reclaim_after_wmarks_check; ctx->callback.after_aggregation = damon_reclaim_after_aggregation; - target = damon_new_target(); - if (!target) { - damon_destroy_ctx(ctx); - return -ENOMEM; - } - damon_add_target(ctx, target); - schedule_delayed_work(&damon_reclaim_timer, 0); damon_reclaim_initialized = true; From patchwork Mon Oct 24 20:49:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018132 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 69DA5C67871 for ; Mon, 24 Oct 2022 20:49:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 998D994000F; Mon, 24 Oct 2022 16:49:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88A54940014; Mon, 24 Oct 2022 16:49:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5793494000F; Mon, 24 Oct 2022 16:49:33 -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 2057F94000F for ; Mon, 24 Oct 2022 16:49:33 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C7578C090A for ; Mon, 24 Oct 2022 20:49:32 +0000 (UTC) X-FDA: 80057033784.18.A81D959 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 6D65E4001A for ; Mon, 24 Oct 2022 20:49:32 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 96191615B8; Mon, 24 Oct 2022 20:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14B0FC433D7; Mon, 24 Oct 2022 20:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644571; bh=ed3OO6jR2hviy6STfWb58XYnzMUxxyGe+e0xErjg1fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J9cIXzhU9U1zWxdfPsC7S7cI+Ulc4SATnZVntGHQSe96wwChjQu3bcUIxth195MMp f4ukgLvBrlxZd/H8PRujs8KanGthShxmvvpLnHDKW1Lq299OzeaVMvog4X/ZgZdPDc gpM3BJ3Hn9RDw+azkUEHJHF155dHbvb5CGHOXw6Wpj2N2B1XvJx/RMFy6ILnUIFUIW PoUMZQoA9/tvPN6u7OKJusB50RP+v/mQIrqZw2hTUaX68Z3CYtid7Ykt9yjoi1Gflh D8BsHRcEsbV8Q8JtuFi3LFky/66KYi+CsQEkI+AyyL6UbExCY19nR679Fw2zEgoFJn 9ENAJnc8bWkRg== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/11] mm/damon/{reclaim,lru_sort}: remove unnecessarily included headers Date: Mon, 24 Oct 2022 20:49:19 +0000 Message-Id: <20221024204919.18524-12-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644572; a=rsa-sha256; cv=none; b=d8d4FwMVkWIFi6/2EXwJV+wOdyXxtrmumpbAoW5o3q07dIIEkHZyM6+GFcnPlaT0q3NHAE KVj6GDhZzGnOBiDxP7HC3Mb9EVApJ6Qdaf+RZNu1Qvvtey3PPPRug58MTjnPka7Z0hfCya xYFW8XB7ZSqsJjmpak7+kxoTSG0FXpc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=J9cIXzhU; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644572; 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:dkim-signature; bh=R4BxHqEmcuKW0c4tNNSt222xcKpiclvp60MW5YFbmHk=; b=NWMaz5prSiNEiPdDoC06D0oGkWLButyq8MdlOy8pqqNqLNEj3ZP1n2J2qyBe3tJ/R4uixn RdYyJBSVIxtzpHqsVHv8oxCGVSZxrCWQQo4AxCboGzLuAiciRS58Lx36r360KLVmSi3bKN XFe5bidIcEsLOK1YNXn8Djmvay+CR4o= X-Rspam-User: X-Rspamd-Queue-Id: 6D65E4001A Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=J9cIXzhU; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: w4oq9hwq1c7ktcokk81pbsxroqyphdan X-Rspamd-Server: rspam03 X-HE-Tag: 1666644572-256117 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: Some headers that 'recalim.c' and 'lru_sort.c' are including are unnecessary now owing to previous cleanups and refactorings. Remove those. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 2 -- mm/damon/reclaim.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index a1896c5acfe9..5c60163e556c 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -8,9 +8,7 @@ #define pr_fmt(fmt) "damon-lru-sort: " fmt #include -#include #include -#include #include #include "modules-common.h" diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 3173f373435c..e14eb30c01f4 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -8,9 +8,7 @@ #define pr_fmt(fmt) "damon-reclaim: " fmt #include -#include #include -#include #include #include "modules-common.h"