Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2898186pxa; Tue, 18 Aug 2020 00:29:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzh5rhvh+QHjOhu5S4+xeWd6JYsKvojF7VqryhJUOFVGdchWq6mujcfr2huoLD1ilcIn80O X-Received: by 2002:a05:6402:22d9:: with SMTP id dm25mr18270130edb.2.1597735764286; Tue, 18 Aug 2020 00:29:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597735764; cv=none; d=google.com; s=arc-20160816; b=Q9G6lplJeMOrj/iSwwVCfGONGw/e0YpzKttBiutNWXfvvdOP7EetGY2s6cMby3y97l v/uiHFlyfgxy3arLMgGPrMwJsBOPLb7NI4MFXsJDM/vJLnRR8+dSyHOVa5UFs/hCr7EW br4xVpNObG7grARHCQZ/XV0whV3HAHGf4MRxZTywlG4HpK6aRVIWHMztYDNPYGiwDM9P JDrIssO60qXz0Iw1qY7c3hVlWIlC7TuzDqOtuQG6ev3FpImxLbttA/oUcFIjNpUH9f31 Lhs2YtBfwsJ8EPwsGcHHSzaZ/YMN8JCdfUAY4rx9b1xPtqfUNKt174oMArE50bNJ5pTN rN0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=SwCQbiqYucE5oscPRIljck7F8gI6oy2A3LLsP/Q11MI=; b=sjv705QisGa6RsrY1sOp5m1Yb4dFJRuR8ex2AEjqkMipEAFz20KjwSv4j9+cREDKPA kiCBm95cmOwGn81zJFaw0eUnHljyCArfImU/zP1nlQe8sNG0RcrNkJa1yhBZb1aoVI/c GzhAxsWMzEqSfk7m387g6lWagxrZVoCT1UAySXEnCPIJ+uDreAmUZNRD/QNrV9Fgwz0U kiLq97ADN+64Pc2VvMQ6BxdkRCDmmZ+rO5LOYjPsCIwNCcGY0EEu1N52/b9fXG8PqgdQ S861VwpQeN22uYWBauaEZv2wg3z3XoBBjgTolXAmOCYt6PJjrYSXS9UXK1zLy6YFi0e5 NJBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=PVvWP2V8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o10si12795949edv.301.2020.08.18.00.29.00; Tue, 18 Aug 2020 00:29:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=PVvWP2V8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726696AbgHRH2I (ORCPT + 99 others); Tue, 18 Aug 2020 03:28:08 -0400 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:62102 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726324AbgHRH2H (ORCPT ); Tue, 18 Aug 2020 03:28:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597735687; x=1629271687; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=SwCQbiqYucE5oscPRIljck7F8gI6oy2A3LLsP/Q11MI=; b=PVvWP2V8BOYeIMT8kHYbHbzw1YNPjQDtomDXkKQiLevLCC4C+mmJyIg1 q4N0vdLK1TW8CxjOD68Y0RSN6/58dkgE1EhdLr3Ibl8uEOD7Y3pa7Rz3J czgXmt7W+whOgqxCv6HREk0BQUFja6HfoSEvuXgRFOipjEHzUudWoxYzX I=; X-IronPort-AV: E=Sophos;i="5.76,326,1592870400"; d="scan'208";a="49836131" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-87a10be6.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 18 Aug 2020 07:28:02 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-87a10be6.us-west-2.amazon.com (Postfix) with ESMTPS id 9842AA1820; Tue, 18 Aug 2020 07:27:59 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 Aug 2020 07:27:58 +0000 Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.73) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 Aug 2020 07:27:41 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v7 07/10] mm/damon/debugfs: Support physical memory monitoring Date: Tue, 18 Aug 2020 09:24:58 +0200 Message-ID: <20200818072501.30396-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200818072501.30396-1-sjpark@amazon.com> References: <20200818072501.30396-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.73] X-ClientProxiedBy: EX13D38UWB002.ant.amazon.com (10.43.161.171) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park This commit makes the debugfs interface to support the physical memory monitoring, in addition to the virtual memory monitoring. Users can do the physical memory monitoring by writing a special keyword, 'paddr\n' to the 'pids' debugfs file. Then, DAMON will check the special keyword and configure the callbacks of the monitoring context for the debugfs user for physical memory. This will internally add one fake monitoring target process, which has pid as -1. Unlike the virtual memory monitoring, DAMON debugfs will not automatically set the monitoring target region. Therefore, users should also set the monitoring target address region using the 'init_regions' debugfs file. While doing this, the 'pid' in the input should be '-1'. Finally, the physical memory monitoring will not automatically terminated because it has fake monitoring target process. The user should explicitly turn off the monitoring by writing 'off' to the 'monitor_on' debugfs file. Signed-off-by: SeongJae Park --- mm/damon.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/mm/damon.c b/mm/damon.c index d0d55656553b..6f078d68c401 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -2113,9 +2113,29 @@ static ssize_t debugfs_target_ids_write(struct file *file, return PTR_ERR(kbuf); nrs = kbuf; - if (!strncmp(kbuf, "pidfd ", 6)) { - received_pidfds = true; - nrs = &kbuf[6]; + if (!strncmp(kbuf, "paddr\n", count)) { + /* Configure the context for physical memory monitoring */ + ctx->init_target_regions = kdamond_init_phys_regions; + ctx->update_target_regions = kdamond_update_phys_regions; + ctx->prepare_access_checks = kdamond_prepare_phys_access_checks; + ctx->check_accesses = kdamond_check_phys_accesses; + ctx->target_valid = NULL; + ctx->cleanup = NULL; + + /* target id is meaningless here, but we set it just for fun */ + snprintf(kbuf, count, "42 "); + } else { + /* Configure the context for virtual memory monitoring */ + ctx->init_target_regions = kdamond_init_vm_regions; + ctx->update_target_regions = kdamond_update_vm_regions; + ctx->prepare_access_checks = kdamond_prepare_vm_access_checks; + ctx->check_accesses = kdamond_check_vm_accesses; + ctx->target_valid = kdamond_vm_target_valid; + ctx->cleanup = kdamond_vm_cleanup; + if (!strncmp(kbuf, "pidfd ", 6)) { + received_pidfds = true; + nrs = &kbuf[6]; + } } targets = str_to_target_ids(nrs, ret, &nr_targets); -- 2.17.1