Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp265859pxa; Wed, 5 Aug 2020 00:04:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRZTTu4cpmfGFUaOicZfUK88BrwPWlSVi6AgizDEkb/hL+NQTdlie2wLd4XZ7X9W3+QBWy X-Received: by 2002:a17:906:f202:: with SMTP id gt2mr1802878ejb.70.1596611044725; Wed, 05 Aug 2020 00:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596611044; cv=none; d=google.com; s=arc-20160816; b=zavuXw2AnUnopZV0j0QHka+D9M8GTsTnvD/8uX5JmKHVv5rLu/igWvUX42S/9G76q9 HODj4T4dA/LbF8NV2p9u7Lxo39ef6MY+/P2mGr1/FUR5dI3urt6tZPCiaiOuGFtTiSet j/opQa0Pydu92F3cK+bJu1X6qZvacZKm2M5RjoM4zjycNCleCIWSQKxod37JtAqTwktd oywhW6OEIV6T9Wj7+8omBEP3g7QRsz3oQ4MwtflWx1dJo2Z8QBa28IjRTLn595DSSgRo zLgeLF+F1qy/Y1oTGpKHXkV2ejOkoYstGTVD+TaSKmSNVA9fj2ftWCHzVqR7AEYEwMIX Va8w== 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:ironport-sdr:dkim-signature; bh=qEyO3NjOJgBbi06zZ5Eyf5uiQGCDh0wt+SIXSMbxXjs=; b=Ox3x57mx97NdHKeBkPEd3reBd6olkqLThUBl+7+A7vO22AadtiroiaVQC+/2VjNj/m ju0jiuXLUu4tYZcLrmFsgpYqRPaeHSHCWT3apXZpNblx+vlGul1lT/rXXWD2SamgLE3w QrsuDppOA/9WZn7eujpg4JRY5qi7Afl9pBMjRID4XocWBsQDl7v+QwDvk6qWZw1aHEUN JRUdBBKTV8/nVz5gDTuQG1m8DOg2vtodNZpRyebEf62NACAD6MXZ4AmZN/jet4PO4Wes 5NuhQSNbCeMgbOMDg90aGVgGQcqzaZ2/kuoQCvBtJtEaJcxPpeNvhrsv/w25or20iCp5 QY1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=FoBuz7+2; 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 a5si727533ejb.582.2020.08.05.00.03.42; Wed, 05 Aug 2020 00:04:04 -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=FoBuz7+2; 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 S1727808AbgHEHDX (ORCPT + 99 others); Wed, 5 Aug 2020 03:03:23 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:52727 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgHEHDW (ORCPT ); Wed, 5 Aug 2020 03:03:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1596611002; x=1628147002; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=qEyO3NjOJgBbi06zZ5Eyf5uiQGCDh0wt+SIXSMbxXjs=; b=FoBuz7+2lJp0E7qAp5oKkZdnfS7Di8nRhkp5YiqWjk1mDv3QGgrJ7E5B RpTF6ODoSnBIuHFBJx70Z2wu2D3Q/4Kpiye0LBG+Wac9CYtY9L3sButTZ lMAw3d7h7tGilJuYeR75Q1zifNP/zufQt5IjZbo/1AlY0lzRReN+4Rx+o w=; IronPort-SDR: +oMl3lt0gfbUgWw/YdBcmZv1+Cp4lWhZOkuJP030jhL5YT/5WTvhaaVsbCnA44++IV+bR4e9SP NMyzFlBxDkeA== X-IronPort-AV: E=Sophos;i="5.75,436,1589241600"; d="scan'208";a="46228955" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 05 Aug 2020 07:03:21 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com (Postfix) with ESMTPS id BE137A21BF; Wed, 5 Aug 2020 07:03:09 +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; Wed, 5 Aug 2020 07:03:08 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.26) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 5 Aug 2020 07:02:51 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v6 07/10] mm/damon/debugfs: Support physical memory monitoring Date: Wed, 5 Aug 2020 08:59:48 +0200 Message-ID: <20200805065951.18221-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200805065951.18221-1-sjpark@amazon.com> References: <20200805065951.18221-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.26] X-ClientProxiedBy: EX13D24UWB002.ant.amazon.com (10.43.161.159) 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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/mm/damon.c b/mm/damon.c index c8d834ce188d..0b6960f62ae9 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -2035,9 +2035,27 @@ 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; + + /* target id is meaningless here, but we set it just for fun */ + snprintf(kbuf, count, "-1 "); + } 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; + if (!strncmp(kbuf, "pidfd ", 6)) { + received_pidfds = true; + nrs = &kbuf[6]; + } } targets = str_to_target_ids(nrs, ret, &nr_targets); -- 2.17.1