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: 4374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp48714wrs; Tue, 18 Oct 2022 17:16:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7fRa2geGALgOYZEP9CFcJbp5nU1Vx7/lTOGyxMLTw21FZN+h+1ZphNQW8vbBXp57fxy0yY X-Received: by 2002:a17:906:5dac:b0:791:93de:c61d with SMTP id n12-20020a1709065dac00b0079193dec61dmr4386981ejv.751.1666138581907; Tue, 18 Oct 2022 17:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666138581; cv=none; d=google.com; s=arc-20160816; b=fsBNmI9mKz5e+IHYY83QGz7VWWRHgsC+BAEhTUOISyX7/ZUQOWg/1Akt4+68NNWJ9Q EAxOGmYVT0bB9JE3qmOtiG1UOH6R/5olvsMlwc9roziUTB/ljNAarQemHHNU+DpTh+r2 GxCHbanGWr2AE3zlID8b/kWUtIjsK5aBSD1cqqnNWiNjh7fcc+A8YCmmKY76rWNWe9K6 RKR/IWZefR8ulgHgie0IDtYXM/gfI1tJnOCp5id0O9kH0hvMFBisxv0PK1kr4a1jQvRO HWUZ1IhYw37chZ+Y8ti/nVzJjvTxyzoJAh8BS4UdHZzpf12nGNuSYQXm5z6kMlkwgR1c miog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7n+YCXhSActcFsJQM+bMjwhqitqXcBT33KamBQXu4Hs=; b=rQFLO1jlGSx7QiUI9j4YzEvTlUku2Q2QX9lM6oK6epGG9TxJJpXbZoMKAuxhc2HW6l zpQNi1419rG8rnU6iXIvw4dsb08y+obnhWWuDtwwfMxyiEr4f1+rDwRiJUVJmi9EMq1i TkWm2JvLSQszRfdXbsjyb7CQtBsm1Ht1gEi6Lr3gNCH2E8TLp3cUBf4D9ADG+dXrIWcA 8aYAHdqCPDjih1pWoVhTnSQXW9cpLH+COqVDqEi9UQvjGpOBlU+kxSf3E7aKYPVAPhVU JyZpH54nZA4jCLyn1Ycnxi3yKfD8CjgKrqba/O1n3kbx1/XFNMaoUqZxbH+f718cAdnx nneg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tvAFreK+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sz15-20020a1709078b0f00b007803449809esi9763501ejc.355.2022.10.18.17.15.33; Tue, 18 Oct 2022 17:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tvAFreK+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbiJSAOB (ORCPT + 99 others); Tue, 18 Oct 2022 20:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiJSANc (ORCPT ); Tue, 18 Oct 2022 20:13:32 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 086B3CF180 for ; Tue, 18 Oct 2022 17:13:30 -0700 (PDT) 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 sin.source.kernel.org (Postfix) with ESMTPS id 6F835CE1FCF for ; Wed, 19 Oct 2022 00:13:28 +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 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747072929433071266?= X-GMAIL-MSGID: =?utf-8?q?1747072929433071266?= 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)