From patchwork Fri Jul 28 20:34:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 127861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp685613vqg; Fri, 28 Jul 2023 13:53:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFUZvUEdxKRimgAxQ2mW54wD3EXRUnhW7Jt+SrW8hN3AJyaYOtQ+/wm6l7auSgnhYcaEGXo X-Received: by 2002:a17:90a:b790:b0:267:f66a:f25f with SMTP id m16-20020a17090ab79000b00267f66af25fmr2743909pjr.11.1690577611479; Fri, 28 Jul 2023 13:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690577611; cv=none; d=google.com; s=arc-20160816; b=XZa8vkMXggAORBNpd1lvt5iT2XuMIpUA59Wpk1LNt2THAMGY2fi6i9bPdi4C0qbP8I rqLo65gNADlEsdf1WAtYSKnqXbKo4b7iDa07Wtc3SBHF3DbC7y5zwo+CtU/Z03/eLsLL 8KleiINSdBJWy6hTQ3pSXZTMf1DyQUuz97akUUwbTb1A44ngN1FeTL7330zxO+xn9bbb X2+EUH013oVSI1EotEGDIiHi5uvmzKAkgaPlFABUfAmADRSc47e3K1PTJEnpoOayKqCu S57bI9LQeDrldYtCWSm0WTOnU4zrfuwMMEBojL1/yUA9/3rFkncrVZLJTLfhxBr/zmPW +aVw== 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=/kPvdyaF0vEK5qYkstLmLzJYcBFMKcv9CmUtYtZboIA=; fh=8oGWbdHExGIIBBigm5y9/rZRjvqmeY+HpW+qV30w+go=; b=wnTS7bsiYHoDRMD3eZhsJc9UrRbzvvQjAzSjIfoB8ircAamRaq9d7OZH07CzMvcRLY sQE6Jo3mjVYVhiiQZL4aMgr2BXZ7oMLr7GGmMRsnlcd16ICDRO8KUMix5SioxeuaNV6s lsgWXvcm1qUmA2JDLiE0F1sJMLVtiLC4BGvvAoSdfOa1fkG4pml8+HAMYOEaTPfm5cBZ nLREIoFZMYhySx/2Jm0y7boTDrzUNjqj4QgTKjSahPSY3AJbJulwf1dlNy9ENyMlKobV 2vP8Ve66xpkDo5aHiCuyC6+GBtQ8Wb0tuqkpHoc4GBqwiO5nrX9GIz3lJf+YxZWlSBOz 3S4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T8PVYgKS; 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 ot6-20020a17090b3b4600b002630cae4f47si5292276pjb.66.2023.07.28.13.53.17; Fri, 28 Jul 2023 13:53:31 -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=T8PVYgKS; 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 S234889AbjG1Uf1 (ORCPT + 99 others); Fri, 28 Jul 2023 16:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234217AbjG1UfD (ORCPT ); Fri, 28 Jul 2023 16:35:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C754497 for ; Fri, 28 Jul 2023 13:34:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 39E78621FF for ; Fri, 28 Jul 2023 20:34:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44EADC433C8; Fri, 28 Jul 2023 20:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690576494; bh=Z5TufRLeeFt1IBETpXgGonzkgtF37kqef1//j1myid4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T8PVYgKS6PhpVB48g8KXiKO4k/4GohZSRliIWj6R8O15K5G2kmG3fnkO0dbOgFkhl /UIHcmpSyJadZWQStltOcf4TGAZaLSowi0asMBRi5Z25HoZhta724/fvsHSQ8I11dY m0D2LjqwzdyKx4hl4XteU2v1tlgB8ElHctrSEsXcU7G5B6pCvO3pYtQe09rd02zLfr x5+D+Qc8R/BZ+Kms/T9KuXAgCUV1tqJo1KVQDt+oxGtbopKr6djuCFIfNOdrhkt9m3 oCcs97pGo1x5w4rXqcln4QseMgiqsejzcN5BQNS9bsf387Cz+oFRuJyfs37iSJb33t eF9hu+cVBOMxw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 09/13] mm/damon/sysfs-schemes: support target damos filter Date: Fri, 28 Jul 2023 20:34:40 +0000 Message-Id: <20230728203444.70703-10-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728203444.70703-1-sj@kernel.org> References: <20230728203444.70703-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1772699109322285167 X-GMAIL-MSGID: 1772699109322285167 Extend DAMON sysfs interface to support the DAMON monitoring target based DAMOS filter. Users can use it via writing 'target' to the filter's 'type' file and specifying the index of the target from the corresponding DAMON context's monitoring targets list to 'target_idx' sysfs file. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 03ddba3e216d..527e7d17eb3b 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -283,6 +283,7 @@ struct damon_sysfs_scheme_filter { bool matching; char *memcg_path; struct damon_addr_range addr_range; + int target_idx; }; static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(void) @@ -295,6 +296,7 @@ static const char * const damon_sysfs_scheme_filter_type_strs[] = { "anon", "memcg", "addr", + "target", }; static ssize_t type_show(struct kobject *kobj, @@ -413,6 +415,25 @@ static ssize_t addr_end_store(struct kobject *kobj, return err ? err : count; } +static ssize_t damon_target_idx_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme_filter *filter = container_of(kobj, + struct damon_sysfs_scheme_filter, kobj); + + return sysfs_emit(buf, "%d\n", filter->target_idx); +} + +static ssize_t damon_target_idx_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_scheme_filter *filter = container_of(kobj, + struct damon_sysfs_scheme_filter, kobj); + int err = kstrtoint(buf, 0, &filter->target_idx); + + return err ? err : count; +} + static void damon_sysfs_scheme_filter_release(struct kobject *kobj) { struct damon_sysfs_scheme_filter *filter = container_of(kobj, @@ -437,12 +458,16 @@ static struct kobj_attribute damon_sysfs_scheme_filter_addr_start_attr = static struct kobj_attribute damon_sysfs_scheme_filter_addr_end_attr = __ATTR_RW_MODE(addr_end, 0600); +static struct kobj_attribute damon_sysfs_scheme_filter_damon_target_idx_attr = + __ATTR_RW_MODE(damon_target_idx, 0600); + static struct attribute *damon_sysfs_scheme_filter_attrs[] = { &damon_sysfs_scheme_filter_type_attr.attr, &damon_sysfs_scheme_filter_matching_attr.attr, &damon_sysfs_scheme_filter_memcg_path_attr.attr, &damon_sysfs_scheme_filter_addr_start_attr.attr, &damon_sysfs_scheme_filter_addr_end_attr.attr, + &damon_sysfs_scheme_filter_damon_target_idx_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_scheme_filter); @@ -1539,6 +1564,8 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme, return -EINVAL; } filter->addr_range = sysfs_filter->addr_range; + } else if (filter->type == DAMOS_FILTER_TYPE_TARGET) { + filter->target_idx = sysfs_filter->target_idx; } damos_add_filter(scheme, filter);