From patchwork Thu Nov 24 21:21:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055363 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 8F102C43219 for ; Thu, 24 Nov 2022 21:21:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05E166B0072; Thu, 24 Nov 2022 16:21:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 00E1A6B0073; Thu, 24 Nov 2022 16:21:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF0736B0075; Thu, 24 Nov 2022 16:21:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CBE956B0072 for ; Thu, 24 Nov 2022 16:21:22 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 74C05140512 for ; Thu, 24 Nov 2022 21:21:22 +0000 (UTC) X-FDA: 80169606804.19.97A4056 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 0F926100002 for ; Thu, 24 Nov 2022 21:21:21 +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 218A962256; Thu, 24 Nov 2022 21:21:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DDB0C433B5; Thu, 24 Nov 2022 21:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324880; bh=YFde7Cg3Hj4Ke5ExGefyiTVasYPENA1m1IEZnM/nGhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gl6EnRqJBxFjy18Iah9VqcR0bmZ1Jn/wwqzkIsrbgqDx/IfCPgTt5d9a94tbDkXFD 60k1/8ZNp/Fkiw63+YfOHXZ7Xj55J6NotdbVC9PyEiWAsI1JwE25fT9AxNm1lekOr0 vEMatfZS+8MRHgx/BkTGNHINHRcbDf/sLiI9w3F0MXtYND2uDCttF/8KFLaVgbRufU tzFfvm9f8yrvTC1sB6FcSMkgjooYlbTwwh4imj/W+Dd348xuySRGnTvlSuU9f72346 Rn/16RrolIPWiQ6RK2b9fxuiskaDMxnknY9Fq32EfifYbqCFzJTCG2gFLevrp7IXai 6wlagUCiBncwQ== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 01/11] mm/damon/core: implement damos filter Date: Thu, 24 Nov 2022 21:21:04 +0000 Message-Id: <20221124212114.136863-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Gl6EnRqJ; spf=pass (imf05.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=1669324882; a=rsa-sha256; cv=none; b=WX+dy4aFUIIw+3gBOpeI/tmG3qRGPjF1Hh9BWspPaAr4wxpr04BVrs3h/yj4t8Uj8pUjW9 ZJMV2rQZYcxG1OcO6JNX1Xs+btaFhIWzlZQnve/saDc8B6jMa6MMA1dJ44GkTpHh8RdZKU C46nKg/lvJ8eHIJYcb1+0X83PCqgkg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324882; 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=ycWoaO12O+YJYB0m55qHF5XnIC0C+dmyP2sXBGT4O9k=; b=L98v2IV2tjeoxuMsLgHLFcNMU+9lBNGOQs3wsTKJd71aRsv3oCWLhR7hBRNUFLaYoqDuf7 9eMp5v+Mn7A9zaT15uYrYXyE75s6ZG6f0K5wZ/4vlU840VngqLxGDq6wOTUpbvpz1g88sX AY88+2CWuxzMZBt6Ir9km62Ox5G56wk= X-Stat-Signature: cyugjzwbco76f31na5bu6bbko8km5hfk X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0F926100002 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Gl6EnRqJ; spf=pass (imf05.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-Rspam-User: X-HE-Tag: 1669324881-490206 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: DAMOS let users do system operation in a data access pattern oriented way. The data access pattern, which is extracted by DAMON, is somewhat accurate more than what user space could know in many cases. However, in some situation, users could know something more than the kernel about the pattern or some special requirements for some types of memory or processes. For example, some users would have slow swap devices and knows latency-ciritical processes and therefore want to use DAMON-based proactive reclamation (DAMON_RECLAIM) for only non-anonymous pages of non-latency-critical processes. For such restriction, users could exclude the memory regions from the initial monitoring regions and use non-dynamic monitoring regions update monitoring operations set including fvaddr and paddr. They could also adjust the DAMOS target access pattern. For dynamically changing memory layout and access pattern, those would be not enough. To help the case, add an interface, namely DAMOS filters, which can be used to avoid the DAMOS actions be applied to specific types of memory, to DAMON kernel API (damon.h). At the moment, it supports filtering anonymous pages and/or specific memory cgroups in or out for each DAMOS scheme. Note that this commit adds only the interface to the DAMON kernel API. The impelmentation should be made in the monitoring operations sets, and following commits will add that. Signed-off-by: SeongJae Park --- include/linux/damon.h | 51 +++++++++++++++++++++++++++++++++++++++++++ mm/damon/core.c | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 35630634d790..42cea3bf7319 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -8,6 +8,7 @@ #ifndef _DAMON_H_ #define _DAMON_H_ +#include #include #include #include @@ -215,6 +216,39 @@ struct damos_stat { unsigned long qt_exceeds; }; +/** + * enum damos_filter_type - Type of memory for &struct damos_filter + * @DAMOS_FILTER_TYPE_ANON: Anonymous pages. + * @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages. + * @NR_DAMOS_FILTER_TYPES: Number of filter types. + */ +enum damos_filter_type { + DAMOS_FILTER_TYPE_ANON, + DAMOS_FILTER_TYPE_MEMCG, + NR_DAMOS_FILTER_TYPES, +}; + +/** + * struct damos_filter - DAMOS action target memory filter. + * @type: Type of the page. + * @matching: If the matching page should filtered out or in. + * @memcg_id: Memcg id of the question if @type is DAMOS_FILTER_MEMCG. + * @list: List head for siblings. + * + * Before applying the &damos->action to a memory region, DAMOS checks if each + * page of the region matches to this and avoid applying the action if so. + * Note that the check support is up to &struct damon_operations + * implementation. + */ +struct damos_filter { + enum damos_filter_type type; + bool matching; + union { + unsigned short memcg_id; + }; + struct list_head list; +}; + /** * struct damos_access_pattern - Target access pattern of the given scheme. * @min_sz_region: Minimum size of target regions. @@ -239,6 +273,7 @@ struct damos_access_pattern { * @action: &damo_action to be applied to the target regions. * @quota: Control the aggressiveness of this scheme. * @wmarks: Watermarks for automated (in)activation of this scheme. + * @filters: Additional set of &struct damos_filter for &action. * @stat: Statistics of this scheme. * @list: List head for siblings. * @@ -254,6 +289,10 @@ struct damos_access_pattern { * If all schemes that registered to a &struct damon_ctx are inactive, DAMON * stops monitoring and just repeatedly checks the watermarks. * + * Before applying the &action to a memory region, &struct damon_operations + * implementation could check pages of the region and skip &action to respect + * &filters + * * After applying the &action to each region, &stat_count and &stat_sz is * updated to reflect the number of regions and total size of regions that the * &action is applied. @@ -263,6 +302,7 @@ struct damos { enum damos_action action; struct damos_quota quota; struct damos_watermarks wmarks; + struct list_head filters; struct damos_stat stat; struct list_head list; }; @@ -516,6 +556,12 @@ static inline unsigned long damon_sz_region(struct damon_region *r) #define damon_for_each_scheme_safe(s, next, ctx) \ list_for_each_entry_safe(s, next, &(ctx)->schemes, list) +#define damos_for_each_filter(f, scheme) \ + list_for_each_entry(f, &(scheme)->filters, list) + +#define damos_for_each_filter_safe(f, next, scheme) \ + list_for_each_entry_safe(f, next, &(scheme)->filters, list) + #ifdef CONFIG_DAMON struct damon_region *damon_new_region(unsigned long start, unsigned long end); @@ -536,6 +582,11 @@ void damon_destroy_region(struct damon_region *r, struct damon_target *t); int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, unsigned int nr_ranges); +struct damos_filter *damos_new_filter(enum damos_filter_type type, + bool matching); +void damos_add_filter(struct damos *s, struct damos_filter *f); +void damos_destroy_filter(struct damos_filter *f); + struct damos *damon_new_scheme(struct damos_access_pattern *pattern, enum damos_action action, struct damos_quota *quota, struct damos_watermarks *wmarks); diff --git a/mm/damon/core.c b/mm/damon/core.c index 9cbcc143179e..d924657ad622 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -273,6 +273,40 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, return 0; } +struct damos_filter *damos_new_filter(enum damos_filter_type type, + bool matching) +{ + struct damos_filter *filter; + + filter = kmalloc(sizeof(*filter), GFP_KERNEL); + if (!filter) + return NULL; + filter->type = type; + filter->matching = matching; + return filter; +} + +void damos_add_filter(struct damos *s, struct damos_filter *f) +{ + list_add_tail(&f->list, &s->filters); +} + +static void damos_del_filter(struct damos_filter *f) +{ + list_del(&f->list); +} + +static void damos_free_filter(struct damos_filter *f) +{ + kfree(f); +} + +void damos_destroy_filter(struct damos_filter *f) +{ + damos_del_filter(f); + damos_free_filter(f); +} + /* initialize private fields of damos_quota and return the pointer */ static struct damos_quota *damos_quota_init_priv(struct damos_quota *quota) { @@ -297,6 +331,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern, return NULL; scheme->pattern = *pattern; scheme->action = action; + INIT_LIST_HEAD(&scheme->filters); scheme->stat = (struct damos_stat){}; INIT_LIST_HEAD(&scheme->list); @@ -325,6 +360,10 @@ static void damon_free_scheme(struct damos *s) void damon_destroy_scheme(struct damos *s) { + struct damos_filter *f, *next; + + damos_for_each_filter_safe(f, next, s) + damos_destroy_filter(f); damon_del_scheme(s); damon_free_scheme(s); } From patchwork Thu Nov 24 21:21:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055366 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 EC0A8C43219 for ; Thu, 24 Nov 2022 21:21:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E8B66B007D; Thu, 24 Nov 2022 16:21:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F95D8E0001; Thu, 24 Nov 2022 16:21:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D54A36B007D; Thu, 24 Nov 2022 16:21:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C3D9A6B0078 for ; Thu, 24 Nov 2022 16:21:23 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8FF17801E8 for ; Thu, 24 Nov 2022 21:21:23 +0000 (UTC) X-FDA: 80169606846.18.78507CF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 2A3E22000B for ; Thu, 24 Nov 2022 21:21:21 +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 4FE9F6223E; Thu, 24 Nov 2022 21:21:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A8D9C43150; Thu, 24 Nov 2022 21:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324880; bh=A+37s6JJXYN+1C0NX4ExPJftU7PAKfFK4zc/BA9nVsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V+0V/UoqSADE6pcLDhZbExhGqrYT4Q8hixpFvbQBtIq6Bj3mpP154eBt+hH0yZnPF sjEbxqQrqRwRIAGFNSdF4WLlSyzdwuIfiCNRf4yZMh/lHgz3zIQh/9XsneDPEthf5x dHkbbR/KPwDkpjuocYYxSEVkwBwLfv6TZBXEENrrySTPlPLDMqWC86RwQ1qXzmyvSb 4ZNk6T1mi0uXuLtfXpfoCc7M0E2NDBlUeytO6oZdIMx0M00hcuq8ZGyiRkgFX08Gng x0PtTaFaHv13Y98mbnIPQgHenGd/LdGPchqBOBwTa0fqjP40QdhT19S5SAuPjIoRQs 1ovdbbxYfl+Ow== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 02/11] mm/damon/paddr: support DAMOS filters Date: Thu, 24 Nov 2022 21:21:05 +0000 Message-Id: <20221124212114.136863-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="V+0V/Uoq"; spf=pass (imf13.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=1669324882; a=rsa-sha256; cv=none; b=mYo7XmoZKvkPxGF9p+sHDIi0DU5Nfyv12B7YmCWu0ui3IY90mDv1L6/xyouDA4n0tEv4/F QL0mZEkxkp/k17t509ObEQhka5oyKEmNBVfuM6NSGFprW4wRNBfLlh5WyLBBRJg2I21hQL /7Cm4Tzvch2vCOpl+6T+za5wbBZv4+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324882; 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=CDD01R5AGR0VCKXOUvbXwSINuJd3g9aT00R1KPyCMrI=; b=1blcLOtVaAA0oQ5EkO+BKTFQ0NeqK1+f7XLTKerq6NVeJj4QzEYm/lTgNN3xNsSzSLY9mk vXUlX/fWJq1PRaASGuoSfe/uBpEZuczaTTWsbDgFs4Sg7LDR8IuULaxDqBpOI0UsFcmve6 injTO2R6RoOEbUC0WznxS77LTT4sheM= X-Stat-Signature: 98janwxj64u4n7kqk1tsuctejqynrs83 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2A3E22000B Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="V+0V/Uoq"; spf=pass (imf13.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-Rspam-User: X-HE-Tag: 1669324881-761328 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: Implement support of the DAMOS filters in the physical address space monitoring operations set, for all DAMOS actions that it supports including 'pageout', 'lru_prio', and 'lru_deprio'. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 71 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index e1a4315c4be6..ebd1905eed6f 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -202,7 +202,47 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) return max_nr_accesses; } -static unsigned long damon_pa_pageout(struct damon_region *r) +static bool __damos_pa_filter_out(struct damos_filter *filter, + struct page *page) +{ + bool matched = false; + struct mem_cgroup *memcg; + + switch (filter->type) { + case DAMOS_FILTER_TYPE_ANON: + matched = PageAnon(page); + break; + case DAMOS_FILTER_TYPE_MEMCG: + rcu_read_lock(); + memcg = page_memcg_check(page); + if (!memcg) + matched = false; + else + matched = filter->memcg_id == mem_cgroup_id(memcg); + rcu_read_unlock(); + break; + default: + break; + } + + return matched == filter->matching; +} + +/* + * damos_pa_filter_out - Return true if the page should be filtered out. + */ +static bool damos_pa_filter_out(struct damos *scheme, struct page *page) +{ + struct damos_filter *filter; + + damos_for_each_filter(filter, scheme) { + if (__damos_pa_filter_out(filter, page)) + return true; + } + return false; +} + +static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s) { unsigned long addr, applied; LIST_HEAD(page_list); @@ -213,6 +253,11 @@ static unsigned long damon_pa_pageout(struct damon_region *r) if (!page) continue; + if (damos_pa_filter_out(s, page)) { + put_page(page); + continue; + } + ClearPageReferenced(page); test_and_clear_page_young(page); if (isolate_lru_page(page)) { @@ -232,7 +277,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r) } static inline unsigned long damon_pa_mark_accessed_or_deactivate( - struct damon_region *r, bool mark_accessed) + struct damon_region *r, struct damos *s, bool mark_accessed) { unsigned long addr, applied = 0; @@ -241,6 +286,12 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( if (!page) continue; + + if (damos_pa_filter_out(s, page)) { + put_page(page); + continue; + } + if (mark_accessed) mark_page_accessed(page); else @@ -251,14 +302,16 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( return applied * PAGE_SIZE; } -static unsigned long damon_pa_mark_accessed(struct damon_region *r) +static unsigned long damon_pa_mark_accessed(struct damon_region *r, + struct damos *s) { - return damon_pa_mark_accessed_or_deactivate(r, true); + return damon_pa_mark_accessed_or_deactivate(r, s, true); } -static unsigned long damon_pa_deactivate_pages(struct damon_region *r) +static unsigned long damon_pa_deactivate_pages(struct damon_region *r, + struct damos *s) { - return damon_pa_mark_accessed_or_deactivate(r, false); + return damon_pa_mark_accessed_or_deactivate(r, s, false); } static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx, @@ -267,11 +320,11 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx, { switch (scheme->action) { case DAMOS_PAGEOUT: - return damon_pa_pageout(r); + return damon_pa_pageout(r, scheme); case DAMOS_LRU_PRIO: - return damon_pa_mark_accessed(r); + return damon_pa_mark_accessed(r, scheme); case DAMOS_LRU_DEPRIO: - return damon_pa_deactivate_pages(r); + return damon_pa_deactivate_pages(r, scheme); case DAMOS_STAT: break; default: From patchwork Thu Nov 24 21:21: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: 13055364 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 98EC4C352A1 for ; Thu, 24 Nov 2022 21:21:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C6AD6B0075; Thu, 24 Nov 2022 16:21:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6766B6B0073; Thu, 24 Nov 2022 16:21:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 516D36B007B; Thu, 24 Nov 2022 16:21:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 39F096B0073 for ; Thu, 24 Nov 2022 16:21:23 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 030EDC0960 for ; Thu, 24 Nov 2022 21:21:22 +0000 (UTC) X-FDA: 80169606846.13.749335F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 9EC8D4000A for ; Thu, 24 Nov 2022 21:21:22 +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 D9A166224C; Thu, 24 Nov 2022 21:21:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0906C43145; Thu, 24 Nov 2022 21:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324881; bh=grt8f69Dz6AwyetZSMeMbFhewde1iaVMzadAT1LoRZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Scsna3COmwE6eGQjmyTlyjMBdHtCfsQzO5q1w/q8qp13kHeVLM7pYbq/hp9VTIvZ8 oeAq5Z4EryN0E8hwqg7wWWL1yCKYXc6Sx7c5qQOgw8qPvFUd0fYn2CR/0gb0nqE996 uv6/Ohyk8hja+94/N/7kXEdJVPkHFh8L4SNkSOG3vMKzBz+hGjxp33tPXRzvIiS37R hsAQFUCu1bE5lUpUt2KOZDM7wOX9x5xe5YvKgnVXWyiErEdkblKhL3siXJ1330TFuy JFhOYoDstdrsx5xYZTQhVJcTuPUxrNfXrJ8qjRnXPyEaXem/Rt6kFQiL66Bp/7ybkJ BJndOwSLhj+0g== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 03/11] mm/damon/reclaim: add a parameter called skip_anon for avoiding anonymous pages reclamation Date: Thu, 24 Nov 2022 21:21:06 +0000 Message-Id: <20221124212114.136863-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Scsna3CO; spf=pass (imf07.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=1669324882; a=rsa-sha256; cv=none; b=VsXEgDVtTiLHzx+T/olFFDHFDO99pFutbhmIl+xSzdpkhzyrnwZFqMCCUoNuPcMoO+eGG1 I2puJaSiWbtJ7KBOPU9XX5+49+i+zZL0Y2zdhJw8UkJc83l2ZFvGFLfanCEBCKkvi9xkUL w4UO1cG4ChAqn9j31DaKLN4ftl1Ei00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324882; 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=r3xyNreIJtEHO9foiiQtvJVmPt1q36n0JQLVr8U6gzI=; b=XzwLDXp2ygnL4XIkajDbR9CNeki74oPt7AWhikPgnqBcS8k0VmjJu2duUm9ONj8NSZvil+ mTs6Jhzbc9CUt10cui9FvvYeAd0bcqETjIBXlZSFRKPG+35m59lFXHsZBlvZv5LUGnCmFo XdahLgHF76dY0OZ5XPoCLS58f5GusBA= X-Stat-Signature: q7ad317e48fmfafbybowa5tkpx8b7pmz X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9EC8D4000A Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Scsna3CO; spf=pass (imf07.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-Rspam-User: X-HE-Tag: 1669324882-857666 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: In some cases, for example if users have confidence at anonymous pages management or the swap device is too slow, users would want to avoid DAMON_RECLAIM swapping the anonymous pages out. For such case, add yet another DAMON_RECLAIM parameter, namely 'skip_anon'. When it is set as 'Y', DAMON_RECLAIM will avoid reclaiming anonymous pages using a DAMOS filter. Signed-off-by: SeongJae Park --- mm/damon/reclaim.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index e82631f39481..648d2a85523a 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -98,6 +98,15 @@ module_param(monitor_region_start, ulong, 0600); static unsigned long monitor_region_end __read_mostly; module_param(monitor_region_end, ulong, 0600); +/* + * Skip anonymous pages reclamation. + * + * If this parameter is set as ``Y``, DAMON_RECLAIM does not reclaim anonymous + * pages. By default, ``N``. + */ +static bool skip_anon __read_mostly; +module_param(skip_anon, bool, 0600); + /* * PID of the DAMON thread * @@ -142,6 +151,7 @@ static struct damos *damon_reclaim_new_scheme(void) static int damon_reclaim_apply_parameters(void) { struct damos *scheme; + struct damos_filter *filter; int err = 0; err = damon_set_attrs(ctx, &damon_reclaim_mon_attrs); @@ -152,6 +162,15 @@ static int damon_reclaim_apply_parameters(void) scheme = damon_reclaim_new_scheme(); if (!scheme) return -ENOMEM; + if (skip_anon) { + filter = damos_new_filter(DAMOS_FILTER_TYPE_ANON, true); + if (!filter) { + /* Will be freed by next 'damon_set_schemes()' below */ + damon_destroy_scheme(scheme); + return -ENOMEM; + } + damos_add_filter(scheme, filter); + } damon_set_schemes(ctx, &scheme, 1); return damon_set_region_biggest_system_ram_default(target, From patchwork Thu Nov 24 21:21:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055365 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 BDBEAC47088 for ; Thu, 24 Nov 2022 21:21:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 960196B0073; Thu, 24 Nov 2022 16:21:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A6AD6B007B; Thu, 24 Nov 2022 16:21:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 629786B007D; Thu, 24 Nov 2022 16:21:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 47E806B0078 for ; Thu, 24 Nov 2022 16:21:23 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1C1F11604B1 for ; Thu, 24 Nov 2022 21:21:23 +0000 (UTC) X-FDA: 80169606846.15.C144121 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id BB2571C000A for ; Thu, 24 Nov 2022 21:21:22 +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 130C162257; Thu, 24 Nov 2022 21:21:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67664C433D7; Thu, 24 Nov 2022 21:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324881; bh=ew0j918CPCZ3BCkCfl4ilV0ZC0sdlaLXkkNEQyNFiwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJmT6SE5SJA1ZiuoIDKQK7YvF+WpstqdQXLA2OAwmGzcllHfgqeMqHBQmw3fIDzBh 6/4db/iEOf/VXaVubqIXasXS+XfUwUpC4hIG+yryfKETPVmo/SatiMQHssPRl9LxF2 HHd3aXxHc66tRm4Hs6ZmhQOYs/W4WRl81HNoyDx1kjhPKt9XkO4VkR0oxIeARx/ZWT p2w5sT7EmdFs/6tgNZtVwDDM4WtHoRa1vgujGujBRqBqfAZPEbQYUczoRmlOng9tL9 sU3WWusdLWjBWHoAb2N8MZqjiUK1cv71Jw3MesaBo1Rvo7NslMPD8xh+SrC+xjOStS u3xZsD3pP/T2g== From: SeongJae Park To: Andrew Morton Cc: Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 04/11] Docs/admin-guide/damon/reclaim: document 'skip_anon' parameter Date: Thu, 24 Nov 2022 21:21:07 +0000 Message-Id: <20221124212114.136863-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SJmT6SE5; spf=pass (imf20.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=1669324882; a=rsa-sha256; cv=none; b=gs/yU2UALqYhXGwKsIk2TJ6wwwO7/6JP6D8cfQwoU1e14EZIE9B/h9V5kHSun61ctpEUrI 4yztjRhM9+HwEdg7virruS3k9GhK+/NhIm7MOEM+/TCFOdwiPZV2mDg3rbba762Isew+/U O3g9IjvHfpRtAhaNmoV5W+w480xDe0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324882; 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=vvd7VIY3E2fb0b6B1lCyCZF6kEVIsBEC2F3qsYkpFaU=; b=fyEgKxH1dm27Xv9vvR1jbqu4BMWXXG7FVs52ZJyXOxHrit34KnaLQzYGxIXoMUL4qYhKIn gfLaLmemNToqQp5k5pChUpCoH1XiZsyQl4XszhT8WI4eRxy5X435u2f9GOP9KnWDZ0MQr2 BGoeEevkaayjvLK3AVNQsypgrdYt9Qs= X-Stat-Signature: wfbxunb5x6wcmb33e7kb4itu5tnpcdmp X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: BB2571C000A Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SJmT6SE5; spf=pass (imf20.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-Rspam-User: X-HE-Tag: 1669324882-926505 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: Document the newly added 'skip_anon' parameter of DAMON_RECLAIM, which can be used to avoid anonymous pages reclamation. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/reclaim.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/reclaim.rst b/Documentation/admin-guide/mm/damon/reclaim.rst index 4f1479a11e63..ff335e96e0d8 100644 --- a/Documentation/admin-guide/mm/damon/reclaim.rst +++ b/Documentation/admin-guide/mm/damon/reclaim.rst @@ -205,6 +205,15 @@ The end physical address of memory region that DAMON_RECLAIM will do work against. That is, DAMON_RECLAIM will find cold memory regions in this region and reclaims. By default, biggest System RAM is used as the region. +skip_anon +--------- + +Skip anonymous pages reclamation. + +If this parameter is set as ``Y``, DAMON_RECLAIM does not reclaim anonymous +pages. By default, ``N``. + + kdamond_pid ----------- From patchwork Thu Nov 24 21:21:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055367 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 20107C4321E for ; Thu, 24 Nov 2022 21:21:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F4318E0001; Thu, 24 Nov 2022 16:21:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E4816B007B; Thu, 24 Nov 2022 16:21:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 084ED8E0002; Thu, 24 Nov 2022 16:21:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E8A988E0001 for ; Thu, 24 Nov 2022 16:21:23 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BE542160695 for ; Thu, 24 Nov 2022 21:21:23 +0000 (UTC) X-FDA: 80169606846.11.930DD59 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 6D0C1A000B for ; Thu, 24 Nov 2022 21:21:23 +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 A9D6F62256; Thu, 24 Nov 2022 21:21:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A5F4C433B5; Thu, 24 Nov 2022 21:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324882; bh=MpYV+KbY79xvzeBIqlzmkGgEI6XBAJRwIre/bGlDx34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gOP7mlJJ1syTxKt2NTsf2/24L2YQ0ugKEYWXxekaidGUfYGZ+gvped+wtAf+53BKq L+UME89oAQahjiiRDswc5tjnB2H0rC/zztQs8uDen2UBJ75NpS7HhjV+YQIXbxR384 xrzV2R+Dg9JXGJ6nAsNOI2qRhJyjJn2INs9Q2pyeQdfGv4kgDBOClvTBzZ7rFTxSSX 5lChmz2X1Ft2ZJMk9226sx3OwkzeEXR3zBF8/iXM+vxZKD5J3Z8Msv4yHm01+SwbXd tRzYy+c9Y07Ivu4S+yMs/LQZ0lOm3unvJyLI3BGh8TK1wR//ToSx7L2xIST0UISdKb jhC4xJ1d1T16g== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 05/11] mm/damon/sysfs-schemes: implement filters directory Date: Thu, 24 Nov 2022 21:21:08 +0000 Message-Id: <20221124212114.136863-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669324883; a=rsa-sha256; cv=none; b=J0jSWWchmqNCiqW0aFx79v6b9xCMO/N/+yRdiOPkwlN4PzNF5iuhtOmG+ezWMgTH5OPuXV GrkdGZXB4BFPb5BBEiyDL+p4xSoJVpJeRGMiaMBj/3AyOjIFecaw0RHDnD3CQKhuw0NiTP ZQlaeJVvuxLjwllAwDW+iuAYidUzN2I= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gOP7mlJJ; spf=pass (imf15.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324883; 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=oAWeLdbec29o/pQUTk4KG0iaCmNJO1bxhOKX71KFHjw=; b=hJRr4Y5Q8+eSPrUSsb/Ft4XzZPYtPq3/hdDv95VrczErNCM8BtjBtbU3x+Pef8xSFNfx/7 Z2GN9OkPf2henw67z0vI67UEaYgwNOZ0eRdu32TUS2aHa9Te693DnVZuhZD5xkfWpftouI 8yyPb8BU69zekQNGAXPMe/RpD0WC9xE= X-Rspamd-Queue-Id: 6D0C1A000B X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gOP7mlJJ; spf=pass (imf15.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-Rspamd-Server: rspam07 X-Stat-Signature: b4b8kgtmb1egfsss58dhegcyoxoywp6c X-HE-Tag: 1669324883-358752 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: DAMOS filters is currently supported by only DAMON kernel API. To expose the feature to user space, implement a DAMON sysfs directory named 'filters' under each scheme directory. Please note that this is implementing only the directory. Following commits will implement more files and directories, and finally connect the DAMOS filters feature. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 85 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 81fc4d27f4e4..50c8148cb474 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -258,6 +258,63 @@ static struct kobj_type damon_sysfs_stats_ktype = { .default_groups = damon_sysfs_stats_groups, }; +/* + * filters directory + */ + +struct damon_sysfs_scheme_filters { + struct kobject kobj; + int nr; +}; + +static struct damon_sysfs_scheme_filters * +damon_sysfs_scheme_filters_alloc(void) +{ + return kzalloc(sizeof(struct damon_sysfs_scheme_filters), GFP_KERNEL); +} + +static ssize_t nr_filters_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme_filters *filters = container_of(kobj, + struct damon_sysfs_scheme_filters, kobj); + + return sysfs_emit(buf, "%d\n", filters->nr); +} + +static ssize_t nr_filters_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int nr, err = kstrtoint(buf, 0, &nr); + + if (err) + return err; + if (nr < 0) + return -EINVAL; + + return count; +} + +static void damon_sysfs_scheme_filters_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damon_sysfs_scheme_filters, kobj)); +} + +static struct kobj_attribute damon_sysfs_scheme_filters_nr_attr = + __ATTR_RW_MODE(nr_filters, 0600); + +static struct attribute *damon_sysfs_scheme_filters_attrs[] = { + &damon_sysfs_scheme_filters_nr_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_filters); + +static struct kobj_type damon_sysfs_scheme_filters_ktype = { + .release = damon_sysfs_scheme_filters_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_filters_groups, +}; + /* * watermarks directory */ @@ -784,6 +841,7 @@ struct damon_sysfs_scheme { struct damon_sysfs_access_pattern *access_pattern; struct damon_sysfs_quotas *quotas; struct damon_sysfs_watermarks *watermarks; + struct damon_sysfs_scheme_filters *filters; struct damon_sysfs_stats *stats; struct damon_sysfs_scheme_regions *tried_regions; }; @@ -878,6 +936,24 @@ static int damon_sysfs_scheme_set_watermarks(struct damon_sysfs_scheme *scheme) return err; } +static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme) +{ + struct damon_sysfs_scheme_filters *filters = + damon_sysfs_scheme_filters_alloc(); + int err; + + if (!filters) + return -ENOMEM; + err = kobject_init_and_add(&filters->kobj, + &damon_sysfs_scheme_filters_ktype, &scheme->kobj, + "filters"); + if (err) + kobject_put(&filters->kobj); + else + scheme->filters = filters; + return err; +} + static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme) { struct damon_sysfs_stats *stats = damon_sysfs_stats_alloc(); @@ -926,9 +1002,12 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) err = damon_sysfs_scheme_set_watermarks(scheme); if (err) goto put_quotas_access_pattern_out; - err = damon_sysfs_scheme_set_stats(scheme); + err = damon_sysfs_scheme_set_filters(scheme); if (err) goto put_watermarks_quotas_access_pattern_out; + err = damon_sysfs_scheme_set_stats(scheme); + if (err) + goto put_filters_watermarks_quotas_access_pattern_out; err = damon_sysfs_scheme_set_tried_regions(scheme); if (err) goto put_tried_regions_out; @@ -937,6 +1016,9 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) put_tried_regions_out: kobject_put(&scheme->tried_regions->kobj); scheme->tried_regions = NULL; +put_filters_watermarks_quotas_access_pattern_out: + kobject_put(&scheme->filters->kobj); + scheme->filters = NULL; put_watermarks_quotas_access_pattern_out: kobject_put(&scheme->watermarks->kobj); scheme->watermarks = NULL; @@ -956,6 +1038,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme) damon_sysfs_quotas_rm_dirs(scheme->quotas); kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); + kobject_put(&scheme->filters->kobj); kobject_put(&scheme->stats->kobj); damon_sysfs_scheme_regions_rm_dirs(scheme->tried_regions); kobject_put(&scheme->tried_regions->kobj); From patchwork Thu Nov 24 21:21:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055368 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 425ECC433FE for ; Thu, 24 Nov 2022 21:21:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 827548E0003; Thu, 24 Nov 2022 16:21:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 714FD8E0002; Thu, 24 Nov 2022 16:21:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F1D98E0003; Thu, 24 Nov 2022 16:21:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3B5608E0002 for ; Thu, 24 Nov 2022 16:21:25 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 19206801E8 for ; Thu, 24 Nov 2022 21:21:25 +0000 (UTC) X-FDA: 80169606930.30.CCD78AA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 7835DC0010 for ; Thu, 24 Nov 2022 21:21:24 +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 AA4106224C; Thu, 24 Nov 2022 21:21:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0D3FC43470; Thu, 24 Nov 2022 21:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324883; bh=KP45fkenUtVNkuekA5wpVSKSKg+M620wUBu7fatA2gQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=th1NC/9CqYR8H+krzv8GHNUBGsnG0hc0TrRpwJhni8NgC0Vtes22K4XcwXezWUksM LyjzdE4nUad+0bke+j02ePQEA8zAwN6Cac8orFTOTNMPBQWCxnhMib0zzA56qqlpei xpaxnY7lqe5wC9KZmKu9u3TiElifD1r3StC2Q9CivX1XLW1r/sOJn6vHuzQbHW4Fgg 9Zl6sMngKWBZ6CBfrCrZuAobXtcmZJQklEnbtHFgcdldIGHDlNbRYYnQmbnTKnW4Nv eKwQgm4YSS08f/5slcVfre8qaNKKsm+WbfgQtJ3ccj2QZ23y0v6SjLY3z1SQVHV/0v 575Ps2FI2RUMQ== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 06/11] mm/damon/sysfs-schemes: implement filter directory Date: Thu, 24 Nov 2022 21:21:09 +0000 Message-Id: <20221124212114.136863-7-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="th1NC/9C"; spf=pass (imf22.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=1669324884; a=rsa-sha256; cv=none; b=rgrTfjHNFbxpz4DLnvrBi1RFekpdIZyJ8NrOtmtLN79nRYBhyfDpkVo41bbVzZbtlgJjdy bXgVYg4BCBj0TpO/fOGkx5fY2elSSiFyZxL4zz852CnO9H8vHIXxfSxjReXB89x3HDMUxH PZgrd8reqwDLqqyq2DJGPHog4QdGfyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324884; 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=6SIrU+qHgmD/alHJaDLXicupWPCEB92hw5xZgg3ikzQ=; b=0LeGY0ZSPYhB7fE8VCpkumfjr3KGTuneriq67YyWomKV4ZzPhup5c9e4xMVWV38tIDWMcp wvPHlLNbsSqr+nx4ckCLpAHV+01fCLjpIklkd8ZnAN/RYJphtj/DfKNdBRLJ4tXWlhrCf8 JC0GdxoOuJeulm8JthKUbcO6EKXCZps= X-Stat-Signature: 9yowt1h91exb3uhser38txupk89q4ugf X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 7835DC0010 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="th1NC/9C"; spf=pass (imf22.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-Rspam-User: X-HE-Tag: 1669324884-424773 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: Implement DAMOS filter directory which will be located under the filters directory. The directory provides three files, namely type, matching, and memcg_path. 'type' and 'matching' will be directly connected to the fields of 'struct damos_filter' having same name. 'memcg_path' will receive the path of the memory cgroup of the interest and later converted to memcg id when it's committed. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 128 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 50c8148cb474..afbfc55a8e84 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -258,6 +258,134 @@ static struct kobj_type damon_sysfs_stats_ktype = { .default_groups = damon_sysfs_stats_groups, }; +/* + * filter directory + */ + +struct damon_sysfs_scheme_filter { + struct kobject kobj; + enum damos_filter_type type; + bool matching; + char *memcg_path; +}; + +/* Should match with enum damos_filter_type */ +static const char * const damon_sysfs_scheme_filter_type_strs[] = { + "anon", + "memcg", +}; + +static ssize_t type_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, "%s\n", + damon_sysfs_scheme_filter_type_strs[filter->type]); +} + +static ssize_t type_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); + enum damos_filter_type type; + ssize_t ret = -EINVAL; + + for (type = 0; type < NR_DAMOS_FILTER_TYPES; type++) { + if (sysfs_streq(buf, damon_sysfs_scheme_filter_type_strs[ + type])) { + filter->type = type; + ret = count; + break; + } + } + return ret; +} + +static ssize_t matching_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, "%c\n", filter->matching ? 'Y' : 'N'); +} + +static ssize_t matching_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); + bool matching; + int err = kstrtobool(buf, &matching); + + if (err) + return err; + + filter->matching = matching; + return count; +} + +static ssize_t memcg_path_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, "%s\n", + filter->memcg_path ? filter->memcg_path : ""); +} + +static ssize_t memcg_path_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); + char *path = kmalloc(sizeof(*path) * (count + 1), GFP_KERNEL); + + if (!path) + return -ENOMEM; + + strncpy(path, buf, count); + path[count] = '\0'; + filter->memcg_path = path; + return count; +} + +static void damon_sysfs_scheme_filter_release(struct kobject *kobj) +{ + struct damon_sysfs_scheme_filter *filter = container_of(kobj, + struct damon_sysfs_scheme_filter, kobj); + + kfree(filter->memcg_path); + kfree(filter); +} + +static struct kobj_attribute damon_sysfs_scheme_filter_type_attr = + __ATTR_RW_MODE(type, 0600); + +static struct kobj_attribute damon_sysfs_scheme_filter_matching_attr = + __ATTR_RW_MODE(matching, 0600); + +static struct kobj_attribute damon_sysfs_scheme_filter_memcg_path_attr = + __ATTR_RW_MODE(memcg_path, 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, + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_filter); + +static struct kobj_type damon_sysfs_scheme_filter_ktype = { + .release = damon_sysfs_scheme_filter_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_filter_groups, +}; + /* * filters directory */ From patchwork Thu Nov 24 21:21:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055372 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 5E8CAC43219 for ; Thu, 24 Nov 2022 21:21:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C74778E0009; Thu, 24 Nov 2022 16:21:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCF398E0006; Thu, 24 Nov 2022 16:21:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A48578E0009; Thu, 24 Nov 2022 16:21:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7688C8E0007 for ; Thu, 24 Nov 2022 16:21:27 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 579AE405E3 for ; Thu, 24 Nov 2022 21:21:27 +0000 (UTC) X-FDA: 80169607014.17.B2404BD Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf18.hostedemail.com (Postfix) with ESMTP id B5C4C1C000B for ; Thu, 24 Nov 2022 21:21:26 +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 ams.source.kernel.org (Postfix) with ESMTPS id E72B3B82903; Thu, 24 Nov 2022 21:21:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E820C43145; Thu, 24 Nov 2022 21:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324883; bh=P6PPKcChryRiegofLGkES15aSEw/aJpUh0oNfEpl4kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=csE2P2pP80gwh9YjLKh9Ih3bnqn66ojFLUM6VT7+M/2+HoETHDkdMQvfgZ4/Gv7Cm GlyAmfjL2tClgHeSpoe4KSS4bfabmWQT2PfRA7FHssoVA2bn8kLknicRPVPM7TIjoV u+LUNjonDlYIYHphKh0ajOWEP3mOO1Tb4rp+tTArrAVvpTdn0OcpLyYBtu/x6gLIP1 NyBgK0wZkffaQxDltOfBkSd5de+FejYYAI8rX2AnthkOftYfxjEyB29v2P+CJcpzW6 OlLHkaL55NjZ2NxLHXoPdeNtmCcZLrQzzes7yUeE7l0kUXs26fGQdibS4XlRabDgbD 1kyLxx7xuDKXg== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 07/11] mm/damon/sysfs-schemes: connect filter directory and filters directory Date: Thu, 24 Nov 2022 21:21:10 +0000 Message-Id: <20221124212114.136863-8-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-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=1669324887; 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=L5uR5rYrk5WBOSUkHBxBiSbuM/EK1gm61GzegfZyReM=; b=toupNmPhf5qXpNm4ZVoZR5H9Iv6dVkhv9+tamEwM6SctRQ7DVvXQSVp3hmqmsOCIzE9Zpw f8e8xDofwO5N1Zs6ZyI2h6/J8EmUKkWI07GJuCVSANutXArbkKdn2P+stabI6376ReOWJT Tdycd1yBkhf3V8Ztpa3LovHYywUXTI0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=csE2P2pP; spf=pass (imf18.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 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=1669324887; a=rsa-sha256; cv=none; b=2la9n0/8uICudgl1LgaaWuiHlw1ft4tNpn1kcISyz1/TEbChFMs25b652Fy8zPWaeiKrO/ RufKuWYHxU6LdwtFBEUN6t7HSVdSilKcd9cHlztXz0bH2F93lJSPNBv/OHHZgr0NN7u71w IdrM8i71duqNHxL/ne0B73qsi4gg0eg= X-Rspamd-Queue-Id: B5C4C1C000B Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=csE2P2pP; spf=pass (imf18.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 6wxsa5iz7c5urb3sqxqnwouppkssf7bx X-HE-Tag: 1669324886-652479 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: Implement 'nr_filters' file under 'filters' directory, which will be used to populate specific number of 'filter' directory under the directory, similar to other 'nr_*' files in DAMON sysfs interface. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index afbfc55a8e84..7f2bab617156 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -269,6 +269,11 @@ struct damon_sysfs_scheme_filter { char *memcg_path; }; +static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(void) +{ + return kzalloc(sizeof(struct damon_sysfs_scheme_filter), GFP_KERNEL); +} + /* Should match with enum damos_filter_type */ static const char * const damon_sysfs_scheme_filter_type_strs[] = { "anon", @@ -392,6 +397,7 @@ static struct kobj_type damon_sysfs_scheme_filter_ktype = { struct damon_sysfs_scheme_filters { struct kobject kobj; + struct damon_sysfs_scheme_filter **filters_arr; int nr; }; @@ -401,6 +407,57 @@ damon_sysfs_scheme_filters_alloc(void) return kzalloc(sizeof(struct damon_sysfs_scheme_filters), GFP_KERNEL); } +static void damon_sysfs_scheme_filters_rm_dirs( + struct damon_sysfs_scheme_filters *filters) +{ + struct damon_sysfs_scheme_filter **filters_arr = filters->filters_arr; + int i; + + for (i = 0; i < filters->nr; i++) + kobject_put(&filters_arr[i]->kobj); + filters->nr = 0; + kfree(filters_arr); + filters->filters_arr = NULL; +} + +static int damon_sysfs_scheme_filters_add_dirs( + struct damon_sysfs_scheme_filters *filters, int nr_filters) +{ + struct damon_sysfs_scheme_filter **filters_arr, *filter; + int err, i; + + damon_sysfs_scheme_filters_rm_dirs(filters); + if (!nr_filters) + return 0; + + filters_arr = kmalloc_array(nr_filters, sizeof(*filters_arr), + GFP_KERNEL | __GFP_NOWARN); + if (!filters_arr) + return -ENOMEM; + filters->filters_arr = filters_arr; + + for (i = 0; i < nr_filters; i++) { + filter = damon_sysfs_scheme_filter_alloc(); + if (!filter) { + damon_sysfs_scheme_filters_rm_dirs(filters); + return -ENOMEM; + } + + err = kobject_init_and_add(&filter->kobj, + &damon_sysfs_scheme_filter_ktype, + &filters->kobj, "%d", i); + if (err) { + kobject_put(&filter->kobj); + damon_sysfs_scheme_filters_rm_dirs(filters); + return err; + } + + filters_arr[i] = filter; + filters->nr++; + } + return 0; +} + static ssize_t nr_filters_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -413,6 +470,7 @@ static ssize_t nr_filters_show(struct kobject *kobj, static ssize_t nr_filters_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { + struct damon_sysfs_scheme_filters *filters; int nr, err = kstrtoint(buf, 0, &nr); if (err) @@ -420,6 +478,15 @@ static ssize_t nr_filters_store(struct kobject *kobj, if (nr < 0) return -EINVAL; + filters = container_of(kobj, struct damon_sysfs_scheme_filters, kobj); + + if (!mutex_trylock(&damon_sysfs_lock)) + return -EBUSY; + err = damon_sysfs_scheme_filters_add_dirs(filters, nr); + mutex_unlock(&damon_sysfs_lock); + if (err) + return err; + return count; } From patchwork Thu Nov 24 21:21:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055369 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 4EE3DC46467 for ; Thu, 24 Nov 2022 21:21:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5BDF8E0005; Thu, 24 Nov 2022 16:21:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0A608E0002; Thu, 24 Nov 2022 16:21:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9864B8E0005; Thu, 24 Nov 2022 16:21:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8785C8E0002 for ; Thu, 24 Nov 2022 16:21:26 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6575AA0552 for ; Thu, 24 Nov 2022 21:21:26 +0000 (UTC) X-FDA: 80169606972.17.3273700 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 0991540011 for ; Thu, 24 Nov 2022 21:21:25 +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 4295662258; Thu, 24 Nov 2022 21:21:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD92CC43147; Thu, 24 Nov 2022 21:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324884; bh=FrCQktxb/IHIkJr0quKPsuPjXDJwuo+SRuylRA+I1fM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRxL/q2g8NWpSQCutGPjfq4P2N/YBsWxmeL5Gok4EK2itrLtEnIQ24rhpi0GZzI2t FALEHRm3hMVoWYKWgI6T4Og4yKjy+KOh3oY1U3PFY4FGn6QUWwWVLwVW274l7eEn5w +utRorYUkFfkos6yTaO+uuKYX0gHxaYGdpRyX69kb3eMo51IKZW3ro8TBplYwathq7 Og8dIjZUI1YThNcJaBo9oyPITPqoo6MIADODcXVzRqwEL3iq04Agg2Msai9wMvIFbc 3jnNWAwmB8o4d0jzMIQwnIDjKtshiR7qvil6B+Ng13wZnj++p4uCBytRZp38XpgKGE ieAYUaSeE6fJw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 08/11] mm/damon/sysfs-schemes: implement scheme filters Date: Thu, 24 Nov 2022 21:21:11 +0000 Message-Id: <20221124212114.136863-9-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669324886; a=rsa-sha256; cv=none; b=rEZBw/8hPlwXjLIe4IEzPDC33GXwO4z2Ef9GDi53XAflmDMBHC1SoHi9+cZcfFi7m3yAhc BI9LWSqhEOA4ksCODeevsQDBrBR4XNwfl5KtyJjk4k/nbutpqI+VCiYT7M+8wr3InAOZsr ySTQHJkhuRHB88o+AvsLFV5byS7IcXc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="HRxL/q2g"; spf=pass (imf27.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324886; 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=xPgizVh5v6TH4m1AiatgBsOnpDW0fqlTlenfaMEirS8=; b=ZyCRPOOAKfo30pqBLxTtD+10lT5o0rhBnjBV2ROZJArUUx0wyt9oVO9dkZCdojS7cBNo1r SRTLYV44eqNiRVcHu4+K7aRiY6zBBdgy5OoHE/2S3uctz1JQyrCTi7NJwpjwdag7zYAdmA 0+VvaXFGm5j/Lcqqa+cZRffUPFrqqQU= X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="HRxL/q2g"; spf=pass (imf27.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: enrjtmdwswf36i7i5yjbhyy76uo5go9q X-Rspamd-Queue-Id: 0991540011 X-Rspamd-Server: rspam12 X-HE-Tag: 1669324885-743227 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: Implement scheme filters functionality of DAMON sysfs interface by making the code reads the values of files under the filter directories and pass that to DAMON using DAMON kernel API. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 85 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 7f2bab617156..6f014b328e6f 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1402,6 +1402,71 @@ struct kobj_type damon_sysfs_schemes_ktype = { .default_groups = damon_sysfs_schemes_groups, }; +static bool damon_sysfs_memcg_path_eq(struct mem_cgroup *memcg, + char *memcg_path_buf, char *path) +{ +#ifdef CONFIG_CGROUPS + cgroup_path(memcg->css.cgroup, memcg_path_buf, PATH_MAX); + if (sysfs_streq(memcg_path_buf, path)) + return true; +#endif + return false; +} + +static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id) +{ + struct mem_cgroup *memcg; + char *path; + + if (!memcg_path) + return -EINVAL; + + path = kmalloc(sizeof(*path) * PATH_MAX, GFP_KERNEL); + if (!path) + return -ENOMEM; + + for (memcg = mem_cgroup_iter(NULL, NULL, NULL); memcg; + memcg = mem_cgroup_iter(NULL, memcg, NULL)) { + if (damon_sysfs_memcg_path_eq(memcg, path, memcg_path)) { + *id = mem_cgroup_id(memcg); + break; + } + } + + kfree(path); + return 0; +} + +static int damon_sysfs_set_scheme_filters(struct damos *scheme, + struct damon_sysfs_scheme_filters *sysfs_filters) +{ + int i; + struct damos_filter *filter, *next; + + damos_for_each_filter_safe(filter, next, scheme) + damos_destroy_filter(filter); + + for (i = 0; i < sysfs_filters->nr; i++) { + struct damon_sysfs_scheme_filter *sysfs_filter = + sysfs_filters->filters_arr[i]; + struct damos_filter *filter = + damos_new_filter(sysfs_filter->type, + sysfs_filter->matching); + int err; + + if (!filter) + return -ENOMEM; + if (filter->type == DAMOS_FILTER_TYPE_MEMCG) { + err = damon_sysfs_memcg_path_to_id( + sysfs_filter->memcg_path, + &filter->memcg_id); + if (err) + return err; + } + } + return 0; +} + static struct damos *damon_sysfs_mk_scheme( struct damon_sysfs_scheme *sysfs_scheme) { @@ -1410,6 +1475,10 @@ static struct damos *damon_sysfs_mk_scheme( struct damon_sysfs_quotas *sysfs_quotas = sysfs_scheme->quotas; struct damon_sysfs_weights *sysfs_weights = sysfs_quotas->weights; struct damon_sysfs_watermarks *sysfs_wmarks = sysfs_scheme->watermarks; + struct damon_sysfs_scheme_filters *sysfs_filters = + sysfs_scheme->filters; + struct damos *scheme; + int err; struct damos_access_pattern pattern = { .min_sz_region = access_pattern->sz->min, @@ -1435,8 +1504,17 @@ static struct damos *damon_sysfs_mk_scheme( .low = sysfs_wmarks->low, }; - return damon_new_scheme(&pattern, sysfs_scheme->action, "a, + scheme = damon_new_scheme(&pattern, sysfs_scheme->action, "a, &wmarks); + if (!scheme) + return NULL; + + err = damon_sysfs_set_scheme_filters(scheme, sysfs_filters); + if (err) { + damon_destroy_scheme(scheme); + return NULL; + } + return scheme; } static void damon_sysfs_update_scheme(struct damos *scheme, @@ -1447,6 +1525,7 @@ static void damon_sysfs_update_scheme(struct damos *scheme, struct damon_sysfs_quotas *sysfs_quotas = sysfs_scheme->quotas; struct damon_sysfs_weights *sysfs_weights = sysfs_quotas->weights; struct damon_sysfs_watermarks *sysfs_wmarks = sysfs_scheme->watermarks; + int err; scheme->pattern.min_sz_region = access_pattern->sz->min; scheme->pattern.max_sz_region = access_pattern->sz->max; @@ -1469,6 +1548,10 @@ static void damon_sysfs_update_scheme(struct damos *scheme, scheme->wmarks.high = sysfs_wmarks->high; scheme->wmarks.mid = sysfs_wmarks->mid; scheme->wmarks.low = sysfs_wmarks->low; + + err = damon_sysfs_set_scheme_filters(scheme, sysfs_scheme->filters); + if (err) + damon_destroy_scheme(scheme); } int damon_sysfs_set_schemes(struct damon_ctx *ctx, From patchwork Thu Nov 24 21:21:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055370 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 4CC8DC4321E for ; Thu, 24 Nov 2022 21:21:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C5378E0008; Thu, 24 Nov 2022 16:21:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FD5D8E0007; Thu, 24 Nov 2022 16:21:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 121648E0002; Thu, 24 Nov 2022 16:21:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DB2CA8E0006 for ; Thu, 24 Nov 2022 16:21:26 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A0BBF140512 for ; Thu, 24 Nov 2022 21:21:26 +0000 (UTC) X-FDA: 80169606972.20.1868B1B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 558631C000E for ; Thu, 24 Nov 2022 21:21:26 +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 A51FD6224C; Thu, 24 Nov 2022 21:21:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83EE2C4314E; Thu, 24 Nov 2022 21:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324885; bh=qgpIYxCoLxiSbmookPCEJSX95mijzZoDksXEWue5IhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bg/AaYGuCYp4M6g57krHOS5GWS+hMi8p5mp+UkjqKaATqZdbygBxDo8pgT5J/V8X5 SeOHpO64VwGb7y2NaTnqWlKcalc/qi6/1yqlseWD2aN0cLZ/0YkzPD+ojVlCjvRKEV tSYo5MiT45nugk3U6ZhWpSImAmvbsV4ikvCk3UFc4RYwy3Ha4KpsJGmK3YSgVoFkQK x8D4bqBobH8wUsPcV4hGQ3erCz7bbPrQmYK9GHlUPwBQrZ6x6vEN9uq+K11ExWHJHy 2xNyShxK/2Ww69uIIYUGBPs7HvreQTYXdhvw2zuS7KG/0AVZPTh2PUzt8JDtgk8pt8 Y2I5aPTMH5/IA== From: SeongJae Park To: Andrew Morton Cc: Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 09/11] selftests/damon/sysfs: test filters directory Date: Thu, 24 Nov 2022 21:21:12 +0000 Message-Id: <20221124212114.136863-10-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669324886; a=rsa-sha256; cv=none; b=3U4tZ8e5QjfQIncqqbkBd6m4Phh6sjIRQXGPE81+pDT7KZURS+YkhQKTGd7FQsSIgIMtC8 PeFsbLjCod78rz5zm4BTXP6Jtr/OhUhB8d7or2gGzqHJJzHmJae9eOrR+DQNXH5XZv0Pmd wVr3wtKOaaSccFglTCoqieDweIfuiCs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="bg/AaYGu"; spf=pass (imf21.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324886; 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=+OTj21n3Wg9gwrrIBxAx4NidZtXBp6SPjJpmtwVGK9A=; b=Ge5/mqKzQkwZnHqwr67vJ8ieZRH4vWNFLaxgI9JSo62hL8elJBmh30SrFaVV7PgVyFnf0U IlOTIZ9OkRuVz1JzRStOAHaayV0vvaj0LR+JiBwho+GwebyfhijRQUtu7nxjYhwi1ZvD5q YlZ3IxPM6txjL+gMgOAPaeyGNv44YD0= X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="bg/AaYGu"; spf=pass (imf21.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: hnbj4wurpx35mzxw7gepup8naeu81cb7 X-Rspamd-Queue-Id: 558631C000E X-Rspamd-Server: rspam12 X-HE-Tag: 1669324886-357521 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: Add simple test cases for scheme filters of DAMON sysfs interface. The test cases check if the files are populated as expected, receives some valid inputs, and refuses some invalid inputs. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.sh | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh index db4942383a50..a00336ffdcad 100644 --- a/tools/testing/selftests/damon/sysfs.sh +++ b/tools/testing/selftests/damon/sysfs.sh @@ -96,6 +96,34 @@ test_stats() done } +test_filter() +{ + filter_dir=$1 + ensure_file "$filter_dir/type" "exist" "600" + ensure_write_succ "$filter_dir/type" "anon" "valid input" + ensure_write_succ "$filter_dir/type" "memcg" "valid input" + ensure_write_fail "$filter_dir/type" "foo" "invalid input" + ensure_file "$filter_dir/matching" "exist" "600" + ensure_file "$filter_dir/memcg_path" "exist" "600" +} + +test_filters() +{ + filters_dir=$1 + ensure_dir "$filters_dir" "exist" + ensure_file "$filters_dir/nr_filters" "exist" "600" + ensure_write_succ "$filters_dir/nr_filters" "1" "valid input" + test_filter "$filters_dir/0" + + ensure_write_succ "$filters_dir/nr_filters" "2" "valid input" + test_filter "$filters_dir/0" + test_filter "$filters_dir/1" + + ensure_write_succ "$filters_dir/nr_filters" "0" "valid input" + ensure_dir "$filters_dir/0" "not_exist" + ensure_dir "$filters_dir/1" "not_exist" +} + test_watermarks() { watermarks_dir=$1 @@ -143,6 +171,7 @@ test_scheme() test_access_pattern "$scheme_dir/access_pattern" test_quotas "$scheme_dir/quotas" test_watermarks "$scheme_dir/watermarks" + test_filters "$scheme_dir/filters" test_stats "$scheme_dir/stats" test_tried_regions "$scheme_dir/tried_regions" } From patchwork Thu Nov 24 21:21:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055371 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 551CBC433FE for ; Thu, 24 Nov 2022 21:21:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CEAA8E0002; Thu, 24 Nov 2022 16:21:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 762E38E0006; Thu, 24 Nov 2022 16:21:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C0F38E0002; Thu, 24 Nov 2022 16:21:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 22A488E0006 for ; Thu, 24 Nov 2022 16:21:27 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EF6F7801E4 for ; Thu, 24 Nov 2022 21:21:26 +0000 (UTC) X-FDA: 80169606972.18.AF8F260 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 99BAD180007 for ; Thu, 24 Nov 2022 21:21:26 +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 E031D62261; Thu, 24 Nov 2022 21:21:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39D8FC4347C; Thu, 24 Nov 2022 21:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324885; bh=r1rD9KyNMBqJg8aGe8o3Z8JXG+myDQ882BtgLSHPqNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qUjgEscQClwo6WemlMmyVkQcyAdOazaD4oNfXaCdV2/UsJsDcRJsDeEGq2OaUHB0Q dZXgZFk9mMS2qVQZEBPnOPMqkJ6eeMeU5XxquL3Mh/lR/iwksqM9Mj2iofHucZwPDQ DhzkcbCF8tsK98kfcM+3CxgJudUlWk4s+59VPkmyRvSbTKFTuQ928ckHt/00s8bCXF Qcb7yPnReQEQNzhEyT0OPXVlsHqal9sqMXP/y5pzAJjcshjaMSy5dBVKU9GTx3+U+3 kameP1nAqmJIXnsz3XobD1ANGRnEHhNf7wOw/vMo5uekrxo2lu9HKwvI0lwgQD8otk mFPTE1n1JQD9A== From: SeongJae Park To: Andrew Morton Cc: Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 10/11] Docs/admin-guide/mm/damon/usage: document DAMOS filters of sysfs Date: Thu, 24 Nov 2022 21:21:13 +0000 Message-Id: <20221124212114.136863-11-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-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=1669324886; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gpmeBORiZpRF2beWDn7dZTCiE/JqtbjFsMCpo3MlrhI=; b=dZTFdHCLYVZoUDHSgvdUfpQVJ9otXDWFotX6MH48STeGHv9dBaV8L4yYsLVQwNlE0zri9w 5yvi49H5odvs1kzNlOBoKCRKxV8j4B8PcNcEFD+JOzZmBSXAk1KB5boHT547Dms0D7Vy26 EzxVCVYCiZRYExyaGJ+3CZTc+kOS4Rc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qUjgEscQ; spf=pass (imf06.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=1669324886; a=rsa-sha256; cv=none; b=Wr4UsMQjigARY/1pjc5VPlFo92B9ke4Zgtb6nuAtzmQgJZr2Ep7NLx2JO/rSpAymvvSkiH dq3foN4k7vhTmmD7NLV4OTuoIeRnSnnUDzp/8zTOPDQWwavNydEsNUB8F3ZC1aoFGj43Xl jdSMYnowUXV8ctalNlI/B/KDc1dGX08= X-Rspamd-Queue-Id: 99BAD180007 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qUjgEscQ; spf=pass (imf06.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-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hpnfo9c3g9gn4qhf11pazbd6eszgw6y9 X-HE-Tag: 1669324886-268263 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: Document about the newly added files for DAMOS filters on the DAMON usage document. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 48 +++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index 1a5b6b71efa1..3d82ca6a17ff 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -87,6 +87,8 @@ comma (","). :: │ │ │ │ │ │ │ quotas/ms,bytes,reset_interval_ms │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil │ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low + │ │ │ │ │ │ │ filters/nr_filters + │ │ │ │ │ │ │ │ 0/type,matching,memcg_id │ │ │ │ │ │ │ stats/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds │ │ │ │ │ │ │ tried_regions/ │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age @@ -151,6 +153,8 @@ number (``N``) to the file creates the number of child directories named as moment, only one context per kdamond is supported, so only ``0`` or ``1`` can be written to the file. +.. _sysfs_contexts: + contexts// ------------- @@ -268,8 +272,8 @@ schemes// ------------ In each scheme directory, five directories (``access_pattern``, ``quotas``, -``watermarks``, ``stats``, and ``tried_regions``) and one file (``action``) -exist. +``watermarks``, ``filters``, ``stats``, and ``tried_regions``) and one file +(``action``) exist. The ``action`` file is for setting and getting what action you want to apply to memory regions having specific access pattern of the interest. The keywords @@ -347,6 +351,46 @@ as below. The ``interval`` should written in microseconds unit. +schemes//filters/ +-------------------- + +Users could know something more than the kernel for specific types of memory. +In the case, users could do their own management for the memory and hence +doesn't want DAMOS bothers that. Users could limit DAMOS by setting the access +pattern of the scheme and/or the monitoring regions for the purpose, but that +can be inefficient in some cases. In such cases, users could set non-access +pattern driven filters using files in this directory. + +In the beginning, this directory has only one file, ``nr_filters``. Writing a +number (``N``) to the file creates the number of child directories named ``0`` +to ``N-1``. Each directory represents each filter. The filters are evaluated +in the numeric order. + +Each filter directory contains three files, namely ``type``, ``matcing``, and +``memcg_path``. You can write one of two special keywords, ``anon`` for +anonymous pages, or ``memcg`` for specific memory cgroup filtering. In case of +the memory cgroup filtering, you can specify the memory cgroup of the interest +by writing the path of the memory cgroup from the cgroups mount point to +``memcg_path`` file. You can write ``Y`` or ``N`` to ``matching`` file to +filter out pages that does or does not match to the type, respectively. Then, +the scheme's action will not be applied to the pages that specified to be +filtered out. + +For example, below restricts a DAMOS action to be applied to only non-anonymous +pages of all memory cgroups except ``/having_care_already``.:: + + # echo 2 > nr_filters + # # filter out anonymous pages + echo anon > 0/type + echo Y > 0/matching + # # further filter out all cgroups except one at '/having_care_already' + echo memcg > 1/type + echo /having_care_already > 1/memcg_path + echo N > 1/matching + +Note that filters could be ignored depend on the running DAMON operations set +`implementation `. + .. _sysfs_schemes_stats: schemes//stats/ From patchwork Thu Nov 24 21:21:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13055373 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 6BDE2C4321E for ; Thu, 24 Nov 2022 21:21:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C17F8E0007; Thu, 24 Nov 2022 16:21:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 120E98E0006; Thu, 24 Nov 2022 16:21:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF9458E000A; Thu, 24 Nov 2022 16:21:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BE0A18E0007 for ; Thu, 24 Nov 2022 16:21:27 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 943AB1604B1 for ; Thu, 24 Nov 2022 21:21:27 +0000 (UTC) X-FDA: 80169607014.14.1D1D282 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 3423E180011 for ; Thu, 24 Nov 2022 21:21:26 +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 73EDF6225F; Thu, 24 Nov 2022 21:21:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E417CC43148; Thu, 24 Nov 2022 21:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669324886; bh=wsgdvbT/35uxHZu2m3onVtLPaAGvmOTx9y/8CzTLOOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YDg+vzz59qn2HGlc430DM8drl6oinc/UL0FpJCDPYW0zg6kwKIMMK7ZH91NR/v7Tc ntUk5ZVoJfTah+eY37CEbVI1t05GDdP8YA/IZrpMUoCqBmMfAWpDjV3wCdVTfK4CCS 3sFVxXLMWYVpheee7x+D4QjZJENE2FSd7g3hsONkaRcNY5G+5dczXqysiXaZeD+HzP /dLKkOBbMCOWzw0KRG4+LhOy700ioqjoBJQdIVUO67vhXsdrEZMfCGcE6Yt2epQRvP kpkaEj1Ly9oJjZgzRkQ9TarH/pCZjAPV/+mR98Y3xXdQjVm67hi/WP4tBua8Bv4twc 8vrIMAkhlxs3A== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 11/11] Docs/ABI/damon: document scheme filters files Date: Thu, 24 Nov 2022 21:21:14 +0000 Message-Id: <20221124212114.136863-12-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124212114.136863-1-sj@kernel.org> References: <20221124212114.136863-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669324887; a=rsa-sha256; cv=none; b=c/vsEPFLkd2sbRaTTKVTHTAEbD3D3yNzYZXNkwhdLReiWzjs1xUI5FpPNHGA0Kf9g6bNwc 2IyMnwZPkkLYPwriWilnkTFdOgsCw+1fXQWdauTXVsvfDLxUPWQIMY/MbcF4sbPmQ7EUF7 V0qqjuF9STy4fHq9175UGtJ5NeIRouc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YDg+vzz5; spf=pass (imf16.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669324887; 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=TLb5XnMDpgcYHy4frIqgmGqxPwmmsgK8DLbiJhJicSI=; b=8Z0Reln6OogUmxQtTiJLXg/L+FWT3UabGCagb4vIuzts3X6fDkqyLRfMxxHbMk00+b/Vmp JXsse2jKS7OQswxkb4guJgpUxKCGVN2aDlfe/Oi/eVD2HUtV+lGdZH0JDoVDkzGY4DqDSo HBwJEqfs9Vo1s5zyatPt2+u2s5mNfMM= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YDg+vzz5; spf=pass (imf16.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: phq1b6m5inhuaihh8j3nir8rge5k9awu X-Rspamd-Queue-Id: 3423E180011 X-Rspamd-Server: rspam06 X-HE-Tag: 1669324886-171330 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: Document newly added DAMON sysfs interface files for DAMOS filtering on the DAMON ABI document. Signed-off-by: SeongJae Park --- .../ABI/testing/sysfs-kernel-mm-damon | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon index 13397b853692..2744f21b5a6b 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -258,6 +258,35 @@ Contact: SeongJae Park Description: Writing to and reading from this file sets and gets the low watermark of the scheme in permil. +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//filters/nr_filters +Date: Dec 2022 +Contact: SeongJae Park +Description: Writing a number 'N' to this file creates the number of + directories for setting filters of the scheme named '0' to + 'N-1' under the filters/ directory. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//filters//type +Date: Dec 2022 +Contact: SeongJae Park +Description: Writing to and reading from this file sets and gets the type of + the memory of the interest. 'anon' for anonymous pages, or + 'memcg' for specific memory cgroup can be written and read. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//filters//memcg_path +Date: Dec 2022 +Contact: SeongJae Park +Description: If 'memcg' is written to the 'type' file, writing to and + reading from this file sets and gets the path to the memory + cgroup of the interest. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//filters//matching +Date: Dec 2022 +Contact: SeongJae Park +Description: Writing 'Y' or 'N' to this file sets whether to filter out + pages that do or do not match to the 'type' and 'memcg_path', + respectively. Filter out means the action of the scheme will + not be applied to. + What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//stats/nr_tried Date: Mar 2022 Contact: SeongJae Park