From patchwork Tue Nov 1 22:03:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3233482wru; Tue, 1 Nov 2022 15:04:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7mBULSDp5itUmzvFoGcgTmaatS2kcdeO0MkSbvLGIFYu5sfri2rrXS+iar0JDo0YooNVxF X-Received: by 2002:a17:902:cccd:b0:187:733:35d1 with SMTP id z13-20020a170902cccd00b00187073335d1mr19713353ple.26.1667340241596; Tue, 01 Nov 2022 15:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340241; cv=none; d=google.com; s=arc-20160816; b=EnrujLgissCwSzSdyQKwSFnwouSqyeSROMBzELl75l9KLxiL2dOCJKK66v6XoToHjw Fw+sitZBNQPyleR2LDfFd5CqbH55YwyY0MXElGsDHmY5aSGiRnJxy32dVGW/PFrxBUjH HCTuRivbHryvtQ4zuiLHkAUnrigKyXZzN19HGFKgmAYQsBkkwWja28AvTXVm0cZqzaDx 3yqMenhxev+nFTX2KYHJWB3JKOcA0Z3874SjQ+T3VYhRhIY2p0UzxeTQ+fgk7c5334ws plpKOhVMKM/P2H49cw9FSnGyHyD6Ula3anXj3lwuprE3RcSswYdD/iHEJnkzgUe70l/j E+2Q== 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=O6KK2U5/3ncofYbeOs/tMg6vCGEKqqa6+Q4m/z1r/AY=; b=0SoNyg/AZH1LHQiVXBj5Rjgjd0Qyc5MO5gZowLdPsF9MG4RHIM44sL8H6fzMKJq5uP ruVw6sXV+AW6/wb/HRHT8tbeqz83kfy1db96kF7ZCVAipB2kohxBcOi61Ur9NE+OUaWd 4+LdWqPLxcejRnGAcrlAtRNufCJndBLO9vAdi2bQk26qx5LiGSv7jsUPTLnzaNPMLV1T X4cDnqbix1w+aS5Nm8evszoZQ0Uc4yIsXPgVyK6IkTBoy8UT+chRfGAnCNT789JaB5Kk 1wg8QEPuPHtrau7Upb+Z2E20NO5PJ/3kaWCKaPWN9l3VhAOz/eTdKnBcD6AyWx7U1C1T +bMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VRXQmr3m; 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 u10-20020a170902e80a00b00186a1c4e64dsi15785921plg.236.2022.11.01.15.03.47; Tue, 01 Nov 2022 15:04:01 -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=VRXQmr3m; 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 S231158AbiKAWDj (ORCPT + 99 others); Tue, 1 Nov 2022 18:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbiKAWDh (ORCPT ); Tue, 1 Nov 2022 18:03:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE2F617A for ; Tue, 1 Nov 2022 15:03:35 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 0215A61744 for ; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBCDEC433D7; Tue, 1 Nov 2022 22:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340214; bh=/1k1bBlsjxjo9k4yKNnny083mrtwv5FWU+9lM1PdzeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRXQmr3mV2mTLz+4+nYdZKAv6AO3TB8XVGLyNXGM0nSSgG5AbZTa1in/nOl8zUDsK BM92vEa7Ze75qXBbB4lvkORJhA+DhNlHnCwC2KBcRkSKqJNwEkmf5SJYpS+6QTK9Pf ypIr8YDbRCzZ77CmCjkUo8YvVKObinMT6rMhnU3ouu9wyFV6+3ALHP7cJpJZ6lXzaC pNkzIbhS9x51U7S/LPtmIwYfozv51FCau3jFvePiUbjPwIfofxT4tj3ggUwqD8qUNM 5w4BL/hXvdy5wFxZXHz/0Ile5zLQtAzu6woU5LPH2UNUyhdf2iEP35Ae/2Qm1EgU77 HhfKu3/Ino90w== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 2/8] mm/damon/sysfs-schemes: implement schemes/tried_regions directory Date: Tue, 1 Nov 2022 22:03:22 +0000 Message-Id: <20221101220328.95765-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 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?1748332961484293272?= X-GMAIL-MSGID: =?utf-8?q?1748332961484293272?= For efficient and simple query-like DAMON monitoring results readings and deep level investigations of DAMOS, DAMON kernel API (include/linux/damon.h) users can use 'before_damos_apply' DAMON callback. However, DAMON sysfs interface users don't have such option. Add a directory, namely 'tried_regions', under each scheme directory to use it as the interface for the purpose. Note that this commit is implementing only the directory but the data filling. After the data filling change is made, users will be able to signal DAMON to fill the directory with the regions that corresponding scheme has tried to be applied. By setting the access pattern of the scheme, users could do the efficient query-like monitoring. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 7ea4bcce90cb..f9714ac62565 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -9,6 +9,36 @@ #include "sysfs-common.h" +/* + * scheme regions directory + */ + +struct damon_sysfs_scheme_regions { + struct kobject kobj; +}; + +static struct damon_sysfs_scheme_regions * +damon_sysfs_scheme_regions_alloc(void) +{ + return kzalloc(sizeof(struct damon_sysfs_scheme_regions), GFP_KERNEL); +} + +static void damon_sysfs_scheme_regions_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damon_sysfs_scheme_regions, kobj)); +} + +static struct attribute *damon_sysfs_scheme_regions_attrs[] = { + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_regions); + +static struct kobj_type damon_sysfs_scheme_regions_ktype = { + .release = damon_sysfs_scheme_regions_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_regions_groups, +}; + /* * schemes/stats directory */ @@ -635,6 +665,7 @@ struct damon_sysfs_scheme { struct damon_sysfs_quotas *quotas; struct damon_sysfs_watermarks *watermarks; struct damon_sysfs_stats *stats; + struct damon_sysfs_scheme_regions *tried_regions; }; /* This should match with enum damos_action */ @@ -743,6 +774,25 @@ static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme) return err; } +static int damon_sysfs_scheme_set_tried_regions( + struct damon_sysfs_scheme *scheme) +{ + struct damon_sysfs_scheme_regions *tried_regions = + damon_sysfs_scheme_regions_alloc(); + int err; + + if (!tried_regions) + return -ENOMEM; + err = kobject_init_and_add(&tried_regions->kobj, + &damon_sysfs_scheme_regions_ktype, &scheme->kobj, + "tried_regions"); + if (err) + kobject_put(&tried_regions->kobj); + else + scheme->tried_regions = tried_regions; + return err; +} + static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) { int err; @@ -759,8 +809,14 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) err = damon_sysfs_scheme_set_stats(scheme); if (err) goto put_watermarks_quotas_access_pattern_out; + err = damon_sysfs_scheme_set_tried_regions(scheme); + if (err) + goto put_tried_regions_out; return 0; +put_tried_regions_out: + kobject_put(&scheme->tried_regions->kobj); + scheme->tried_regions = NULL; put_watermarks_quotas_access_pattern_out: kobject_put(&scheme->watermarks->kobj); scheme->watermarks = NULL; @@ -781,6 +837,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme) kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); kobject_put(&scheme->stats->kobj); + kobject_put(&scheme->tried_regions->kobj); } static ssize_t action_show(struct kobject *kobj, struct kobj_attribute *attr,