From mboxrd@z Thu Jan 1 00:00:00 1970 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 406CCC83028 for ; Sun, 29 Jun 2025 20:14:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 446266B0096; Sun, 29 Jun 2025 16:14:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A88C6B0098; Sun, 29 Jun 2025 16:14:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 221E46B0099; Sun, 29 Jun 2025 16:14:51 -0400 (EDT) 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 0E8026B0096 for ; Sun, 29 Jun 2025 16:14:51 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B1B7557D1C for ; Sun, 29 Jun 2025 20:14:50 +0000 (UTC) X-FDA: 83609541540.08.DC74306 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf24.hostedemail.com (Postfix) with ESMTP id EBF2F180005 for ; Sun, 29 Jun 2025 20:14:48 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lXMIQhz8; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751228089; a=rsa-sha256; cv=none; b=GA0+Ii8+wCQD9J4PyDjixGv8d+VyMrd720Z0I4l9aDa8PDyPIu4W1xzdtlyEtSUmYaTitW daytV3CwSdpxikJJUbX75BdgZX1ez6fTGajhxip52+chazxyzdly3p5y6TbiMLukab3w2N l7IhAeNNkgxPNes0XrVrXuDHoqrUlKU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lXMIQhz8; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751228089; 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=sveLsOg5vgpk5My6LBBDRESZ0lsRMiWbBrxtK49xBP0=; b=LxTnyTiSpMsl9qHsTKGIm8ZnOIOHbu4PMrL8eZsCeYDemnP9fKYDVEUGFP32ucQMh3VgJ0 si+pgkokOyGUYaDJ3pyOGCLi96vFUwLqbEeA2g3uo2jbnW8y4D53ie4Ia84sv0zLMQLgGa B0oubOmb337rNrf1lPKp0LPrU5wXGNI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id ADC2944F54; Sun, 29 Jun 2025 20:14:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64CF6C4CEEB; Sun, 29 Jun 2025 20:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751228087; bh=MU2ihuhRbcRf1fDg3XPwZVg/5ZSe+hiAlUpj1S6bhJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lXMIQhz8xwv2iKYzuyO6NqQHPvp3tlMkOsUXw5R/QGyqAl2iAlN4JIEMU8GMeQMJY ukicEefMFlMqdhHowBFKTGzsRhv6b9txOfBsp77unrsIcLL61fr/kqVpumaHJtqoty eMJdXnWCWlU+zQzgFZv2p+F0ysPLTtkTvLprxaUFP/oILF0yh1kpHnISwpQAYL/1xw GBj0GDJBc3fGIwDLtin/lM6WY1pHk+Dpa+6CvqRWc0ERxRTbPYUItmy6YwBllqvIcy Q/9jRrVCdODH6O4+2AVo0WZSMKuDWsmCPAYGzntR4o5SrG/caK/0QYt4eGY9uMHIRl cZYKJmA7wSRFw== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 1/6] mm/damon/core: introduce damon_report_access() Date: Sun, 29 Jun 2025 13:14:38 -0700 Message-Id: <20250629201443.52569-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250629201443.52569-1-sj@kernel.org> References: <20250629201443.52569-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: EBF2F180005 X-Stat-Signature: kj4kfs9zft1d8n4eu3zr7iakw6ai38us X-Rspam-User: X-HE-Tag: 1751228088-497601 X-HE-Meta: U2FsdGVkX18k8v6WtAbfuGh6t8lKR9H7/nZCdhrm7Gv57C0KmkMbIiVHFzbjIM6UAJTZrSk5HqwQyWcjuV43Z+Qvss72am0ELo0YNHq0zq1H5jmhQV2JISDVsfxO8zUN/0brnzSsUYGDrOUtI2SLTrwliQ2ps9nVd1yserwE2+1rJgW+G8eT2fPl8YHMqlhVdwQan1bcECDhNcV1ZsMoTXtiwtCwVUH80EPFltWS3sD5kHY8RazzsVFacR6wrkuhLdTkFN89Sla/gsXGWUPkeLSXAhodKGRhPDNQx85sJCdGC5gwC5fGsfoYsc6uBZS8QCmLrEEMgRVXlzcG5zSlltqBbTyn7wSg/ANfwE9Wp8ViYti1t+pMJ1QIEuTB5o0TPCtFXs5ELBFww/IVyuceNe+FlhP0TMl4jQTxSalOgf7iukrOhU420jJt5UR9RG3oWdDKyzYNqK7h1KJvUIp9bJ4Y2S8BM0yrKpymF1JcOQs5qL52CuZhyIMVfXtwmWJl0Ahb9h+UqdwFRvX6jzcn1pVoDKgxOdRJWMizw6E2qAFVKN/pRR+sOtMhsfotb0nIHU4XmqnNeMYbyNmGtsZO38LxblG/ifcjDv1uAC/nf5O4JQg1jZcPfYojNYY0boYvzYrz2geuO+B7/J2l67U0sng7UybNqyLeIRJVNPkZNtwzXUUUIdnHRx5nKDsVjp8DLo35/0iZLgCo7eU2FM3qfrIUTHD8Zm0GHsMA7ieB4522rBMmwGtSuy98he9YekstluGPZqxXGr4fsjNRU8ZqWJqQfbDmDLvz2z6wvEpOlqs41Dmx6hpdCNtYJ5Ea4DMQm5n/CtKbHrbLk19wCFcNZLXDgVn+MKRY4PzVj31/E824+Q6OugPzWQrATsa7o4hd1s0wSenzdtpUZi8azvkT1jEmyrHN0zV50OFBqFYDMx9E/1j7gEDVkBFd3Si5toOlwafDF9VUAoABA0+fsbN wfAawlnj ZIDIMiVMOXktJVYyldGUIyAynNThXuKXi82kx9xO3nI1v6w3RJWBdG7+rrgAeGc3vLxcW8O0j3K4VZ+DSP67zITco/dCcRLjMPB/pUXP6ZrtG5gzouEtpHDTL8mIbILVj8pOEIaUlq/Q9nk3a2dOwQ89YsUApRU67qbr4LlsKbc2VO7fi4U/Eel8Isoggscbi6jwthFbvDouriMjm/1/KTEeNT+E1h5pGW3FgRpFOmPHcZFQ/4XqbOYyEditoEYwvYv11PycaA4txI7FQmMf8D8/7WFeXbk9NowvydvNUbl5ok8RHiiLt2DhrnnvlHQR6SmMm 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: List-Subscribe: List-Unsubscribe: DAMON core layer asks operations set layer about past access information, on core layer's schedule. In other words, core layer "pulls" the information from the operations set layer. This is problematic for a case that the operations set layer have no time and space to save the information until the core layer queries. Add a new DAMON API function for reporting identified data accesses to DAMON, on the identifiers' schedule. In other words, it lets the operations set layer to "push" the information to the core layer. The function internally uses mutex, so reporting kernel code should be safe to sleep. Signed-off-by: SeongJae Park --- include/linux/damon.h | 21 +++++++++++++++++++++ mm/damon/core.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 6370cf44486f..a2198909c903 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -104,6 +104,25 @@ struct damon_target { struct list_head list; }; +/** + * struct damon_access_report - Represent single acces report information. + * @pid: The PID of the virtual address space of the address. + * NULL if it is of the physical address. + * @addr: The start address of the reporting region. + * @size: The size of the reporting region. + * @nr_accesses: Number of detected accesses to the region. + * + * @pid could be stale, and hence shouldn't be de-referenced. + */ +struct damon_access_report { + struct pid *pid; + unsigned long addr; + unsigned long size; + int nr_accesses; +/* private: */ + unsigned long report_jiffies; /* when this report is made */ +}; + /** * enum damos_action - Represents an action of a Data Access Monitoring-based * Operation Scheme. @@ -961,6 +980,8 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control); +void damon_report_access(struct damon_access_report *report); + int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); diff --git a/mm/damon/core.c b/mm/damon/core.c index ea2a17b2dee7..b54ed91f2dce 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -24,6 +24,8 @@ #define DAMON_MIN_REGION 1 #endif +#define DAMON_ACCESS_REPORTS_CAP 1000 + static DEFINE_MUTEX(damon_lock); static int nr_running_ctxs; static bool running_exclusive_ctxs; @@ -33,6 +35,11 @@ static struct damon_operations damon_registered_ops[NR_DAMON_OPS]; static struct kmem_cache *damon_region_cache __ro_after_init; +static DEFINE_MUTEX(damon_access_reports_lock); +static struct damon_access_report damon_access_reports[ + DAMON_ACCESS_REPORTS_CAP]; +static int damon_access_reports_len; + /* Should be called under damon_ops_lock with id smaller than NR_DAMON_OPS */ static bool __damon_is_registered_ops(enum damon_ops_id id) { @@ -1403,6 +1410,34 @@ int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control) return 0; } +/** + * damon_report_access() - Report identified access events to DAMON. + * @report: The reporting access information. + * + * Report access events to DAMON. + * + * Context: May sleep. + * + * NOTE: we may be able to implement this as a lockless queue, and allow any + * context. As the overhead is unknown, and region-based DAMON logics would + * guarantee the reports would be not made that frequently, let's start with + * this simple implementation, though. + */ +void damon_report_access(struct damon_access_report *report) +{ + struct damon_access_report *dst; + + /* silently fail for races */ + if (!mutex_trylock(&damon_access_reports_lock)) + return; + dst = &damon_access_reports[damon_access_reports_len++]; + if (damon_access_reports_len == DAMON_ACCESS_REPORTS_CAP) + damon_access_reports_len = 0; + *dst = *report; + dst->report_jiffies = jiffies; + mutex_unlock(&damon_access_reports_lock); +} + /* * Warn and fix corrupted ->nr_accesses[_bp] for investigations and preventing * the problem being propagated. -- 2.39.5