Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp537224ybg; Wed, 3 Jun 2020 07:17:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPBTETZNCYOXUhvoyMIKj5eWiKMe79yJObHAYp4Y/ADE/K2pvmLi3IysYg3F9RfHWX0omM X-Received: by 2002:a17:906:b7cd:: with SMTP id fy13mr29138795ejb.133.1591193858276; Wed, 03 Jun 2020 07:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591193858; cv=none; d=google.com; s=arc-20160816; b=0zd7GYDtK8LBaIdL+Nt9Y8XLt6NN2ooa0KkVHBGdpkN4jq51KNPDNXgovjFF4KNxzv 1K8APaJZX8p6DUNopPF9n2Y51qt6uoYGIA2mWlbU23323ennqR0r6/H2l2QebhrBrU2B ajwr8vdkOJ7OA5B1eBgTQJ5PyLcqwCdElJEW9N/C1oEPN0ManIOYup5gtvvZb6KDBku8 TNAoupsw+8lrNq4eet+PU17ecogH4CQThL6zMP+i1GILtxTMt1r+cT82fiaUs0bycmQ0 cUzm0Pi0DZXw67ymT1mmASTDWiHMLSYoplGZeAYkZohqvJAc9dkeQjv3j+GD3fJBzYPH dQZA== 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=SRYgykF0yAohy2O2/4bBvbIs8aFrlPW/NT2qDFyZwWE=; b=WW7a35hDJZPtOivUzVDrISdqeq6CMEG/0J2/7GU1zDVqANkA07xyE8Idv23HV2W+9c GXRwRejJMNXcdiTq1gznaN35AJ8O3uos+sw+YcBIUP+rD9TL/WzQP2BZlWZxRFU5s3rB LWeNDRyG4HoiAF327MD4x5kHptiIMi8dW+zv9t6i/1VaCaxPuOxWFVIErz90EqQjO7pa Qz8YyRNCZ7+kLKxeC2Ee515PE13q9n7qXybkaX5bccJ64vXuKQ1pRqqK2y09cag/UtB1 eK/Ul9e/7zF1KlEmEshQj/OTc2czYBA7cqu7pq80PGjyPNdOmjVSNYn2r4HRW8hihoVQ Ucdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b="vbUCOu/7"; 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 gv4si1041685ejb.565.2020.06.03.07.17.15; Wed, 03 Jun 2020 07:17:38 -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="vbUCOu/7"; 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 S1726192AbgFCOOm (ORCPT + 99 others); Wed, 3 Jun 2020 10:14:42 -0400 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:54367 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725882AbgFCOOl (ORCPT ); Wed, 3 Jun 2020 10:14:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591193680; x=1622729680; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=SRYgykF0yAohy2O2/4bBvbIs8aFrlPW/NT2qDFyZwWE=; b=vbUCOu/74qRdQK4VKPBpFZRcImn4bkwLASUcIkQDCHaJnJYUDbAf1fqm 0J58ZcUJ7gGOBTpjM/zoefjnAAm8TiDGHkAdS7YfroduhJsRCW3GvI06y Bv6HgjEyUE6UbyHOV86jvm5Q61qe1qisTGPmxcHtWk/agyJ2sWLiqMRRF g=; IronPort-SDR: 1kL31in7XtdjkETvtVd2fzBeZmIrdTWw1WeU3Rr7AK11SdSlFGC1OsaKPzcRq//dMRCiZ9uBym zSbFg8kH0BAQ== X-IronPort-AV: E=Sophos;i="5.73,467,1583193600"; d="scan'208";a="41265283" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-119b4f96.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 03 Jun 2020 14:14:40 +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-119b4f96.us-west-2.amazon.com (Postfix) with ESMTPS id C67E51A18E6; Wed, 3 Jun 2020 14:14:37 +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, 3 Jun 2020 14:14:37 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.90) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 3 Jun 2020 14:14:21 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v2 6/9] mm/damon: Make access check primitive configurable Date: Wed, 3 Jun 2020 16:11:32 +0200 Message-ID: <20200603141135.10575-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603141135.10575-1-sjpark@amazon.com> References: <20200603141135.10575-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.90] X-ClientProxiedBy: EX13D45UWB002.ant.amazon.com (10.43.161.78) 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, as some CPU provides H/W based memory access check features that usually more accurate and light-weight than PTE Accessed bit checking, some users would want to use those in special use cases. 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 therefore allows DAMON users to configure the low level access check primitives as they want. Signed-off-by: SeongJae Park --- include/linux/damon.h | 13 +++++++++++-- mm/damon.c | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index a1b6810ce0eb..1a788bfd1b4e 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -160,13 +160,18 @@ struct damos { * * @init_target_regions: Constructs initial monitoring target regions. * @update_target_regions: Updates monitoring target regions. + * @prepare_access_checks: Prepares next access check of target regions. + * @check_accesses: Checks the access of target regions. * @sample_cb: Called for each sampling interval. * @aggregate_cb: Called for each aggregation interval. * * The monitoring thread calls @init_target_regions before starting the - * monitoring, @update_target_regions for each @regions_update_interval. By + * monitoring, @update_target_regions for each @regions_update_interval, and + * @prepare_access_checks and @check_accesses for each @sample_interval. By * setting these callbacks to appropriate functions, therefore, users can - * monitor specific range of virtual address space. + * monitor any address space with special handling. If these are not + * explicitly configured, the functions for virtual memory address space + * monitoring are used. * * @sample_cb and @aggregate_cb are called from @kdamond for each of the * sampling intervals and aggregation intervals, respectively. Therefore, @@ -199,6 +204,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); }; @@ -206,6 +213,8 @@ struct damon_ctx { /* Reference callback implementations for virtual memory */ void kdamond_init_vm_regions(struct damon_ctx *ctx); void kdamond_update_vm_regions(struct damon_ctx *ctx); +void kdamond_prepare_vm_access_checks(struct damon_ctx *ctx); +unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx); int damon_set_pids(struct damon_ctx *ctx, int *pids, ssize_t nr_pids); int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int, diff --git a/mm/damon.c b/mm/damon.c index c7806e81248a..f5cbc97a3bbc 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -75,6 +75,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, }; /* @@ -507,7 +509,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(r->ar.start, r->ar.end); @@ -515,7 +517,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) +void kdamond_prepare_vm_access_checks(struct damon_ctx *ctx) { struct damon_task *t; struct mm_struct *mm; @@ -526,7 +528,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); } } @@ -564,7 +566,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; @@ -588,7 +590,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) +unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) { struct damon_task *t; struct mm_struct *mm; @@ -600,12 +602,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; } @@ -1111,13 +1113,13 @@ static int kdamond_fn(void *data) kdamond_write_record_header(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