From patchwork Fri Jul 28 20:34:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13332648 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 D7E38C001DF for ; Fri, 28 Jul 2023 20:34:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4F228D0003; Fri, 28 Jul 2023 16:34:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CFE986B0074; Fri, 28 Jul 2023 16:34:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC1638D0003; Fri, 28 Jul 2023 16:34:52 -0400 (EDT) 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 8457A6B0074 for ; Fri, 28 Jul 2023 16:34:52 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4CB89A05AC for ; Fri, 28 Jul 2023 20:34:52 +0000 (UTC) X-FDA: 81062174424.05.2A810F7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 9DA8880009 for ; Fri, 28 Jul 2023 20:34:50 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=p2r8hu9C; spf=pass (imf30.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=1690576490; 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=f1+kUO/1jvUs16oQPMZPa4+TQlRIDLtHo6KkeqNkj7g=; b=KkKsB/S2cmikq1t6KhNasiY6oKtywGrh1jd/8kX3NCMKY42Z1RviX26do1sTnpmpPSdJ9L F2LQVI63NTCWul+9tWN2bCDwxDwzmq/iqWbQMfUamFEWWib9nCmQQI1C1ZleJz0liPsM/1 Zv1sMX+A2rNXz8uKQuFRSpLXITmLDyA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690576490; a=rsa-sha256; cv=none; b=JfcG1GVfWoUdFNthuX48HNgCJ2dcJM5fB02CwSkN5bO+9hmgPq8UAbeG+e0xZnyQ91vWX3 Ysd1eNbSxFis2HkwyeFe8pVzVInEC2If3qNvIQEPHS7lugH6DXBTdYFD07YO2to6bfgtUq 3cgJOy4zoUNbHLlGn+SbAfmumlNyrlo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=p2r8hu9C; spf=pass (imf30.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 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 BAE5A62205; Fri, 28 Jul 2023 20:34:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B668BC433C9; Fri, 28 Jul 2023 20:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690576489; bh=RNhaUHFt4yEDSg34n1AIbUDtUgo0To5YvQtFN1055is=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p2r8hu9CmFI364JLZUBG5moYhkILhGzb8EUF5UUqi4zpjISMyATubHTf8iaRu+Y3e B7Mb9YlocLRyG+jrKWyvPFKDQJHIHMnMaPTd9txEMbGeYRaSJwgaAbCHqkHQg9K0fW VibqHFWGC5EnpYUnVK2qUxRfeduyXd72rk2CDLfw2EbHQyq+wZyKy/1sqT5yCbjDgj /aoJsj5yLhShWP70po7j3u8d9kh4bpVU6glpe2lFV8+KPa5zSjLDjgg/5R/XkpKt2P EevGd1FGvMBFcAwR88pJIotq/h/bcab83pCI7HEFhB+wwMDetEl+nhyJtU+EfdmRb8 2FkRJskRSLGqA== 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 01/13] mm/damon/core: introduce address range type damos filter Date: Fri, 28 Jul 2023 20:34:32 +0000 Message-Id: <20230728203444.70703-2-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-Rspamd-Queue-Id: 9DA8880009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: argo7bxube3odhqmcjyojpg7yofthb7c X-HE-Tag: 1690576490-884610 X-HE-Meta: U2FsdGVkX1/4Bq2m6i1+Q7FiMckNSy5qS2tx/ApHYR1/ptEqfTahPRqt6XzckYsPjlpS6i1DQ2g1xpXYzUswSNA9pFMM/KpqrVAsfZFmI2EYfUaKxbc54Je8qD+jou4yibvOVfsqTKvHhc5V2++m53B48gbbrHt+AoIiRWoBg9F1PBJvT4J6ROYX3i/4NJvh1zJvF/SGRxeIVYZtvoGtHSiAMipw602rHNMXpJ8eB/uq4s0QMwFqW1ZP27PcL20BFrhHe2AIV2iayOnmo/Ztzi7yiXtUNiPcbOy8aDROgV5UYWqxlqFaCFC5DaXrTacEFE8X01Ap50WaXWUPcMPF6LgXTgfOjlBy298V26uIXyUR78USlTfKiwymc5yZ8Q0xQ+7mweDy8RwTIRDXmbbjMRkj+SmxT8gxDanf3JVXS10WMefcyitNccuekPqSCF0XnLNKnedd5Tb5JHDRpgyJY4aP3R/8k4ZCK4CYaURfxRS3u6wqE2qNjamT2Nc3m8xHgdw8dfhe+l0ygjg/0PdxB8NdjjCzyeksrEs41vdE4ERW9N18E723fH28pzEH2Vcpl5njtWOtj+WrTajujFMQDyd76y7i26u9yK5sUWPv1hxTw9EN1npwbMuC8pmTbKPl3yTExG+B+PUaKqhgKzh5xSgm/Kp9B9e0cmK5TW6aVYDyDZIKSOoVMZGcb2i/f4wM10623rGPuNznVHH8cW89pTRZaBVtv5PEw8r/XTnXmqLVyrTsNpeb8S8db0654b6sYhTMnpKAZcINCs0OkcOoMFdibEuPbwzX2fkyd+EP52qJ30Pf+g/JN7ESvhMWtU4Ij0euOKPOLfqtdvzAp768BaNbmuh1uBNWfgxUwagIoK6CYpkQXyj4PZWCUHe+WLl6RaP5ia+y4mZLrNYf48kwC1NYe/EPtscfYmmWABk3j4GT5JYWpExQtFZT4KIP+beUPFGbiJk7PNTDQABTbgX gyzlyaMN AuI1VOz6f6CRhPKmRUmbQZgKL12FYFeeQBXbTjZA26vbFr3gvK+RTZcUqKmfCwHN9pn+szFljAi0spubLqhb5fztD54I6+SnZB6Pgpl1u52Y1qfBetLodxJOgnG2jtTu2sWk0/xlD6J6UBt6blXogSlQj/I2lfiI4sMHjxCrDs2UgKoafpRUS8d1P4ElV1VPotC6Lvnli9Dj5wj3b8rJDSBzyWag2kmPnUxSoae6hpv4JbFSSqah1mcSPahzv4soRrHT0gDFMk254fy8r3ih3pdiabaAaOXKvkfl2HTidFj2JEal7M0BbWskhb69zYm23zn5c44W45FuiwNQCIdqm8wUt5Q== 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: Users can know special characteristic of specific address ranges. NUMA nodes or special objects or buffers in virtual address space could be such examples. For such cases, DAMOS schemes could required to be applied to only specific address ranges. Implement yet another type of DAMOS filter for the purpose. Note that the existing filter types, namely anon pages and memcg DAMOS filters needed page level type check. Because such check can be done efficiently in the opertions set layer, those filters are handled in operations set layer. Specifically, only paddr operations set implementation supports these filters. Also, because statistics counting is done in the DAMON core layer, the regions that filtered out by these filters are counted as tried but failed to the statistics. Unlike those, address range based filters can efficiently handled in the core layer. Hence, do the handling in the layer, and count the regions that filtered out by those as the scheme has not tried for the region. This difference should clearly documented. Signed-off-by: SeongJae Park --- include/linux/damon.h | 22 +++++++++++++----- mm/damon/core.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index d5d4d19928e0..476f37a883a4 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -226,16 +226,24 @@ struct damos_stat { * 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. + * @DAMOS_FILTER_TYPE_ADDR: Address range. * @NR_DAMOS_FILTER_TYPES: Number of filter types. * - * The support of each filter type is up to running &struct damon_operations. - * &enum DAMON_OPS_PADDR is supporting all filter types, while - * &enum DAMON_OPS_VADDR and &enum DAMON_OPS_FVADDR are not supporting any - * filter types. + * The anon pages type and memcg type filters are handled by underlying + * &struct damon_operations as a part of scheme action trying, and therefore + * accounted as 'tried'. In contrast, other types are handled by core layer + * before trying of the action and therefore not accounted as 'tried'. + * + * The support of the filters that handled by &struct damon_operations depend + * on the running &struct damon_operations. + * &enum DAMON_OPS_PADDR supports both anon pages type and memcg type filters, + * while &enum DAMON_OPS_VADDR and &enum DAMON_OPS_FVADDR don't support any of + * the two types. */ enum damos_filter_type { DAMOS_FILTER_TYPE_ANON, DAMOS_FILTER_TYPE_MEMCG, + DAMOS_FILTER_TYPE_ADDR, NR_DAMOS_FILTER_TYPES, }; @@ -244,18 +252,20 @@ enum damos_filter_type { * @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. + * @addr_range: Address range if @type is DAMOS_FILTER_TYPE_ADDR. * @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. + * Support of each filter type depends on the running &struct damon_operations + * and the type. Refer to &enum damos_filter_type for more detai. */ struct damos_filter { enum damos_filter_type type; bool matching; union { unsigned short memcg_id; + struct damon_addr_range addr_range; }; struct list_head list; }; diff --git a/mm/damon/core.c b/mm/damon/core.c index cbe5a1cc27c4..c061d289c832 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -906,6 +906,56 @@ static void damos_update_stat(struct damos *s, s->stat.sz_applied += sz_applied; } +static bool __damos_filter_out(struct damon_target *t, struct damon_region *r, + struct damos_filter *filter) +{ + bool matched = false; + unsigned long start, end; + + switch (filter->type) { + case DAMOS_FILTER_TYPE_ADDR: + start = ALIGN_DOWN(filter->addr_range.start, DAMON_MIN_REGION); + end = ALIGN_DOWN(filter->addr_range.end, DAMON_MIN_REGION); + + /* inside the range */ + if (start <= r->ar.start && r->ar.end <= end) { + matched = true; + break; + } + /* outside of the range */ + if (r->ar.end <= start || end <= r->ar.start) { + matched = false; + break; + } + /* start before the range and overlap */ + if (r->ar.start < start) { + damon_split_region_at(t, r, start - r->ar.start); + matched = false; + break; + } + /* start inside the range */ + damon_split_region_at(t, r, end - r->ar.start); + matched = true; + break; + default: + break; + } + + return matched == filter->matching; +} + +static bool damos_filter_out(struct damon_target *t, struct damon_region *r, + struct damos *s) +{ + struct damos_filter *filter; + + damos_for_each_filter(filter, s) { + if (__damos_filter_out(t, r, filter)) + return true; + } + return false; +} + static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, struct damon_region *r, struct damos *s) { @@ -932,6 +982,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, } damon_split_region_at(t, r, sz); } + if (damos_filter_out(t, r, s)) + return; ktime_get_coarse_ts64(&begin); if (c->callback.before_damos_apply) err = c->callback.before_damos_apply(c, t, r, s);