Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3297347ybb; Mon, 6 Apr 2020 06:15:36 -0700 (PDT) X-Google-Smtp-Source: APiQypJ1MneQr0qB9JSIksv2V05n/FvmtwP+gZCYvrunfNmi0fEUfR0A/+I0nBFFKLWTQqe3aC/s X-Received: by 2002:a9d:344:: with SMTP id 62mr18506072otv.102.1586178936805; Mon, 06 Apr 2020 06:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586178936; cv=none; d=google.com; s=arc-20160816; b=vh/z7vN6SRFaBne/d73FxfXJ3MK0c3dFmQa2MyQzyGVY9jdkkunvxNEC3XqqU3QgUk RLfmzEuaVr8PieNeSa2SNFsLzDffefmdtclmG5htRwixxWXRlqxbRKtrlj31Yo53gcwR m/2KLA7oAWcBq8vZHZ39vt6Sl361V5+kjHxd48d4mVN0AXR6qmzuvyUj0+QH92XxyLVg cz4toaDPhLWGBdd0/L8goGJCFUJeDziLMf+6KXTCUffCK/RO4k20AL+DBx0i1vJ2KtTR xZSBx2HDui5Cvz19YbUdNcG9rvYIpizInnWgN+AGPJsodgXCbnLViTJD/SY7lT5gHWJP m58Q== 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=xjZkneBUveUkovP0qf4dvlI7qTPmP9m2LFnwSnSWkCg=; b=WFlcthmi8j+H/dGtgTxNQ1/Fjc4hDgFzsEcZ5n7l5pmklutQK8qLQYhLKu2heAmoGt XWuxN12DOB4obBhSvRmfwjDWDNB5xC2PXjdYxto/xP3aNBxmSgAb+uJABsnkhmHaqk6n 7Nt7B2fkvmvf6vpuKx8bAaIT+48tsFSCH7igfnUZe/2P/65fmPciNr44VZGtOFCC9gzG 9tnAk5n7OXGmmo5HA60LfQgvkJsQCvl6MOV8e5A8Gx9JntMpI+WN/iH1SyRmAtEDraqK dkwMaRlD//d7x6gfJZOuKQAiGU0bgHuoRQuFODWxQPHKq740/ulhhwphdR6pp4LqJEVT l6wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=YNMWEFRb; 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 r71si7344467oie.265.2020.04.06.06.15.24; Mon, 06 Apr 2020 06:15:36 -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=YNMWEFRb; 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 S1728314AbgDFNOk (ORCPT + 99 others); Mon, 6 Apr 2020 09:14:40 -0400 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:18057 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728193AbgDFNOk (ORCPT ); Mon, 6 Apr 2020 09:14:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1586178879; x=1617714879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=xjZkneBUveUkovP0qf4dvlI7qTPmP9m2LFnwSnSWkCg=; b=YNMWEFRbwNPMaX8w+Jm3cwNdqF6CluaWU/UoYv67/DDTJ4fXoCDSb+40 ypp2IcvhQnH3bS/qGY3BWsOwKfOLi4tYqZxmiqfWYXDZCtnN4rpoTOiWz RE09RX8LBlRlW+WOw7zGeWW3h1KL6K2Nb4eg8XPDoJWL4c1THN1DuqCkC Y=; IronPort-SDR: 7exDCaXD0/dqwecCJlkZBrNslf25aZLciAE5ha0qyGQ1BnfldCehPJMIzITBKBd453YqICXWYp G5hZBWAfy/+w== X-IronPort-AV: E=Sophos;i="5.72,351,1580774400"; d="scan'208";a="24290807" 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-6002.iad6.amazon.com with ESMTP; 06 Apr 2020 13:14:25 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com (Postfix) with ESMTPS id 7C32EA24B6; Mon, 6 Apr 2020 13:14:15 +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; Mon, 6 Apr 2020 13:14:14 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.65) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 6 Apr 2020 13:14:00 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v8 07/15] mm/damon: Implement callbacks Date: Mon, 6 Apr 2020 15:09:30 +0200 Message-ID: <20200406130938.14066-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200406130938.14066-1-sjpark@amazon.com> References: <20200406130938.14066-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.65] X-ClientProxiedBy: EX13D11UWB003.ant.amazon.com (10.43.161.206) 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 implements callbacks for DAMON. Using this, DAMON users can install their callbacks for each step of the access monitoring so that they can do something interesting with the monitored access patterns online. For example, callbacks can report the monitored patterns to users or do some access pattern based memory management such as proactive reclamations or access pattern based THP promotions/demotions decision makings. Signed-off-by: SeongJae Park --- include/linux/damon.h | 4 ++++ mm/damon.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 64e327400749..cad3ee3d78db 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -56,6 +56,10 @@ struct damon_ctx { struct rnd_state rndseed; struct list_head tasks_list; /* 'damon_task' objects */ + + /* callbacks */ + void (*sample_cb)(struct damon_ctx *context); + void (*aggregate_cb)(struct damon_ctx *context); }; int damon_set_pids(struct damon_ctx *ctx, unsigned long *pids, ssize_t nr_pids); diff --git a/mm/damon.c b/mm/damon.c index acbcd702ef0c..608787e88118 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -821,6 +821,8 @@ static int kdamond_fn(void *data) kdamond_init_regions(ctx); while (!kdamond_need_stop(ctx)) { kdamond_prepare_access_checks(ctx); + if (ctx->sample_cb) + ctx->sample_cb(ctx); usleep_range(ctx->sample_interval, ctx->sample_interval + 1); @@ -828,6 +830,8 @@ static int kdamond_fn(void *data) if (kdamond_aggregate_interval_passed(ctx)) { kdamond_merge_regions(ctx, max_nr_accesses / 10); + if (ctx->aggregate_cb) + ctx->aggregate_cb(ctx); kdamond_reset_aggregated(ctx); kdamond_split_regions(ctx); } -- 2.17.1