From patchwork Wed Oct 19 00:13:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13011219 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 1651CC4332F for ; Wed, 19 Oct 2022 00:13:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C1B56B007E; Tue, 18 Oct 2022 20:13:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94BE96B0080; Tue, 18 Oct 2022 20:13:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E3056B0082; Tue, 18 Oct 2022 20:13:28 -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 477756B0080 for ; Tue, 18 Oct 2022 20:13:28 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0BE20160941 for ; Wed, 19 Oct 2022 00:13:28 +0000 (UTC) X-FDA: 80035774896.16.B8FD4CB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 977E340013 for ; Wed, 19 Oct 2022 00:13: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 EF0736173E; Wed, 19 Oct 2022 00:13:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67827C43145; Wed, 19 Oct 2022 00:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666138406; bh=sv1BrnKGZiPaDlM88kZTZVyO+ljEIr4/QgXhQUY8YPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tvAFreK+G10C1pyh9YM4X+J+zD/uLMqY4tYwN0mSyUWHESy4P3X/Vwxnfz5cHvdhr 4Pz2aQH+0AechmySoEprq6PNta6sqsjpQTJMOqxZG1ANR4Hu19rvw6itBh+5duWnbT I4KG6RiTpn1VzVIlPqHOGUYp5z2+92LPn7E/6MuCpLfurMNOTTwTY8vvIJN6VaXABi rJxS9wzTzaE33yQfSiPmR+EcXjbVdVXJXXwfYFi5mdg9UiRJI2jo9SZVlE6Daim7rN Rdb2QOviLOwaCFY7hfkZbcgQHB6qTkbONVSGComw9kSIB9s26s+RyuPQdgQDhCc3Lv O8ipS/+9CrpCQ== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 07/18] mm/damon/sysfs: Use damon_addr_range for regions' start and end values Date: Wed, 19 Oct 2022 00:13:06 +0000 Message-Id: <20221019001317.104270-8-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019001317.104270-1-sj@kernel.org> References: <20221019001317.104270-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=1666138407; 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=Jx0D+29sqvJl3GCkp3PojUgpLB+QhkVQyYSMI/W3eEYw/qHgfBoSZ+qkdk9lXtxQQAutfe 9k0x7wZg591KMXNQpnHstEYDG9focJwd7TvoStOg2RvuvqfRy4eQwDwzjejwYdlLJSau4j +U8RVT1Mb8QFpGvYNMNxG+kyfcAz+3M= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tvAFreK+; 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=1666138407; a=rsa-sha256; cv=none; b=hsKjlbwzSsbtVbBWLB8kwkTbjxrFfeF/NkGDNuaYOLGAz4qlQ3GpS6383L+NkmaiWNNbza mVU73hqHaACaATEOuouWyd/Q7u4qTYk4nYUXBcmMjIY4tCS4NAOVAqAPWQWYHi4yxlq6Rz xLXp8zYDC9r03MSCY+9KXgGBkZI3CGY= X-Rspamd-Server: rspam12 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tvAFreK+; 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-Stat-Signature: zpf33rhtr6x1bgmsoq93it3ytxf9znhx X-Rspamd-Queue-Id: 977E340013 X-HE-Tag: 1666138407-148553 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)