From patchwork Sat Sep 16 02:09:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 140884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1438496vqi; Fri, 15 Sep 2023 19:24:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeycm9e5EiMbz2dhLQDnJH4jnc/eqsZsbONUVo7v+64O/LHjmFVd7zEng8WyMA+00dcJ2A X-Received: by 2002:a05:6a20:3d1b:b0:153:8983:d87c with SMTP id y27-20020a056a203d1b00b001538983d87cmr9851645pzi.22.1694831067380; Fri, 15 Sep 2023 19:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694831067; cv=none; d=google.com; s=arc-20160816; b=EOL3jCU8utSVPGBkud8vZgE+ArSh7c9cSGKgfupA9qV9FaC30eTmgHHUPZSNmtOvPl gKYRcwBxptq03/NjTlkpybs3XGZOC0M1F0Yqe8ewLw83eDdUMuyfsN7U/qZY8h3pq9EF AnVHWe/vCJjoiPRPv1NtBxIm1L+7uv82sDnHKh+nRFFy8ojajqdEGcZWl2nTL6MlRns2 vYvTPZCmOCPztgNpVB8W3O6gUJpCxKTEt6D3Epq1NokzGi4fN0HSUpWrvIAZA8lFGiNY n5RPp5hE+SPJpkX1ErZDw7NYAwEYsRwyUcc9ELlcWYwn1F11ScENl8l0cx8pv7z4h8aj Qa8Q== 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=NUas3Av5c7Yuwe0Tw6b8l7+Jb4Jf4UY1Y9mRHVVQKto=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=Z68J76jHqa3Ect0JDGT8IAsg1kiLNvdHbXGf/DVS0BwAAR+TbXAGwYyRZWWC1Ylj5A M1Mk3xo47UA4hIqCtPao/xmZJH+Gx9Rib9ieRombxcQcxEtS9Uv0c2sG0z2KKA5VtVuH 5HbZq47vbt0efDqZwaTK9J6/Fy9GQwYEbs7Vjg7rcWaWprXzR4iUtuO+/CgTD2cxdX/F pho8q+wsDpa+WPZrCrchDPjbH9ZtSGaatNUS3eNWSDlQsjY2C/Xne1ZfYrUEmHCT7s9O m8nPygYZV9dTs1Z1d3JCxTIT70CsE+2AsJtIi27f4Qdv+wArbPOF8Idl6bVFGExzHAv9 Dzug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XUb0Za8b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x26-20020a63b21a000000b0056baff5c553si4134177pge.101.2023.09.15.19.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 19:24:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XUb0Za8b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DE0658270DED; Fri, 15 Sep 2023 19:11:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238409AbjIPCKZ (ORCPT + 27 others); Fri, 15 Sep 2023 22:10:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237683AbjIPCKL (ORCPT ); Fri, 15 Sep 2023 22:10:11 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84BC9173C for ; Fri, 15 Sep 2023 19:10:06 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8E34C433CB; Sat, 16 Sep 2023 02:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694830206; bh=CxNdbzA0gxD0qFOAF+9FaJdfdv1eofTN2A5LeDdD5oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XUb0Za8b5NIRMAAJKo0tr9S53C++iGSYlP/jV4+2zMzBqfI5andQM3B8DKRE56GBE JYVNEg6j5tUbTrcXRo4I1lkPLG42yvwG5xUWCn3ezU4XMMbz2mOMwtn8B6BlIZq/d4 ICfyBmkefS09qC8by3z7VGo0i/vBV1m92PDvsbYYIwkdYLNmCZt/tpLHa+pEUw1vte RUoB1p1dMYcv5w1MNew42XFfsi5Wj+8P1zNARMuVwKQcUxazpj71sjgncklfPPnxin hiFnZpeP0MrQ5VCdcqcs8Hz8fv0mc7IYZ0/BWUsmqotVbhAEPBu1U+6oDF5nxeh2GC 5OM5b/TUAD5og== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/9] mm/damon/sysfs-schemes: support DAMOS apply interval Date: Sat, 16 Sep 2023 02:09:42 +0000 Message-Id: <20230916020945.47296-7-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230916020945.47296-1-sj@kernel.org> References: <20230916020945.47296-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 15 Sep 2023 19:11:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777159181378054615 X-GMAIL-MSGID: 1777159181378054615 Update DAMON sysfs interface to support DAMOS apply intervals by adding a new file, 'apply_interval_us' in each scheme directory. Users can set and get the interval for each scheme in microseconds by writing to and reading from the file. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 3d30e85596b0..a7d70b95c4dd 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1121,6 +1121,7 @@ struct damon_sysfs_scheme { struct kobject kobj; enum damos_action action; struct damon_sysfs_access_pattern *access_pattern; + unsigned long apply_interval_us; struct damon_sysfs_quotas *quotas; struct damon_sysfs_watermarks *watermarks; struct damon_sysfs_scheme_filters *filters; @@ -1141,7 +1142,7 @@ static const char * const damon_sysfs_damos_action_strs[] = { }; static struct damon_sysfs_scheme *damon_sysfs_scheme_alloc( - enum damos_action action) + enum damos_action action, unsigned long apply_interval_us) { struct damon_sysfs_scheme *scheme = kmalloc(sizeof(*scheme), GFP_KERNEL); @@ -1150,6 +1151,7 @@ static struct damon_sysfs_scheme *damon_sysfs_scheme_alloc( return NULL; scheme->kobj = (struct kobject){}; scheme->action = action; + scheme->apply_interval_us = apply_interval_us; return scheme; } @@ -1353,6 +1355,25 @@ static ssize_t action_store(struct kobject *kobj, struct kobj_attribute *attr, return -EINVAL; } +static ssize_t apply_interval_us_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme *scheme = container_of(kobj, + struct damon_sysfs_scheme, kobj); + + return sysfs_emit(buf, "%lu\n", scheme->apply_interval_us); +} + +static ssize_t apply_interval_us_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_scheme *scheme = container_of(kobj, + struct damon_sysfs_scheme, kobj); + int err = kstrtoul(buf, 0, &scheme->apply_interval_us); + + return err ? err : count; +} + static void damon_sysfs_scheme_release(struct kobject *kobj) { kfree(container_of(kobj, struct damon_sysfs_scheme, kobj)); @@ -1361,8 +1382,12 @@ static void damon_sysfs_scheme_release(struct kobject *kobj) static struct kobj_attribute damon_sysfs_scheme_action_attr = __ATTR_RW_MODE(action, 0600); +static struct kobj_attribute damon_sysfs_scheme_apply_interval_us_attr = + __ATTR_RW_MODE(apply_interval_us, 0600); + static struct attribute *damon_sysfs_scheme_attrs[] = { &damon_sysfs_scheme_action_attr.attr, + &damon_sysfs_scheme_apply_interval_us_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_scheme); @@ -1413,7 +1438,11 @@ static int damon_sysfs_schemes_add_dirs(struct damon_sysfs_schemes *schemes, schemes->schemes_arr = schemes_arr; for (i = 0; i < nr_schemes; i++) { - scheme = damon_sysfs_scheme_alloc(DAMOS_STAT); + /* + * apply_interval_us as 0 means same to aggregation interval + * (same to before-apply_interval behavior) + */ + scheme = damon_sysfs_scheme_alloc(DAMOS_STAT, 0); if (!scheme) { damon_sysfs_schemes_rm_dirs(schemes); return -ENOMEM; @@ -1610,8 +1639,8 @@ static struct damos *damon_sysfs_mk_scheme( .low = sysfs_wmarks->low, }; - scheme = damon_new_scheme(&pattern, sysfs_scheme->action, 0, "a, - &wmarks); + scheme = damon_new_scheme(&pattern, sysfs_scheme->action, + sysfs_scheme->apply_interval_us, "a, &wmarks); if (!scheme) return NULL; @@ -1641,6 +1670,7 @@ static void damon_sysfs_update_scheme(struct damos *scheme, scheme->pattern.max_age_region = access_pattern->age->max; scheme->action = sysfs_scheme->action; + scheme->apply_interval_us = sysfs_scheme->apply_interval_us; scheme->quota.ms = sysfs_quotas->ms; scheme->quota.sz = sysfs_quotas->sz;