From patchwork Fri Apr 29 16:06:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12832419 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 81A0DC433F5 for ; Fri, 29 Apr 2022 16:06:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D5696B0085; Fri, 29 Apr 2022 12:06:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5326C6B0087; Fri, 29 Apr 2022 12:06:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F6F76B0088; Fri, 29 Apr 2022 12:06:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 288B76B0085 for ; Fri, 29 Apr 2022 12:06:22 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E63FF2717C for ; Fri, 29 Apr 2022 16:06:21 +0000 (UTC) X-FDA: 79410393762.07.539041D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id D27A840060 for ; Fri, 29 Apr 2022 16:06:19 +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 A9A02622B3; Fri, 29 Apr 2022 16:06:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B39E6C385B2; Fri, 29 Apr 2022 16:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651248380; bh=5YMNTMsgfge8ubKXp7EhKpr2TL9m6guiVctUmtgprC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OJBRW49WESwGwEdpEAB5f/EIx6t8TTqQTTGFRq80FMowxFxMpMTuFpW3pdSo/Qh+3 gx1vbm1C9d8sh1hSOX7a9XDM7KACYx5c7lXTVc8pSCg/vGpKnRvlYs+7pMNhluTazQ QtQ7RgTdR4KHxzvD+GcRuSxFio72EL7GiTVwqv7DT1fv8WQqdLeJy1sg1v6452zR7f xhfqBWSwyhvZiSNfiNj0fIyj8XPG2+sQmR54VFU0cFztw1alugFZnQO0uz7RYQj+/J xYQRiS2iyfQijMDqkIL8qMhikKGiee8PWGjHG30yUh+xs9KfJXgyHpK9AYmm2XTV4H lDW22HdPZkt7w== From: sj@kernel.org To: akpm@linux-foundation.org Cc: linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 08/14] mm/damon/sysfs: reuse damon_set_regions() for regions setting Date: Fri, 29 Apr 2022 16:06:00 +0000 Message-Id: <20220429160606.127307-9-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429160606.127307-1-sj@kernel.org> References: <20220429160606.127307-1-sj@kernel.org> MIME-Version: 1.0 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OJBRW49W; spf=pass (imf27.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: rspam05 X-Rspamd-Queue-Id: D27A840060 X-Stat-Signature: 9j94hrz4wxn3ktj6wbstrsq7d6zarpcm X-HE-Tag: 1651248379-67580 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: From: SeongJae Park 'damon_set_regions()' is general enough so that it can also be used for only creating regions. This commit makes DAMON sysfs interface to reuse the function rather keeping two implementations for a same purpose. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 331647ab6396..0d6cb9b5bd5b 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2095,28 +2095,31 @@ static void damon_sysfs_destroy_targets(struct damon_ctx *ctx) static int damon_sysfs_set_regions(struct damon_target *t, struct damon_sysfs_regions *sysfs_regions) { - int i; + struct damon_addr_range *ranges = kmalloc_array(sysfs_regions->nr, + sizeof(*ranges), GFP_KERNEL | __GFP_NOWARN); + int i, err = -EINVAL; + if (!ranges) + return -ENOMEM; for (i = 0; i < sysfs_regions->nr; i++) { struct damon_sysfs_region *sys_region = sysfs_regions->regions_arr[i]; - struct damon_region *prev, *r; if (sys_region->start > sys_region->end) - return -EINVAL; - r = damon_new_region(sys_region->start, sys_region->end); - if (!r) - return -ENOMEM; - damon_add_region(r, t); - if (damon_nr_regions(t) > 1) { - prev = damon_prev_region(r); - if (prev->ar.end > r->ar.start) { - damon_destroy_region(r, t); - return -EINVAL; - } - } + goto out; + + ranges[i].start = sys_region->start; + ranges[i].end = sys_region->end; + if (i == 0) + continue; + if (ranges[i - 1].end > ranges[i].start) + goto out; } - return 0; + err = damon_set_regions(t, ranges, sysfs_regions->nr); +out: + kfree(ranges); + return err; + } static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,