From patchwork Tue Dec 10 21:50:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13902110 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 6AEF8E77183 for ; Tue, 10 Dec 2024 21:50:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 996776B0274; Tue, 10 Dec 2024 16:50:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91E2F6B0275; Tue, 10 Dec 2024 16:50:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E6FF8D0013; Tue, 10 Dec 2024 16:50:41 -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 592856B0274 for ; Tue, 10 Dec 2024 16:50:41 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 04B8B120F25 for ; Tue, 10 Dec 2024 21:50:41 +0000 (UTC) X-FDA: 82880393610.26.149DC10 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf03.hostedemail.com (Postfix) with ESMTP id 595B020008 for ; Tue, 10 Dec 2024 21:50:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bl7caDxm; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1733867429; 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=/WUPRywr9T2lNCgWCZ770NBeqkLMpVh9VEeQt8UmtbM=; b=3B1rBywAdYP/WRitmK+DrBoFP64fJh754uFFYLsf2xl64GQ7FklLAdLudlMqUSbBKXP62p atgpovORBIoT8sdzqzEo6kv/hHSQArRb/yFBvVZgmqHiZMEEXXmxgHclhe9X5rZ+tiC3KP iVaBJxZxSjKQkanUIHNseoQ/bJVbSWY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733867429; a=rsa-sha256; cv=none; b=Xv7xXtrqus4au6e2XL2FEnOGVX3oNzAUTCCQcxD0HfDopQpz7jfqhVteOArgkBR4TsNh+6 3xj/OMu1bIs2qAs9TrG+km3or6JPg9pgfluoRxzvFxM437OIAFncMDsReTcCvCofkPEnE5 5EXoZ6bitToV48El2LITYTUPCDV1qP4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bl7caDxm; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 71194A41AC9; Tue, 10 Dec 2024 21:48:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55444C4CED6; Tue, 10 Dec 2024 21:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733867438; bh=hoi3YSqqOR9ePv9N3p8sOerDMAcJ+RMcuGrppxt+mz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bl7caDxmLeYr/o8tpYrjKbJRh6DULZtvH6VaBGKNqJ9E7gVsm/G00XYnAtxCqsxPn i8J260Ruy88dw6OYY3lGAg0E+gPFiX7P5FIql/AG4y/rdPuOCUkqofbaK0livJSP44 lwYtDlRNDcM0D6j4hpOKd0DlDK8F98uiP5Iddddck8qscsnNbCo3RUVg++r9aEOsug THFGw1CoXBGjE/CMQNAwPlr8y0Hxqd2cNI+M2WQhks2hZ6VLsa6Tf2KY/qYE3+rQkO /5P71yilA08C4due9Nrh6c5J3NjAq2SAnay8Iq1do/5xn6/R9cKK0BPbzJcR/kDF2w 0bx+PLksRF9iw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 2/5] samples/damon/wsse: start and stop DAMON as the user requests Date: Tue, 10 Dec 2024 13:50:27 -0800 Message-Id: <20241210215030.85675-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241210215030.85675-1-sj@kernel.org> References: <20241210215030.85675-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: w5xn5fcp8w4y47hytiz5h56d137hde5a X-Rspamd-Queue-Id: 595B020008 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733867429-609690 X-HE-Meta: U2FsdGVkX18s9Tm39Op5P/W3GzFWLEwqE9EAHaetf7Nl35IsI1udqp91AQJgFd60nA+ecMA0xIctdOmnD4QhtfC7alpuEDQw5J6wey0EWVwczkczPP5bZif9odPWdpQXZmBxT+tHepY15ny1in+IvDRfn9mCCxSlvhDNLcy+uOziHmOkJIhQU+ff3se72sc8gyupEEPeFQZD47lJXOVTBNFNewybspCqu7s4Sb/B6IUgVKCJ50rZQb9WogPUm0w2DGk4bvgUdo4a9ogYArFcxDJv/0wvwqOEGJ4wdpMTDCwsEEiMGqzSTRFfrap/A7mRIt33vpuiyJLEf5KKKeJR7N5RJlJ+BbpH4c43zetw993XlUaiAl+aRaBqwEr0TmPR4pRjB8VutWH+8PmkWailjF0y0P2UxEBEKs90CcSuVlxkFgkEoEPNwPaWMzWTD+EZWHb0Nid84t97EQT//8BCmxyc21tZYWzDVzq5n1QbZJrzy+jzPk/bW1aGDHUhQH9rUb0QGvXFWFWnp3ZRZnOtPGAasIB3AL+Guh/Moxeo0Xu0lwH71ntj6PeWzsYDOQdaFBqjF06+bVZbM+Q5l24l0qpPww0WcDA6L+vCGwyXm6EM99sVjIdjGJRqbYoZ8ThJOux2lfrtxe18X7Bj5a0gqONG6l3p+nKDPGvyWRUU7vq+Goch0PYecVJLlMRoXjDG0MhC/FE2vCtsVo30of5alnoT7VtZFj3bcVStFRA/9LfmPPz26Jc5C1cZOc2jp2FGoBC1qrXgL2VpZeQG9JLHU2czUoI/ozgdnrab5aZKBezhA5tEs/j+78mWCuaTZLvGNftYkP8REFal0B+PymjmyaDcQeLmnfxO2bqfXN0xGLSttClT8VjG5XhDyq4EbU85Bbp+2mJSH1TuWQyrSdQqsmwWtmEoTOI6Fo1xIcESO/iZPJGy4+lIS8DTvOGezEapGSw7BcYrRXG2G8QJkyv LzMcAL/I btw4e9ibUVRt9wL4xdo2YwctaemIB7gxm4nbzZwX9P/JaujB2SilHd48JrKq8nQeOpivuhAe/W1Isak4oFOfU5gF6eTu2S8fi3Z4mW73XtDwmUIRBmuMUHj1v8fRGLZ/cTQM0C3ZR5Cgn/hDoqzVaQ9gDkgOwl2DMTOR/2REpAqOUk+mJZkZ1EfyWWIhZqiPG8pLqF3wwO0NZ3/FUx9XXUR0sr089FJt6ZrlawoGizYBuDxg= 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: Start running DAMON to monitor accesses of a process that the user specified via 'target_pid' parameter, when 'y' is passed to 'enable' parameter. Stop running DAMON when 'n' is passed to 'enable' parameter. Estimating the working set size from DAMON's monitoring results and reporting it to the user will be implemented by the following commit. Signed-off-by: SeongJae Park --- samples/damon/wsse.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c index 7f2cb76a1a70..2ba0c91baad9 100644 --- a/samples/damon/wsse.c +++ b/samples/damon/wsse.c @@ -27,15 +27,48 @@ static bool enable __read_mostly; module_param_cb(enable, &enable_param_ops, &enable, 0600); MODULE_PARM_DESC(enable, "Enable or disable DAMON_SAMPLE_WSSE"); +static struct damon_ctx *ctx; +static struct pid *target_pidp; + static int damon_sample_wsse_start(void) { + struct damon_target *target; + pr_info("start\n"); - return 0; + + ctx = damon_new_ctx(); + if (!ctx) + return -ENOMEM; + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target = damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + target_pidp = find_get_pid(target_pid); + if (!target_pidp) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + target->pid = target_pidp; + + return damon_start(&ctx, 1, true); } static void damon_sample_wsse_stop(void) { pr_info("stop\n"); + if (ctx) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } + if (target_pidp) + put_pid(target_pidp); } static int damon_sample_wsse_enable_store(