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 E9DAAC5AE59 for ; Thu, 5 Jun 2025 15:25:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0619C6B058D; Thu, 5 Jun 2025 11:25:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00BBC6B058F; Thu, 5 Jun 2025 11:25:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3A4E6B0592; Thu, 5 Jun 2025 11:25:14 -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 BDC096B058D for ; Thu, 5 Jun 2025 11:25:14 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 03E9580C4D for ; Thu, 5 Jun 2025 15:25:13 +0000 (UTC) X-FDA: 83521720548.03.D525CCB Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf09.hostedemail.com (Postfix) with ESMTP id 1842A14000E for ; Thu, 5 Jun 2025 15:25:11 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VjpWNAvP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749137112; 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=hywIa1C5VWmiWv5K8Y4aCyROkM0KVWGznJdti4Qv9UY=; b=iFV5zVOWdROiZR4dRzMJX3Ag9BNbfltm02zc0mAF6MdIeqqCpvg5kACsnIqEzTy1V1sj1O lqAQBRWiIGDjbBF9m3ORHS21ZFNyx/SCDIm5f7+PSSKyFrjSU7fBTOyDzcuGh/QCFlwYlR x9FbwSx0M0uHzvdSGRvPDSCETYzROW8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VjpWNAvP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of joshua.hahnjy@gmail.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=joshua.hahnjy@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749137112; a=rsa-sha256; cv=none; b=BCm+Sfme+dQPc5H8KvX5oWiSYgaii+b3ypHCvgkeJsolX9NswdkZ1J6gPPfzMXfvJP2dCN h17URqWCoR5Dbt03Zhk5Vg0YU0XerB5dTqAQ4pBe/rYmHcnBekrYlOyICkXNjZeOz84znJ pZa63L6hMyUk+mD+oASw3o1o/QkKvLQ= Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-710f39f5cb9so3371417b3.3 for ; Thu, 05 Jun 2025 08:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749137111; x=1749741911; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hywIa1C5VWmiWv5K8Y4aCyROkM0KVWGznJdti4Qv9UY=; b=VjpWNAvP9zoURpJxdhduJ3BW1LCfSiWLPjH+ayCBDy60og9DEZjFJBfEZ5cXxiDo9+ WRszO1i6kyPOYi2dn+/Js82ZVqyvH9lg+ktoGKbOOD4qzwXFL3BFN2e69JpalDMuajko eHaZ0u7yTNnpsASDM4qvVRQlPDUKPPF7Y7HhQdysIy2W+fSD3kKxi7aQocpPAM3fWVgm jFieTCHOraXnxRKthyZtzhe2rrxd3HWX0a2zKU0EG88xXWeztXXjSrfehwgeVGbIGQZh XfnnaVLHNIHKwOThXYZf7j3cPOR/HSKut+N5SlktcZycqiPN/gcw6tpzbUkncF5Th2K+ EpAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749137111; x=1749741911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hywIa1C5VWmiWv5K8Y4aCyROkM0KVWGznJdti4Qv9UY=; b=mM6qRhWBqa6UOdWAlqRrZsn8VFzm8wQaBc1QCz3qDtVKCL3l6w+FAJKSk2sCZcoqky yyrNIH22mXZdtMZS6duZDo8n2Wb2+P9/7NfTyQ85wYCZ/eJXrQhmmthtIWsasf303FEk kZrLYD2p+hSOwST/j4I8K/mcKvw0qlfWhwPSdwCK5ohojOecChgC6/B3YMWGW9naufGu OG02nk07JhfG4qAJwZ6CWSx0saJjKRb9wS2M2D7DKWF00lm2aeJQYikZ5JolATd0Yra8 MhKRPr4qU1UfH/C8Tpre0yVAYw+A4tNgphXeKEcqHYeYIj6BvQsRbyvhrETSCF9DnsUx 6pxg== X-Forwarded-Encrypted: i=1; AJvYcCW0B5Dd0KS2sEJa/W1qZPVhwbwm5GmUm3pwrTnry2qeAmmUQHQKs2kXpIMWQjUdgboPrlBVuk7tqQ==@kvack.org X-Gm-Message-State: AOJu0Yx9thET/vjIzMnYP6mW6uNOGVnTnXsCfIGesm+AxDOZRJ0Q7N1+ +0RwWaVt5DAArPdFUdizVppNtFywx3VIrIl1QdSawx12r5PWpRb/swSy X-Gm-Gg: ASbGncuIhRdPoBbcqQsdGo5Wkfw5c3jZ+TjIIsenVzVcnYz97MxeyxiFlVqYENpaJME yfOYwOFUCembuZXH+vYelqs17s2cnDMPhKPda5ljjpnZlSmTKnQezLMx8MgUkOAtaP7LRSGaP2W 4EMynCkzYNwkRC84QI7tJOqlYTE6Lu9icSwugePuAfMWO/06iEbpA+aZd5EKp+Wi0Upxk4xh2/S KazOA8o8HwtaKPr7/KA/L1CqofNCbLOp5UwuPFIN9MedT73nwGrwbhOlozkQQyR2FEMkAgUV0Lm c26G26K+tRwBhLaODddqm2TBN9HKQHL6BkToVkwa4fZ+3hADUQ== X-Google-Smtp-Source: AGHT+IFKgP5b3rRmeu100Vg2csRRR2cxN4MyQ8g5gK0KVrLhsIwOxgu/whtgrI5JrALBQh9eixFOvA== X-Received: by 2002:a05:690c:84e:b0:710:e9b1:485f with SMTP id 00721157ae682-710e9b15030mr33158717b3.20.1749137110770; Thu, 05 Jun 2025 08:25:10 -0700 (PDT) Received: from localhost ([2a03:2880:25ff:e::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-70f8ad25be6sm35189437b3.122.2025.06.05.08.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 08:25:10 -0700 (PDT) From: Joshua Hahn To: SeongJae Park Cc: Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 1/4] mm/damon: introduce DAMON_STAT module Date: Thu, 5 Jun 2025 08:25:07 -0700 Message-ID: <20250605152508.3275113-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250604183127.13968-2-sj@kernel.org> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1842A14000E X-Stat-Signature: hyk1aq1qhikf7bthr5udpkptns8s78sa X-Rspam-User: X-HE-Tag: 1749137111-786038 X-HE-Meta: U2FsdGVkX18cUsJY/tOvpmwH4P0kktS1+w31zey/PvQT9jMXe1T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nb+9ERfxO61oi6OC389Yhb2GJz/3JG1J/NiUeuzs669v1YMWklNsQMVK7a/YB2K9WklXuphT1mPReQGPcCU44hIC15+WHeoZ6dZPx7B2213qMNyIHadgcEPjTUL00UsKDyIDUclTEOaSghn8iO9fRTzXlwRRoYQBzhUdvIgh6Bad8SFo2q2I1ZpN6N1sJ0FibWK7ir0rgMDus5e3ka68gFcOPDimwVOt8DKdT2zQ9nIyDu+oXWUJwVlBs8oA8Ro9ZCtc3bqsMy2LQEWC9N1dAQk2RIBoBFq49ZMK7j2VNR77Sm0eP4ODSnSH/S2Y3gI7B203s497pOlVLu21LYIa8HZYfpVKV2hTHfjjvwR6W3Eham9TqXHVEM/r8cLfpK1GLim12rkarKjn/FtLOrXM4h/9Kk9 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: On Wed, 4 Jun 2025 11:31:24 -0700 SeongJae Park wrote: > To use DAMON for monitoring access patterns of the system, users should > manually start DAMON via DAMON sysfs ABI with a number of parameters for > specifying the monitoring target address space, address ranges, and > monitoring intervals. After that, users should also wait until desired > amount of time data is captured into DAMON's monitoring results. It is > bothersome and take a long time to be practical for access monitoring on > large fleet level production environments. > > For access-aware system operations use cases like proactive cold memory > reclamation, similar problems existed. We we solved those by > introducing dedicated static kernel modules such as DAMON_RECLAIM. > > Implement such static kernel module for access monitoring, namely > DAMON_STAT. It monitors the entire physical address space with > auto-tuned monitoring intervals. The auto-tuning is set to capture 4 % > of observable access events in each snapshot while keeping the sampling > intervals 5 milliseconds in minimum and 10 seconds in maximum. From > a few production environments, we confirmed this setup provides high > quality monitoring results with minimum overheads. The module therefore > receives only one user input, whether to enable or disable it. It can > be set on build or boot time via build configuration or kernel boot > command line. It can also be overridden at runtime. > > Note that this commit only implements the DAMON control part of the > module. Users could get the monitoring results via > damon:damon_aggregated tracepoint, but that's of course not the > recommended way. Following commits will implement convenient and > optimized ways for serving the monitoring results to users. > > Signed-off-by: SeongJae Park > --- Hi SJ, thank you for this patch! I have been looking forward to it : -) I had a few questions about the init function: [...snip...] > +static int damon_stat_start(void) > +{ > + damon_stat_context = damon_stat_build_ctx(); > + if (!damon_stat_context) > + return -ENOMEM; > + return damon_start(&damon_stat_context, 1, true); > +} > + > +static void damon_stat_stop(void) > +{ > + damon_stop(&damon_stat_context, 1); > + damon_destroy_ctx(damon_stat_context); > +} > + > +static bool damon_stat_init_called; > + > +static int damon_stat_enabled_store( > + const char *val, const struct kernel_param *kp) > +{ > + bool is_enabled = enabled; > + int err; > + > + err = kstrtobool(val, &enabled); > + if (err) > + return err; > + > + if (is_enabled == enabled) > + return 0; > + > + if (!damon_stat_init_called) > + /* > + * probably called from command line parsing (parse_args()). > + * Cannot call damon_new_ctx(). Let damon_stat_init() handle. > + */ > + return 0; I was hoping you could educate me about how damon_stat_init_called works here. I think my confusion comes from my lack of knowledge about kernel modules : -) In the cover letter, you wrote that DAMON_STAT is a static kernel module. My understanding was that this would mean damon_stat_init would always be called, so I was wondering under what condition it would not be initialized. I see the comment you wrote above, but was still a little bit confused. Also, should we perhaps call damon_stat_init() if !damon_stat_init_called? That way, the first caller would just eat up the time it takes to run damon_stat_start(). One other thought I have is that if this config checks for whether damon_stat_init was called, this can be moved to the beginning of the function before the other checks are run, but that is just my thought : -) Feel free to keep the input check first, since having this at the beginning of the function would mean incorrect inputs would be silently ignored. Thank you SJ! I hope you have a great day! Joshua > + if (enabled) > + return damon_stat_start(); > + damon_stat_stop(); > + return 0; > +} > + > +static int __init damon_stat_init(void) > +{ > + int err = 0; > + > + damon_stat_init_called = true; > + > + /* probably set via command line */ > + if (enabled) > + err = damon_stat_start(); > + return err; > +} > + > +module_init(damon_stat_init); > -- > 2.39.5