Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1468321ybb; Thu, 9 Apr 2020 02:45:30 -0700 (PDT) X-Google-Smtp-Source: APiQypJAdw1K4EroeZyztWfBqEGjrya04flt4WqR8VgtxWM12xMVS/0Q8PV99CZkMC5zdnkBY2E3 X-Received: by 2002:aca:cdcd:: with SMTP id d196mr5611941oig.16.1586425530082; Thu, 09 Apr 2020 02:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586425530; cv=none; d=google.com; s=arc-20160816; b=QNoZiqr0irlYzlWyQu/mLy+JENx5w9GRYl8TUBfDvGV6uK840o5ag8trrhmMpsRNN0 pZFw/LY8MTlykxXM2Gbr2kNPNy0tYx7YqatN76Cc4LSQNMGXjLAn/ZTgoMDWIQQ+AxJP R3QFIe/Pzi3Zv3A8lgkqfYnpghMoPtE2zS9nOWPFgd2i5z7/y0Zq7hzit8Je+VePhNip FDIYGKmZxXKF8IVT2GPEtMEpAzt7Gg5Kk6O/R1+NtcPADa3cO23g1KM4pb7zWcbfXUWs 4PmqjbvUB+x2QGnhtPHb+7b/EfoBnt3QVNoJmKO/lD2p9V54/C8uxsXQqZWcYVLocQVw 0YxQ== 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=JM5sUrNXKRJcdMGMKqju9wpkLsnMHLh8mrvocthSOiA=; b=kAmkRgU7V/VXIqAvNyusGrx9NB/RYnWgpQfwlbOe91v89QE/xz7wZeb3IVlp7xb4Ch +y9DNbPkxUBGR5YPIpnFrgk8vVThd2LR483V00KDf+eFQPSU1GOFD8UzQkrabRbQ9VlT 9306y9d31/wHywpUqMg2wc2Cl9FaO+1M/T04zFj3KF8SNCam/bMuxd0q9qC2b9nRtEWO ZFH/VksFsuKTcWFvHl/q02f6+a8c88chyUh7AhLVc8zQr7M4Nsp9MuoKliVh4UPtjyIm AdQ1iGrNQ8q5oYfzWs4EYkeHKJ22tCk11joyc9uOfZl7rLL7inxqEVcQfIRmN5OYHjdj 22OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ORcpdwju; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id j69si3154307oib.93.2020.04.09.02.45.16; Thu, 09 Apr 2020 02:45:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ORcpdwju; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726744AbgDIJof (ORCPT + 99 others); Thu, 9 Apr 2020 05:44:35 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:19563 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726678AbgDIJof (ORCPT ); Thu, 9 Apr 2020 05:44:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1586425475; x=1617961475; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=JM5sUrNXKRJcdMGMKqju9wpkLsnMHLh8mrvocthSOiA=; b=ORcpdwju5i36mdlhScsr5feYqn7wswQiF7gNifwq4GdzTs6EOeQnPWL5 WHkNtin8tXavIu8lkDEwZ+XOqOuYhc3h9ESvpgUhHLhR3kcJ4uEnW+nN1 1scQ8HPCA/MH/YOczarcCztNrE4FJ+Lei7vSOIOqi8KvOAO9Va0BT6TP3 Q=; IronPort-SDR: GznbAMVH7ewBpKdtsJ3sQUEMtalWl/P2BFIN4vgfkQARSVI5kXIJ4bsAcXOgyKormsKvROOcNu Dt2pMSgWnnSw== X-IronPort-AV: E=Sophos;i="5.72,362,1580774400"; d="scan'208";a="24913339" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 09 Apr 2020 09:44:20 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com (Postfix) with ESMTPS id E2548A2391; Thu, 9 Apr 2020 09:44:17 +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; Thu, 9 Apr 2020 09:44:17 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.161.115) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 09:44:03 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 4/4] mm/damon: Make access check configurable Date: Thu, 9 Apr 2020 11:42:32 +0200 Message-ID: <20200409094232.29680-5-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200409094232.29680-1-sjpark@amazon.com> References: <20200409094232.29680-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.115] X-ClientProxiedBy: EX13D15UWB003.ant.amazon.com (10.43.161.138) 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 DAMON assumes the target region is in virtual address space and therefore uses PTE Accessed bit checking for access checking. However, some users might want to use architecture-specific, more accurate and light-weight access checking features. Also, some users might want to use DAMON for different address spaces such as physical memory space, which needs different ways to check the access. This commit allows DAMON users to configure the access check function to their own version. Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 ++ mm/damon.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index a051b5d966ed..188d5b89b303 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -95,6 +95,8 @@ struct damon_ctx { /* callbacks */ void (*init_target_regions)(struct damon_ctx *context); void (*update_target_regions)(struct damon_ctx *context); + void (*prepare_access_checks)(struct damon_ctx *context); + unsigned int (*check_accesses)(struct damon_ctx *context); void (*sample_cb)(struct damon_ctx *context); void (*aggregate_cb)(struct damon_ctx *context); }; diff --git a/mm/damon.c b/mm/damon.c index da0e7efdf1e1..20a66a6307d1 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -59,6 +59,8 @@ static void kdamond_init_vm_regions(struct damon_ctx *ctx); static void kdamond_update_vm_regions(struct damon_ctx *ctx); +static void kdamond_prepare_vm_access_checks(struct damon_ctx *ctx); +static unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx); /* A monitoring context for debugfs interface users. */ static struct damon_ctx damon_user_ctx = { @@ -70,6 +72,8 @@ static struct damon_ctx damon_user_ctx = { .init_target_regions = kdamond_init_vm_regions, .update_target_regions = kdamond_update_vm_regions, + .prepare_access_checks = kdamond_prepare_vm_access_checks, + .check_accesses = kdamond_check_vm_accesses, }; /* @@ -506,7 +510,7 @@ static void damon_mkold(struct mm_struct *mm, unsigned long addr) #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ } -static void damon_prepare_access_check(struct damon_ctx *ctx, +static void damon_prepare_vm_access_check(struct damon_ctx *ctx, struct mm_struct *mm, struct damon_region *r) { r->sampling_addr = damon_rand(ctx, r->ar.start, r->ar.end); @@ -514,7 +518,7 @@ static void damon_prepare_access_check(struct damon_ctx *ctx, damon_mkold(mm, r->sampling_addr); } -static void kdamond_prepare_access_checks(struct damon_ctx *ctx) +static void kdamond_prepare_vm_access_checks(struct damon_ctx *ctx) { struct damon_task *t; struct mm_struct *mm; @@ -525,7 +529,7 @@ static void kdamond_prepare_access_checks(struct damon_ctx *ctx) if (!mm) continue; damon_for_each_region(r, t) - damon_prepare_access_check(ctx, mm, r); + damon_prepare_vm_access_check(ctx, mm, r); mmput(mm); } } @@ -563,7 +567,7 @@ static bool damon_young(struct mm_struct *mm, unsigned long addr, * mm 'mm_struct' for the given virtual address space * r the region to be checked */ -static void damon_check_access(struct damon_ctx *ctx, +static void damon_check_vm_access(struct damon_ctx *ctx, struct mm_struct *mm, struct damon_region *r) { static struct mm_struct *last_mm; @@ -587,7 +591,7 @@ static void damon_check_access(struct damon_ctx *ctx, last_addr = r->sampling_addr; } -static unsigned int kdamond_check_accesses(struct damon_ctx *ctx) +static unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) { struct damon_task *t; struct mm_struct *mm; @@ -599,12 +603,12 @@ static unsigned int kdamond_check_accesses(struct damon_ctx *ctx) if (!mm) continue; damon_for_each_region(r, t) { - damon_check_access(ctx, mm, r); + damon_check_vm_access(ctx, mm, r); max_nr_accesses = max(r->nr_accesses, max_nr_accesses); } - mmput(mm); } + return max_nr_accesses; } @@ -1134,13 +1138,13 @@ static int kdamond_fn(void *data) pr_info("kdamond (%d) starts\n", ctx->kdamond->pid); ctx->init_target_regions(ctx); while (!kdamond_need_stop(ctx)) { - kdamond_prepare_access_checks(ctx); + ctx->prepare_access_checks(ctx); if (ctx->sample_cb) ctx->sample_cb(ctx); usleep_range(ctx->sample_interval, ctx->sample_interval + 1); - max_nr_accesses = kdamond_check_accesses(ctx); + max_nr_accesses = ctx->check_accesses(ctx); if (kdamond_aggregate_interval_passed(ctx)) { kdamond_merge_regions(ctx, max_nr_accesses / 10); -- 2.17.1