From patchwork Tue Feb 4 06:23:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11364077 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C98A921 for ; Tue, 4 Feb 2020 06:24:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2FC7E218AC for ; Tue, 4 Feb 2020 06:24:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uEUYAryv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FC7E218AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6611F6B0008; Tue, 4 Feb 2020 01:24:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 611626B000A; Tue, 4 Feb 2020 01:24:03 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D99C6B000C; Tue, 4 Feb 2020 01:24:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id 3004E6B0008 for ; Tue, 4 Feb 2020 01:24:03 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D8292824805A for ; Tue, 4 Feb 2020 06:24:02 +0000 (UTC) X-FDA: 76451454324.21.honey28_40613f7a24833 X-Spam-Summary: 2,0,0,c22228a770b24d2f,d41d8cd98f00b204,sj38.park@gmail.com,:akpm@linux-foundation.org:sjpark@amazon.de:acme@kernel.org:alexander.shishkin@linux.intel.com:amit@kernel.org:brendan.d.gregg@gmail.com:brendanhiggins@google.com:cai@lca.pw:colin.king@canonical.com:corbet@lwn.net:dwmw@amazon.com:jolsa@redhat.com:kirill@shutemov.name:mark.rutland@arm.com:mgorman@suse.de:minchan@kernel.org:mingo@redhat.com:namhyung@kernel.org:peterz@infradead.org:rdunlap@infradead.org:rostedt@goodmis.org:sj38.park@gmail.com:vdavydov.dev@gmail.com::linux-doc@vger.kernel.org:linux-kernel@vger.kernel.org,RULES_HIT:2:41:355:379:541:800:960:968:973:988:989:1260:1345:1359:1437:1535:1605:1606:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:2892:2895:2898:2901:2918:2924:2925:2926:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4119:5007:6261:6653:6742:6743:7576:7903:8908:8957:9413:10004:11026:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12679:12683:12895:13161 :13229:1 X-HE-Tag: honey28_40613f7a24833 X-Filterd-Recvd-Size: 8571 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 4 Feb 2020 06:24:02 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id z124so9113521pgb.13 for ; Mon, 03 Feb 2020 22:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x9XwPpcnrzgrrw2vWDfOiJeo4D6MamUNM5l6+xL07jw=; b=uEUYAryv7P2zxdgxNMrVTxeekTfgrccxN/u4AEhYDIvEzXkHCPZHyM0cOVtf5sGTl5 OM+wkzoea2bsplWFr0OqoTURmZwuM+TYK/WcMNkVSz/raAH6cz0UHo8c+HcLfZyzIcsc OORPROX3zrNRI72fhfhUsECFLpCccHQkRA6rIJAiw+epndmwN/d7fKG4Ifb79LCL6zse Sai2963aHUj6Alx4ci4rAWhXMB6rD+i3EXsYZkLhIZFXaraM+Eccd2eMn9Xn9NCsmXQ0 ZjDmCB/cJqD380DVoJgG2cLvwQY/tlp7ZIWZc7dGpArkRBvlcS61Ns1Pa5+Jr1Ja7HYW QWrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x9XwPpcnrzgrrw2vWDfOiJeo4D6MamUNM5l6+xL07jw=; b=HwxoYmaHk5Dx1NCYHISeNA/JD+YpQT+aPfxFMogtyD8yuTnOZMxH2h/K2xwWwdA9iS BfzhenOY2qqCKL8cUdAUIBh30tXOWLQyTWRHOK0BtqBwmRBgnYG3D7hzuXk6Wan7y566 ghax4y2OEa1a2jhRPMX8cPumtqP3YBsBulXg9X+nT89xYLcaqN0BI4V7iADA2OFjqTlM QRCMtLKw9aS6gYOJiMLV1me503spaWDpQLM5iCAE9rLc9Db6iRwDbFfArdqlBkW2mSUo 32vYmkeifdWuG057EqKmnw+Hq9snGJvYqmHSoD10XEU6/NzGhlig21Aw79g5wBGFCl7C WAGw== X-Gm-Message-State: APjAAAXA1I/44tjGl/hOt9rQ9Vs1XlL3x885GFz+ANLuO0fdHDyoV2Rf yNHBUhvMbO7Zf0HqKQ1rhG4= X-Google-Smtp-Source: APXvYqwzpUW++1KXmfW0MFnVqd4owKGJSsz+q5qQT4TEZZDhWoZ8Ew6f2A8xW5Z9llKdZ2DOkG8YMQ== X-Received: by 2002:a63:1f5b:: with SMTP id q27mr15753698pgm.434.1580797441323; Mon, 03 Feb 2020 22:24:01 -0800 (PST) Received: from localhost.localdomain ([106.254.212.20]) by smtp.gmail.com with ESMTPSA id u26sm21880240pfn.46.2020.02.03.22.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 22:24:00 -0800 (PST) From: sj38.park@gmail.com To: akpm@linux-foundation.org Cc: SeongJae Park , acme@kernel.org, alexander.shishkin@linux.intel.com, amit@kernel.org, brendan.d.gregg@gmail.com, brendanhiggins@google.com, cai@lca.pw, colin.king@canonical.com, corbet@lwn.net, dwmw@amazon.com, jolsa@redhat.com, kirill@shutemov.name, mark.rutland@arm.com, mgorman@suse.de, minchan@kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org, rdunlap@infradead.org, rostedt@goodmis.org, sj38.park@gmail.com, vdavydov.dev@gmail.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/11] mm/damon: Apply dynamic memory mapping changes Date: Tue, 4 Feb 2020 06:23:05 +0000 Message-Id: <20200204062312.19913-5-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204062312.19913-1-sj38.park@gmail.com> References: <20200204062312.19913-1-sj38.park@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park Only a number of parts in the virtual address space of the processes is mapped to physical memory and accessed. Thus, tracking the unmapped address regions is just wasteful. However, tracking every memory mapping change might incur an overhead. For the reason, DAMON applies the dynamic memory mapping changes to the tracking regions only for each of a user-specified time interval (``regions update interval``). Signed-off-by: SeongJae Park --- mm/damon.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/mm/damon.c b/mm/damon.c index 13af2de8e45e..8fb1e090733c 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -60,13 +60,16 @@ struct damon_task { * For each 'sample_interval', DAMON checks whether each region is accessed or * not. It aggregates and keeps the access information (number of accesses to * each region) for 'aggr_interval' and then flushes it to the result buffer if - * an 'aggr_interval' surpassed. + * an 'aggr_interval' surpassed. And for each 'regions_update_interval', damon + * checks whether the memory mapping of the target tasks has changed (e.g., by + * mmap() calls from the applications) and applies the changes. * * All time intervals are in micro-seconds. */ struct damon_ctx { unsigned long sample_interval; unsigned long aggr_interval; + unsigned long regions_update_interval; unsigned long min_nr_regions; unsigned long max_nr_regions; @@ -744,6 +747,87 @@ static void kdamond_split_regions(struct damon_ctx *ctx) damon_split_regions_of(ctx, t); } +/* + * Check whether it is time to check and apply the dynamic mmap changes + * + * Returns true if it is. + */ +static bool kdamond_need_update_regions(struct damon_ctx *ctx) +{ + return damon_check_reset_time_interval(&ctx->last_regions_update, + ctx->regions_update_interval); +} + +static bool damon_intersect(struct damon_region *r, struct region *re) +{ + return !(r->vm_end <= re->start || re->end <= r->vm_start); +} + +/* + * Update damon regions for the three big regions of the given task + * + * t the given task + * bregions the three big regions of the task + */ +static void damon_apply_three_regions(struct damon_ctx *ctx, + struct damon_task *t, struct region bregions[3]) +{ + struct damon_region *r, *next; + unsigned int i = 0; + + /* Remove regions which isn't in the three big regions now */ + damon_for_each_region_safe(r, next, t) { + for (i = 0; i < 3; i++) { + if (damon_intersect(r, &bregions[i])) + break; + } + if (i == 3) + damon_destroy_region(r); + } + + /* Adjust intersecting regions to fit with the threee big regions */ + for (i = 0; i < 3; i++) { + struct damon_region *first = NULL, *last; + struct damon_region *newr; + struct region *br; + + br = &bregions[i]; + /* Get the first and last regions which intersects with br */ + damon_for_each_region(r, t) { + if (damon_intersect(r, br)) { + if (!first) + first = r; + last = r; + } + if (r->vm_start >= br->end) + break; + } + if (!first) { + /* no damon_region intersects with this big region */ + newr = damon_new_region(ctx, br->start, br->end); + damon_add_region(newr, damon_prev_region(r), r); + } else { + first->vm_start = br->start; + last->vm_end = br->end; + } + } +} + +/* + * Update regions for current memory mappings + */ +static void kdamond_update_regions(struct damon_ctx *ctx) +{ + struct region three_regions[3]; + struct damon_task *t; + + damon_for_each_task(ctx, t) { + if (damon_three_regions_of(t, three_regions)) + continue; + damon_apply_three_regions(ctx, t, three_regions); + } +} + /* * Check whether current monitoring should be stopped * @@ -808,6 +892,9 @@ static int kdamond_fn(void *data) kdamond_split_regions(ctx); } + if (kdamond_need_update_regions(ctx)) + kdamond_update_regions(ctx); + usleep_range(ctx->sample_interval, ctx->sample_interval + 1); } damon_flush_rbuffer(ctx); @@ -955,6 +1042,7 @@ static int damon_set_recording(struct damon_ctx *ctx, * * sample_int time interval between samplings * aggr_int time interval between aggregations + * regions_update_int time interval between vma update checks * min_nr_reg minimal number of regions * max_nr_reg maximum number of regions * @@ -964,7 +1052,8 @@ static int damon_set_recording(struct damon_ctx *ctx, * Returns 0 on success, negative error code otherwise. */ static int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int, - unsigned long aggr_int, unsigned long min_nr_reg) + unsigned long aggr_int, unsigned long regions_update_int, + unsigned long min_nr_reg, unsigned long max_nr_reg) { if (min_nr_reg < 3) { pr_err("min_nr_regions (%lu) should be bigger than 2\n", @@ -979,6 +1068,7 @@ static int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int, ctx->sample_interval = sample_int; ctx->aggr_interval = aggr_int; + ctx->regions_update_interval = regions_update_int; ctx->min_nr_regions = min_nr_reg; ctx->max_nr_regions = max_nr_reg; return 0;