From patchwork Tue Jun 9 14:19:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595809 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 1219790 for ; Tue, 9 Jun 2020 14:20:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A8D682078D for ; Tue, 9 Jun 2020 14:20:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fpBTw6jc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8D682078D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B24E66B0002; Tue, 9 Jun 2020 10:20:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AD3926B0003; Tue, 9 Jun 2020 10:20:50 -0400 (EDT) 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 99BCA6B0005; Tue, 9 Jun 2020 10:20:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 7C5DC6B0002 for ; Tue, 9 Jun 2020 10:20:50 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 35BC6FB63 for ; Tue, 9 Jun 2020 14:20:50 +0000 (UTC) X-FDA: 76909884660.04.light09_0c08f8626dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 11BF481352D5 for ; Tue, 9 Jun 2020 14:20:50 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30004:30012:30054:30064:30070:30075,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: light09_0c08f8626dc3 X-Filterd-Recvd-Size: 23913 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:20:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712450; x=1623248450; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=QfG5eKoD+sZ//7OiS8Fehvn0otmU61iX4KRNGPgG1BA=; b=fpBTw6jc3b4K04m+pIX4CKAl6XxqCm0yj0d9/LK73gdqLcocR2t0EOdT yAClgv88U8vJE0/5nu+VIi5HQLJS6yu+4aJO+0bCc54gnl1ocSkGwZszY BExCrJ+hnZLEuz+AizBIh4GCFJ8SAYwlgS7bZ/D37m+q7ZlTcJA0waewq 0=; IronPort-SDR: E42dogMr/dT/P/eMFkUcyxmW31bPAboJCxDhedHmjnCGWokaAT4DBH62rcQTO+MS7foDk6NUvn qnkjIWgQjU4g== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="36625790" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-17c49630.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 09 Jun 2020 14:20:49 +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-17c49630.us-east-1.amazon.com (Postfix) with ESMTPS id E5708A2007; Tue, 9 Jun 2020 14:20: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; Tue, 9 Jun 2020 14:20:37 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:20:19 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 01/10] mm/damon: Use vm-independent address range concept Date: Tue, 9 Jun 2020 16:19:32 +0200 Message-ID: <20200609141941.19184-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 11BF481352D5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 DAMON's main idea is not limited to virtual address space. To prepare for further expansion of the support for other address spaces including physical memory, this commit modifies one of its core struct, 'struct damon_region' to use virtual memory independent address space concept, and cleans up the code using it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 20 +++++--- include/trace/events/damon.h | 4 +- mm/damon-test.h | 78 +++++++++++++++--------------- mm/damon.c | 94 +++++++++++++++++------------------- 4 files changed, 98 insertions(+), 98 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index e77256cf30dd..b4b06ca905a2 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -16,11 +16,18 @@ #include /** - * struct damon_region - Represents a monitoring target region of - * [@vm_start, @vm_end). - * - * @vm_start: Start address of the region (inclusive). - * @vm_end: End address of the region (exclusive). + * struct damon_addr_range - Represents an address region of [@start, @end). + * @start: Start address of the region (inclusive). + * @end: End address of the region (exclusive). + */ +struct damon_addr_range { + unsigned long start; + unsigned long end; +}; + +/** + * struct damon_region - Represents a monitoring target region. + * @ar: The address range of the region. * @sampling_addr: Address of the sample for the next access check. * @nr_accesses: Access frequency of this region. * @list: List head for siblings. @@ -33,8 +40,7 @@ * region are set as region size-weighted average of those of the two regions. */ struct damon_region { - unsigned long vm_start; - unsigned long vm_end; + struct damon_addr_range ar; unsigned long sampling_addr; unsigned int nr_accesses; struct list_head list; diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h index fd260463d5b8..471b6e49960f 100644 --- a/include/trace/events/damon.h +++ b/include/trace/events/damon.h @@ -27,8 +27,8 @@ TRACE_EVENT(damon_aggregated, TP_fast_assign( __entry->pid = t->pid; __entry->nr_regions = nr_regions; - __entry->vm_start = r->vm_start; - __entry->vm_end = r->vm_end; + __entry->vm_start = r->ar.start; + __entry->vm_end = r->ar.end; __entry->nr_accesses = r->nr_accesses; ), diff --git a/mm/damon-test.h b/mm/damon-test.h index 5b18619efe72..6d01f0e782d5 100644 --- a/mm/damon-test.h +++ b/mm/damon-test.h @@ -78,8 +78,8 @@ static void damon_test_regions(struct kunit *test) struct damon_task *t; r = damon_new_region(&damon_user_ctx, 1, 2); - KUNIT_EXPECT_EQ(test, 1ul, r->vm_start); - KUNIT_EXPECT_EQ(test, 2ul, r->vm_end); + KUNIT_EXPECT_EQ(test, 1ul, r->ar.start); + KUNIT_EXPECT_EQ(test, 2ul, r->ar.end); KUNIT_EXPECT_EQ(test, 0u, r->nr_accesses); t = damon_new_task(42); @@ -177,7 +177,7 @@ static void damon_test_set_recording(struct kunit *test) */ static void damon_test_three_regions_in_vmas(struct kunit *test) { - struct region regions[3] = {0,}; + struct damon_addr_range regions[3] = {0,}; /* 10-20-25, 200-210-220, 300-305, 307-330 */ struct vm_area_struct vmas[] = { (struct vm_area_struct) {.vm_start = 10, .vm_end = 20}, @@ -267,7 +267,7 @@ static void damon_test_aggregate(struct kunit *test) KUNIT_EXPECT_EQ(test, 3, it); /* The aggregated information should be written in the buffer */ - sr = sizeof(r->vm_start) + sizeof(r->vm_end) + sizeof(r->nr_accesses); + sr = sizeof(r->ar.start) + sizeof(r->ar.end) + sizeof(r->nr_accesses); sp = sizeof(t->pid) + sizeof(unsigned int) + 3 * sr; sz = sizeof(struct timespec64) + sizeof(unsigned int) + 3 * sp; KUNIT_EXPECT_EQ(test, (unsigned int)sz, ctx->rbuf_offset); @@ -331,7 +331,7 @@ static struct damon_region *__nth_region_of(struct damon_task *t, int idx) */ static void damon_do_test_apply_three_regions(struct kunit *test, unsigned long *regions, int nr_regions, - struct region *three_regions, + struct damon_addr_range *three_regions, unsigned long *expected, int nr_expected) { struct damon_task *t; @@ -350,8 +350,8 @@ static void damon_do_test_apply_three_regions(struct kunit *test, for (i = 0; i < nr_expected / 2; i++) { r = __nth_region_of(t, i); - KUNIT_EXPECT_EQ(test, r->vm_start, expected[i * 2]); - KUNIT_EXPECT_EQ(test, r->vm_end, expected[i * 2 + 1]); + KUNIT_EXPECT_EQ(test, r->ar.start, expected[i * 2]); + KUNIT_EXPECT_EQ(test, r->ar.end, expected[i * 2 + 1]); } damon_cleanup_global_state(); @@ -369,10 +369,10 @@ static void damon_test_apply_three_regions1(struct kunit *test) unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, 70, 80, 80, 90, 90, 100}; /* 5-27, 45-55, 73-104 */ - struct region new_three_regions[3] = { - (struct region){.start = 5, .end = 27}, - (struct region){.start = 45, .end = 55}, - (struct region){.start = 73, .end = 104} }; + struct damon_addr_range new_three_regions[3] = { + (struct damon_addr_range){.start = 5, .end = 27}, + (struct damon_addr_range){.start = 45, .end = 55}, + (struct damon_addr_range){.start = 73, .end = 104} }; /* 5-20-27, 45-55, 73-80-90-104 */ unsigned long expected[] = {5, 20, 20, 27, 45, 55, 73, 80, 80, 90, 90, 104}; @@ -391,10 +391,10 @@ static void damon_test_apply_three_regions2(struct kunit *test) unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, 70, 80, 80, 90, 90, 100}; /* 5-27, 56-57, 65-104 */ - struct region new_three_regions[3] = { - (struct region){.start = 5, .end = 27}, - (struct region){.start = 56, .end = 57}, - (struct region){.start = 65, .end = 104} }; + struct damon_addr_range new_three_regions[3] = { + (struct damon_addr_range){.start = 5, .end = 27}, + (struct damon_addr_range){.start = 56, .end = 57}, + (struct damon_addr_range){.start = 65, .end = 104} }; /* 5-20-27, 56-57, 65-80-90-104 */ unsigned long expected[] = {5, 20, 20, 27, 56, 57, 65, 80, 80, 90, 90, 104}; @@ -415,10 +415,10 @@ static void damon_test_apply_three_regions3(struct kunit *test) unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, 70, 80, 80, 90, 90, 100}; /* 5-27, 61-63, 65-104 */ - struct region new_three_regions[3] = { - (struct region){.start = 5, .end = 27}, - (struct region){.start = 61, .end = 63}, - (struct region){.start = 65, .end = 104} }; + struct damon_addr_range new_three_regions[3] = { + (struct damon_addr_range){.start = 5, .end = 27}, + (struct damon_addr_range){.start = 61, .end = 63}, + (struct damon_addr_range){.start = 65, .end = 104} }; /* 5-20-27, 61-63, 65-80-90-104 */ unsigned long expected[] = {5, 20, 20, 27, 61, 63, 65, 80, 80, 90, 90, 104}; @@ -440,10 +440,10 @@ static void damon_test_apply_three_regions4(struct kunit *test) unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, 70, 80, 80, 90, 90, 100}; /* 5-7, 30-32, 65-68 */ - struct region new_three_regions[3] = { - (struct region){.start = 5, .end = 7}, - (struct region){.start = 30, .end = 32}, - (struct region){.start = 65, .end = 68} }; + struct damon_addr_range new_three_regions[3] = { + (struct damon_addr_range){.start = 5, .end = 7}, + (struct damon_addr_range){.start = 30, .end = 32}, + (struct damon_addr_range){.start = 65, .end = 68} }; /* expect 5-7, 30-32, 65-68 */ unsigned long expected[] = {5, 7, 30, 32, 65, 68}; @@ -470,8 +470,8 @@ static void damon_test_split_evenly(struct kunit *test) i = 0; damon_for_each_region(r, t) { - KUNIT_EXPECT_EQ(test, r->vm_start, i++ * 10); - KUNIT_EXPECT_EQ(test, r->vm_end, i * 10); + KUNIT_EXPECT_EQ(test, r->ar.start, i++ * 10); + KUNIT_EXPECT_EQ(test, r->ar.end, i * 10); } damon_free_task(t); @@ -485,11 +485,11 @@ static void damon_test_split_evenly(struct kunit *test) damon_for_each_region(r, t) { if (i == 4) break; - KUNIT_EXPECT_EQ(test, r->vm_start, 5 + 10 * i++); - KUNIT_EXPECT_EQ(test, r->vm_end, 5 + 10 * i); + KUNIT_EXPECT_EQ(test, r->ar.start, 5 + 10 * i++); + KUNIT_EXPECT_EQ(test, r->ar.end, 5 + 10 * i); } - KUNIT_EXPECT_EQ(test, r->vm_start, 5 + 10 * i); - KUNIT_EXPECT_EQ(test, r->vm_end, 59ul); + KUNIT_EXPECT_EQ(test, r->ar.start, 5 + 10 * i); + KUNIT_EXPECT_EQ(test, r->ar.end, 59ul); damon_free_task(t); t = damon_new_task(42); @@ -499,8 +499,8 @@ static void damon_test_split_evenly(struct kunit *test) KUNIT_EXPECT_EQ(test, nr_damon_regions(t), 1u); damon_for_each_region(r, t) { - KUNIT_EXPECT_EQ(test, r->vm_start, 5ul); - KUNIT_EXPECT_EQ(test, r->vm_end, 6ul); + KUNIT_EXPECT_EQ(test, r->ar.start, 5ul); + KUNIT_EXPECT_EQ(test, r->ar.end, 6ul); } damon_free_task(t); } @@ -514,12 +514,12 @@ static void damon_test_split_at(struct kunit *test) r = damon_new_region(&damon_user_ctx, 0, 100); damon_add_region(r, t); damon_split_region_at(&damon_user_ctx, r, 25); - KUNIT_EXPECT_EQ(test, r->vm_start, 0ul); - KUNIT_EXPECT_EQ(test, r->vm_end, 25ul); + KUNIT_EXPECT_EQ(test, r->ar.start, 0ul); + KUNIT_EXPECT_EQ(test, r->ar.end, 25ul); r = damon_next_region(r); - KUNIT_EXPECT_EQ(test, r->vm_start, 25ul); - KUNIT_EXPECT_EQ(test, r->vm_end, 100ul); + KUNIT_EXPECT_EQ(test, r->ar.start, 25ul); + KUNIT_EXPECT_EQ(test, r->ar.end, 100ul); damon_free_task(t); } @@ -539,8 +539,8 @@ static void damon_test_merge_two(struct kunit *test) damon_add_region(r2, t); damon_merge_two_regions(r, r2); - KUNIT_EXPECT_EQ(test, r->vm_start, 0ul); - KUNIT_EXPECT_EQ(test, r->vm_end, 300ul); + KUNIT_EXPECT_EQ(test, r->ar.start, 0ul); + KUNIT_EXPECT_EQ(test, r->ar.end, 300ul); KUNIT_EXPECT_EQ(test, r->nr_accesses, 16u); i = 0; @@ -577,8 +577,8 @@ static void damon_test_merge_regions_of(struct kunit *test) KUNIT_EXPECT_EQ(test, nr_damon_regions(t), 5u); for (i = 0; i < 5; i++) { r = __nth_region_of(t, i); - KUNIT_EXPECT_EQ(test, r->vm_start, saddrs[i]); - KUNIT_EXPECT_EQ(test, r->vm_end, eaddrs[i]); + KUNIT_EXPECT_EQ(test, r->ar.start, saddrs[i]); + KUNIT_EXPECT_EQ(test, r->ar.end, eaddrs[i]); } damon_free_task(t); } diff --git a/mm/damon.c b/mm/damon.c index 98fd32ace6f7..fcd919e96754 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -95,7 +95,7 @@ static struct damon_ctx damon_user_ctx = { * Returns the pointer to the new struct if success, or NULL otherwise */ static struct damon_region *damon_new_region(struct damon_ctx *ctx, - unsigned long vm_start, unsigned long vm_end) + unsigned long start, unsigned long end) { struct damon_region *region; @@ -103,8 +103,8 @@ static struct damon_region *damon_new_region(struct damon_ctx *ctx, if (!region) return NULL; - region->vm_start = vm_start; - region->vm_end = vm_end; + region->ar.start = start; + region->ar.end = end; region->nr_accesses = 0; INIT_LIST_HEAD(®ion->list); @@ -296,16 +296,16 @@ static int damon_split_region_evenly(struct damon_ctx *ctx, if (!r || !nr_pieces) return -EINVAL; - orig_end = r->vm_end; - sz_orig = r->vm_end - r->vm_start; + orig_end = r->ar.end; + sz_orig = r->ar.end - r->ar.start; sz_piece = ALIGN_DOWN(sz_orig / nr_pieces, MIN_REGION); if (!sz_piece) return -EINVAL; - r->vm_end = r->vm_start + sz_piece; + r->ar.end = r->ar.start + sz_piece; next = damon_next_region(r); - for (start = r->vm_end; start + sz_piece <= orig_end; + for (start = r->ar.end; start + sz_piece <= orig_end; start += sz_piece) { n = damon_new_region(ctx, start, start + sz_piece); if (!n) @@ -315,24 +315,20 @@ static int damon_split_region_evenly(struct damon_ctx *ctx, } /* complement last region for possible rounding error */ if (n) - n->vm_end = orig_end; + n->ar.end = orig_end; return 0; } -struct region { - unsigned long start; - unsigned long end; -}; - -static unsigned long sz_region(struct region *r) +static unsigned long sz_range(struct damon_addr_range *r) { return r->end - r->start; } -static void swap_regions(struct region *r1, struct region *r2) +static void swap_ranges(struct damon_addr_range *r1, + struct damon_addr_range *r2) { - struct region tmp; + struct damon_addr_range tmp; tmp = *r1; *r1 = *r2; @@ -343,7 +339,7 @@ static void swap_regions(struct region *r1, struct region *r2) * Find three regions separated by two biggest unmapped regions * * vma the head vma of the target address space - * regions an array of three 'struct region's that results will be saved + * regions an array of three address ranges that results will be saved * * This function receives an address space and finds three regions in it which * separated by the two biggest unmapped regions in the space. Please refer to @@ -353,9 +349,9 @@ static void swap_regions(struct region *r1, struct region *r2) * Returns 0 if success, or negative error code otherwise. */ static int damon_three_regions_in_vmas(struct vm_area_struct *vma, - struct region regions[3]) + struct damon_addr_range regions[3]) { - struct region gap = {0}, first_gap = {0}, second_gap = {0}; + struct damon_addr_range gap = {0}, first_gap = {0}, second_gap = {0}; struct vm_area_struct *last_vma = NULL; unsigned long start = 0; @@ -368,20 +364,20 @@ static int damon_three_regions_in_vmas(struct vm_area_struct *vma, } gap.start = last_vma->vm_end; gap.end = vma->vm_start; - if (sz_region(&gap) > sz_region(&second_gap)) { - swap_regions(&gap, &second_gap); - if (sz_region(&second_gap) > sz_region(&first_gap)) - swap_regions(&second_gap, &first_gap); + if (sz_range(&gap) > sz_range(&second_gap)) { + swap_ranges(&gap, &second_gap); + if (sz_range(&second_gap) > sz_range(&first_gap)) + swap_ranges(&second_gap, &first_gap); } last_vma = vma; } - if (!sz_region(&second_gap) || !sz_region(&first_gap)) + if (!sz_range(&second_gap) || !sz_range(&first_gap)) return -EINVAL; /* Sort the two biggest gaps by address */ if (first_gap.start > second_gap.start) - swap_regions(&first_gap, &second_gap); + swap_ranges(&first_gap, &second_gap); /* Store the result */ regions[0].start = ALIGN(start, MIN_REGION); @@ -400,7 +396,7 @@ static int damon_three_regions_in_vmas(struct vm_area_struct *vma, * Returns 0 on success, negative error code otherwise. */ static int damon_three_regions_of(struct damon_task *t, - struct region regions[3]) + struct damon_addr_range regions[3]) { struct mm_struct *mm; int rc; @@ -462,7 +458,7 @@ static int damon_three_regions_of(struct damon_task *t, static void damon_init_regions_of(struct damon_ctx *c, struct damon_task *t) { struct damon_region *r, *m = NULL; - struct region regions[3]; + struct damon_addr_range regions[3]; int i; if (damon_three_regions_of(t, regions)) { @@ -501,15 +497,13 @@ static void kdamond_init_regions(struct damon_ctx *ctx) */ /* - * Check whether regions are intersecting - * - * Note that this function checks 'struct damon_region' and 'struct region'. + * Check whether a region is intersecting an address range * * Returns true if it is. */ -static bool damon_intersect(struct damon_region *r, struct region *re) +static bool damon_intersect(struct damon_region *r, struct damon_addr_range *re) { - return !(r->vm_end <= re->start || re->end <= r->vm_start); + return !(r->ar.end <= re->start || re->end <= r->ar.start); } /* @@ -519,7 +513,7 @@ static bool damon_intersect(struct damon_region *r, struct region *re) * 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_task *t, struct damon_addr_range bregions[3]) { struct damon_region *r, *next; unsigned int i = 0; @@ -538,7 +532,7 @@ static void damon_apply_three_regions(struct damon_ctx *ctx, for (i = 0; i < 3; i++) { struct damon_region *first = NULL, *last; struct damon_region *newr; - struct region *br; + struct damon_addr_range *br; br = &bregions[i]; /* Get the first and last regions which intersects with br */ @@ -548,7 +542,7 @@ static void damon_apply_three_regions(struct damon_ctx *ctx, first = r; last = r; } - if (r->vm_start >= br->end) + if (r->ar.start >= br->end) break; } if (!first) { @@ -560,8 +554,8 @@ static void damon_apply_three_regions(struct damon_ctx *ctx, continue; damon_insert_region(newr, damon_prev_region(r), r); } else { - first->vm_start = ALIGN_DOWN(br->start, MIN_REGION); - last->vm_end = ALIGN(br->end, MIN_REGION); + first->ar.start = ALIGN_DOWN(br->start, MIN_REGION); + last->ar.end = ALIGN(br->end, MIN_REGION); } } } @@ -571,7 +565,7 @@ static void damon_apply_three_regions(struct damon_ctx *ctx, */ static void kdamond_update_regions(struct damon_ctx *ctx) { - struct region three_regions[3]; + struct damon_addr_range three_regions[3]; struct damon_task *t; damon_for_each_task(t, ctx) { @@ -617,7 +611,7 @@ static void damon_mkold(struct mm_struct *mm, unsigned long addr) static void damon_prepare_access_check(struct damon_ctx *ctx, struct mm_struct *mm, struct damon_region *r) { - r->sampling_addr = damon_rand(r->vm_start, r->vm_end); + r->sampling_addr = damon_rand(r->ar.start, r->ar.end); damon_mkold(mm, r->sampling_addr); } @@ -821,8 +815,8 @@ static void kdamond_reset_aggregated(struct damon_ctx *c) nr = nr_damon_regions(t); damon_write_rbuf(c, &nr, sizeof(nr)); damon_for_each_region(r, t) { - damon_write_rbuf(c, &r->vm_start, sizeof(r->vm_start)); - damon_write_rbuf(c, &r->vm_end, sizeof(r->vm_end)); + damon_write_rbuf(c, &r->ar.start, sizeof(r->ar.start)); + damon_write_rbuf(c, &r->ar.end, sizeof(r->ar.end)); damon_write_rbuf(c, &r->nr_accesses, sizeof(r->nr_accesses)); trace_damon_aggregated(t, r, nr); @@ -853,8 +847,8 @@ static int damos_madvise(struct damon_task *task, struct damon_region *r, if (!mm) goto put_task_out; - ret = do_madvise(t, mm, PAGE_ALIGN(r->vm_start), - PAGE_ALIGN(r->vm_end - r->vm_start), behavior); + ret = do_madvise(t, mm, PAGE_ALIGN(r->ar.start), + PAGE_ALIGN(r->ar.end - r->ar.start), behavior); mmput(mm); put_task_out: put_task_struct(t); @@ -901,7 +895,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c, struct damon_task *t, unsigned long sz; damon_for_each_scheme(s, c) { - sz = r->vm_end - r->vm_start; + sz = r->ar.end - r->ar.start; if ((s->min_sz_region && sz < s->min_sz_region) || (s->max_sz_region && s->max_sz_region < sz)) continue; @@ -932,7 +926,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) } } -#define sz_damon_region(r) (r->vm_end - r->vm_start) +#define sz_damon_region(r) (r->ar.end - r->ar.start) /* * Merge two adjacent regions into one region @@ -945,7 +939,7 @@ static void damon_merge_two_regions(struct damon_region *l, l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) / (sz_l + sz_r); l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r); - l->vm_end = r->vm_end; + l->ar.end = r->ar.end; damon_destroy_region(r); } @@ -967,7 +961,7 @@ static void damon_merge_regions_of(struct damon_task *t, unsigned int thres) else r->age++; - if (prev && prev->vm_end == r->vm_start && + if (prev && prev->ar.end == r->ar.start && diff_of(prev->nr_accesses, r->nr_accesses) <= thres) damon_merge_two_regions(prev, r); else @@ -1004,8 +998,8 @@ static void damon_split_region_at(struct damon_ctx *ctx, { struct damon_region *new; - new = damon_new_region(ctx, r->vm_start + sz_r, r->vm_end); - r->vm_end = new->vm_start; + new = damon_new_region(ctx, r->ar.start + sz_r, r->ar.end); + r->ar.end = new->ar.start; new->age = r->age; new->last_nr_accesses = r->last_nr_accesses; @@ -1022,7 +1016,7 @@ static void damon_split_regions_of(struct damon_ctx *ctx, int i; damon_for_each_region_safe(r, next, t) { - sz_region = r->vm_end - r->vm_start; + sz_region = r->ar.end - r->ar.start; for (i = 0; i < nr_subs - 1 && sz_region > 2 * MIN_REGION; i++) { From patchwork Tue Jun 9 14:19:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595813 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 6DD0590 for ; Tue, 9 Jun 2020 14:21:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2CC56206D5 for ; Tue, 9 Jun 2020 14:21:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="KfA35YMN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CC56206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0284C6B0006; Tue, 9 Jun 2020 10:21:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EF5AC6B0007; Tue, 9 Jun 2020 10:21:07 -0400 (EDT) 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 DE53A6B0008; Tue, 9 Jun 2020 10:21:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id C72EE6B0006 for ; Tue, 9 Jun 2020 10:21:07 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 78287809C05A for ; Tue, 9 Jun 2020 14:21:07 +0000 (UTC) X-FDA: 76909885374.30.ink83_1e15ec226dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 470CE18014AFF for ; Tue, 9 Jun 2020 14:21:07 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30012:30054:30064:30070,0,RBL:52.95.49.90:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: ink83_1e15ec226dc3 X-Filterd-Recvd-Size: 8179 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:21:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712466; x=1623248466; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=nIL22XofaxtLVU0O95H0B/lImASPrQqjRlXGSEAIqCw=; b=KfA35YMN/Syt8hjW0XdJEO1D0X4OYEChwaDHAZhFJ/MCx2Eg8zZ6489f D7LN5/Hz4gDPtN7o00WSCUnoPTwdUr297a04RJNx7i0afN9uhzzpX9TTo OpLqQPXzfuBl1/6yuzgvgqzHQiBuDy0WMTd3K2v0mFZMRXTI4RX/CvjYW 4=; IronPort-SDR: 7ZT/BMgZK0IojUAPw4DiT+9l0AU6iE8tsdsD/l+aW2Kq2FjADXPASz5pEytvPMfvi03K2HxT6e qIINmW7Rv1wg== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="35196772" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 09 Jun 2020 14:21:05 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id 2839FA1D05; Tue, 9 Jun 2020 14:20:54 +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; Tue, 9 Jun 2020 14:20:54 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:20:38 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 02/10] mm/damon: Make monitoring target regions init/update configurable Date: Tue, 9 Jun 2020 16:19:33 +0200 Message-ID: <20200609141941.19184-3-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 470CE18014AFF X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 This commit allows DAMON users to configure their own monitoring target regions initializer / updater. Using this, users can confine the monitoring address spaces as they want. For example, users can track only stack, heap, shared memory area, or specific file-backed area, as they want. Signed-off-by: SeongJae Park --- include/linux/damon.h | 13 +++++++++++++ mm/damon.c | 17 ++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index b4b06ca905a2..a1b6810ce0eb 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -158,9 +158,16 @@ struct damos { * @tasks_list: Head of monitoring target tasks (&damon_task) list. * @schemes_list: Head of schemes (&damos) list. * + * @init_target_regions: Constructs initial monitoring target regions. + * @update_target_regions: Updates monitoring 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 + * setting these callbacks to appropriate functions, therefore, users can + * monitor specific range of virtual address space. + * * @sample_cb and @aggregate_cb are called from @kdamond for each of the * sampling intervals and aggregation intervals, respectively. Therefore, * users can safely access to the monitoring results via @tasks_list without @@ -190,10 +197,16 @@ struct damon_ctx { struct list_head schemes_list; /* 'damos' objects */ /* callbacks */ + void (*init_target_regions)(struct damon_ctx *context); + void (*update_target_regions)(struct damon_ctx *context); void (*sample_cb)(struct damon_ctx *context); void (*aggregate_cb)(struct damon_ctx *context); }; +/* Reference callback implementations for virtual memory */ +void kdamond_init_vm_regions(struct damon_ctx *ctx); +void kdamond_update_vm_regions(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, unsigned long aggr_int, unsigned long regions_update_int, diff --git a/mm/damon.c b/mm/damon.c index fcd919e96754..b55d501365c0 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -87,6 +87,9 @@ static struct damon_ctx damon_user_ctx = { .regions_update_interval = 1000 * 1000, .min_nr_regions = 10, .max_nr_regions = 1000, + + .init_target_regions = kdamond_init_vm_regions, + .update_target_regions = kdamond_update_vm_regions, }; /* @@ -343,7 +346,7 @@ static void swap_ranges(struct damon_addr_range *r1, * * This function receives an address space and finds three regions in it which * separated by the two biggest unmapped regions in the space. Please refer to - * below comments of 'damon_init_regions_of()' function to know why this is + * below comments of 'damon_init_vm_regions_of()' function to know why this is * necessary. * * Returns 0 if success, or negative error code otherwise. @@ -455,7 +458,7 @@ static int damon_three_regions_of(struct damon_task *t, * * */ -static void damon_init_regions_of(struct damon_ctx *c, struct damon_task *t) +static void damon_init_vm_regions_of(struct damon_ctx *c, struct damon_task *t) { struct damon_region *r, *m = NULL; struct damon_addr_range regions[3]; @@ -484,12 +487,12 @@ static void damon_init_regions_of(struct damon_ctx *c, struct damon_task *t) } /* Initialize '->regions_list' of every task */ -static void kdamond_init_regions(struct damon_ctx *ctx) +void kdamond_init_vm_regions(struct damon_ctx *ctx) { struct damon_task *t; damon_for_each_task(t, ctx) - damon_init_regions_of(ctx, t); + damon_init_vm_regions_of(ctx, t); } /* @@ -563,7 +566,7 @@ static void damon_apply_three_regions(struct damon_ctx *ctx, /* * Update regions for current memory mappings */ -static void kdamond_update_regions(struct damon_ctx *ctx) +void kdamond_update_vm_regions(struct damon_ctx *ctx) { struct damon_addr_range three_regions[3]; struct damon_task *t; @@ -1131,7 +1134,7 @@ static int kdamond_fn(void *data) unsigned int max_nr_accesses = 0; pr_info("kdamond (%d) starts\n", ctx->kdamond->pid); - kdamond_init_regions(ctx); + ctx->init_target_regions(ctx); kdamond_write_record_header(ctx); @@ -1154,7 +1157,7 @@ static int kdamond_fn(void *data) } if (kdamond_need_update_regions(ctx)) - kdamond_update_regions(ctx); + ctx->update_target_regions(ctx); } damon_flush_rbuffer(ctx); damon_for_each_task(t, ctx) { From patchwork Tue Jun 9 14:19:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595815 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 37B59618 for ; Tue, 9 Jun 2020 14:21:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EAB07206D5 for ; Tue, 9 Jun 2020 14:21:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="sku1/o1u" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAB07206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1AED66B0007; Tue, 9 Jun 2020 10:21:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 160136B0008; Tue, 9 Jun 2020 10:21:36 -0400 (EDT) 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 04DF66B000A; Tue, 9 Jun 2020 10:21:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id E25076B0007 for ; Tue, 9 Jun 2020 10:21:35 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9CA9116B11 for ; Tue, 9 Jun 2020 14:21:35 +0000 (UTC) X-FDA: 76909886550.17.crib73_4501d1826dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id E2E891835BF7F for ; Tue, 9 Jun 2020 14:21:28 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30051:30054:30056:30064:30070,0,RBL:207.171.184.25:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: crib73_4501d1826dc3 X-Filterd-Recvd-Size: 9258 Received: from smtp-fw-9101.amazon.com (smtp-fw-9101.amazon.com [207.171.184.25]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:21:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712488; x=1623248488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Z0IurggP0Ne0aRf1k3oi5eHLQ+CxnTgV+b+ukC/GSlc=; b=sku1/o1u3raFG7rgF8jBNL01Q68T5481lBLmB+rVuxeJY9+qGHzx3uR6 xkHB8TqNKkON3M1c3OzRQMIIHZIwC1UvTVTAJ2/dJ5TD+Xv5v4GDHlteQ 49Yr8c8rgWHmF66O4WusKgr+c9WgZQ3yGXzh+LpnbNY89H0/jsYzY6c9n M=; IronPort-SDR: IoIAhU2gdayHbH5DmuXPA0GLLungqSc+dCSDwl0z1N7LUvk9RzMBQM8e69uAV4+d7Y2POSHQp1 Vcc5IQNbm24w== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="42677853" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-303d0b0e.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 09 Jun 2020 14:21:24 +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-303d0b0e.us-east-1.amazon.com (Postfix) with ESMTPS id 6BD7AA244A; Tue, 9 Jun 2020 14:21:13 +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; Tue, 9 Jun 2020 14:21:12 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:20:56 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 03/10] mm/damon/debugfs: Allow users to set initial monitoring target regions Date: Tue, 9 Jun 2020 16:19:34 +0200 Message-ID: <20200609141941.19184-4-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: E2E891835BF7F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 Some users would want to monitor only a part of the entire virtual memory address space. The '->init_target_regions' callback is therefore provided, but only programming interface can use it. For the reason, this commit introduces a new debugfs file, 'init_region'. Users can specify which initial monitoring target address regions they want by writing special input to the file. The input should describe each region in each line in below form: This commit also makes the default '->init_target_regions' callback, 'kdamon_init_vm_regions()' to do nothing if the user has set the initial target regions already. Note that the regions will be updated to cover entire memory mapped regions after 'regions update interval'. If you want the regions to not be updated after the initial setting, you could set the interval as a very long time, say, a few decades. Signed-off-by: SeongJae Park --- mm/damon.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 162 insertions(+), 6 deletions(-) diff --git a/mm/damon.c b/mm/damon.c index b55d501365c0..2d8322e6558f 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -491,8 +491,10 @@ void kdamond_init_vm_regions(struct damon_ctx *ctx) { struct damon_task *t; - damon_for_each_task(t, ctx) - damon_init_vm_regions_of(ctx, t); + damon_for_each_task(t, ctx) { + if (!nr_damon_regions(t)) + damon_init_vm_regions_of(ctx, t); + } } /* @@ -1721,6 +1723,153 @@ static ssize_t debugfs_record_write(struct file *file, return ret; } +static ssize_t sprint_init_regions(struct damon_ctx *c, char *buf, ssize_t len) +{ + struct damon_task *t; + struct damon_region *r; + int written = 0; + int rc; + + damon_for_each_task(t, c) { + damon_for_each_region(r, t) { + rc = snprintf(&buf[written], len - written, + "%d %lu %lu\n", + t->pid, r->ar.start, r->ar.end); + if (!rc) + return -ENOMEM; + written += rc; + } + } + return written; +} + +static ssize_t debugfs_init_regions_read(struct file *file, char __user *buf, + size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = &damon_user_ctx; + char *kbuf; + ssize_t len; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) { + mutex_unlock(&ctx->kdamond_lock); + return -EBUSY; + } + + len = sprint_init_regions(ctx, kbuf, count); + mutex_unlock(&ctx->kdamond_lock); + if (len < 0) + goto out; + len = simple_read_from_buffer(buf, count, ppos, kbuf, len); + +out: + kfree(kbuf); + return len; +} + +static int add_init_region(struct damon_ctx *c, + int pid, struct damon_addr_range *ar) +{ + struct damon_task *t; + struct damon_region *r, *prev; + int rc = -EINVAL; + + if (ar->start >= ar->end) + return -EINVAL; + + damon_for_each_task(t, c) { + if (t->pid == pid) { + r = damon_new_region(c, ar->start, ar->end); + if (!r) + return -ENOMEM; + damon_add_region(r, t); + if (nr_damon_regions(t) > 1) { + prev = damon_prev_region(r); + if (prev->ar.end > r->ar.start) { + damon_destroy_region(r); + return -EINVAL; + } + } + rc = 0; + } + } + return rc; +} + +static int set_init_regions(struct damon_ctx *c, const char *str, ssize_t len) +{ + struct damon_task *t; + struct damon_region *r, *next; + int pos = 0, parsed, ret; + int pid; + struct damon_addr_range ar; + int err; + + damon_for_each_task(t, c) { + damon_for_each_region_safe(r, next, t) + damon_destroy_region(r); + } + + while (pos < len) { + ret = sscanf(&str[pos], "%d %lu %lu%n", + &pid, &ar.start, &ar.end, &parsed); + if (ret != 3) + break; + err = add_init_region(c, pid, &ar); + if (err) + goto fail; + pos += parsed; + } + + return 0; + +fail: + damon_for_each_task(t, c) { + damon_for_each_region_safe(r, next, t) + damon_destroy_region(r); + } + return err; +} + +static ssize_t debugfs_init_regions_write(struct file *file, const char __user + *buf, size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = &damon_user_ctx; + char *kbuf; + ssize_t ret; + int err; + + if (*ppos) + return -EINVAL; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + ret = simple_write_to_buffer(kbuf, count, ppos, buf, count); + if (ret < 0) + goto out; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) { + ret = -EBUSY; + goto unlock_out; + } + + err = set_init_regions(ctx, kbuf, ret); + if (err) + ret = err; + +unlock_out: + mutex_unlock(&ctx->kdamond_lock); +out: + kfree(kbuf); + return ret; +} static ssize_t debugfs_attrs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) @@ -1802,6 +1951,12 @@ static const struct file_operations record_fops = { .write = debugfs_record_write, }; +static const struct file_operations init_regions_fops = { + .owner = THIS_MODULE, + .read = debugfs_init_regions_read, + .write = debugfs_init_regions_write, +}; + static const struct file_operations attrs_fops = { .owner = THIS_MODULE, .read = debugfs_attrs_read, @@ -1812,10 +1967,11 @@ static struct dentry *debugfs_root; static int __init damon_debugfs_init(void) { - const char * const file_names[] = {"attrs", "record", "schemes", - "pids", "monitor_on"}; - const struct file_operations *fops[] = {&attrs_fops, &record_fops, - &schemes_fops, &pids_fops, &monitor_on_fops}; + const char * const file_names[] = {"attrs", "init_regions", "record", + "schemes", "pids", "monitor_on"}; + const struct file_operations *fops[] = {&attrs_fops, + &init_regions_fops, &record_fops, &schemes_fops, &pids_fops, + &monitor_on_fops}; int i; debugfs_root = debugfs_create_dir("damon", NULL); From patchwork Tue Jun 9 14:19:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595817 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 66A7290 for ; Tue, 9 Jun 2020 14:21:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 263CE20774 for ; Tue, 9 Jun 2020 14:21:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="L/xGpa5B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 263CE20774 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4BC576B0008; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 46AC76B000A; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) 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 334C96B000D; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 1C4526B0008 for ; Tue, 9 Jun 2020 10:21:47 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D3FF0181355C8 for ; Tue, 9 Jun 2020 14:21:46 +0000 (UTC) X-FDA: 76909887012.30.stage39_380c9c126dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 24D33182018FA for ; Tue, 9 Jun 2020 14:21:44 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30029:30034:30051:30054:30064,0,RBL:72.21.196.25:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: stage39_380c9c126dc3 X-Filterd-Recvd-Size: 11441 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712504; x=1623248504; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=lCtpFdulZBcc+gNwg5rlkrBP9DmunmKCV7foIDqhGGw=; b=L/xGpa5BhSnNYfYiP9jafsjBeAqwKC4yKzQpcF0zAMr/ndvqhChOAGaw M6+IJd3PNU/V8r6GI+NDy69aTPGEmUKKogUjImyTK217RYAh63Cp147RO tw7rTVgdY1Cy5QjbHm8vSkP5UrO2Y+1DA3KayMd+WTpD/kmFqUOC3RBId k=; IronPort-SDR: yrI9nYiJ625dK61ZoZSXYWif1o52cVGahPtLx3H7yzm0pbk01cMhjIYilsOFHg6blhuh3KLNi2 /nzGR9YXbyGg== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="35297473" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 09 Jun 2020 14:21:43 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id C47C2A1D00; Tue, 9 Jun 2020 14:21:30 +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; Tue, 9 Jun 2020 14:21:30 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:21:13 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 04/10] tools/damon: Implement init target regions feature Date: Tue, 9 Jun 2020 16:19:35 +0200 Message-ID: <20200609141941.19184-5-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 24D33182018FA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 This commit updates the damon user space tool to support the initial monitoring target regions feature. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 39 +++++++++++++++++++++++++++++++++++++++ tools/damon/record.py | 12 +++++++----- tools/damon/schemes.py | 12 +++++++----- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index 3620ef12a5ea..ad476cc61421 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -12,12 +12,25 @@ debugfs_attrs = None debugfs_record = None debugfs_schemes = None debugfs_pids = None +debugfs_init_regions = None debugfs_monitor_on = None def set_target_pid(pid): return subprocess.call('echo %s > %s' % (pid, debugfs_pids), shell=True, executable='/bin/bash') +def set_target(pid, init_regions=[]): + rc = set_target_pid(pid) + if rc: + return rc + + if not os.path.exists(debugfs_init_regions): + return 0 + + string = ' '.join(['%s %d %d' % (pid, r[0], r[1]) for r in init_regions]) + return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), + shell=True, executable='/bin/bash') + def turn_damon(on_off): return subprocess.call("echo %s > %s" % (on_off, debugfs_monitor_on), shell=True, executable="/bin/bash") @@ -97,6 +110,7 @@ def chk_update_debugfs(debugfs): global debugfs_record global debugfs_schemes global debugfs_pids + global debugfs_init_regions global debugfs_monitor_on debugfs_damon = os.path.join(debugfs, 'damon') @@ -104,6 +118,7 @@ def chk_update_debugfs(debugfs): debugfs_record = os.path.join(debugfs_damon, 'record') debugfs_schemes = os.path.join(debugfs_damon, 'schemes') debugfs_pids = os.path.join(debugfs_damon, 'pids') + debugfs_init_regions = os.path.join(debugfs_damon, 'init_regions') debugfs_monitor_on = os.path.join(debugfs_damon, 'monitor_on') if not os.path.isdir(debugfs_damon): @@ -131,6 +146,26 @@ def cmd_args_to_attrs(args): return Attrs(sample_interval, aggr_interval, regions_update_interval, min_nr_regions, max_nr_regions, rbuf_len, rfile_path, schemes) +def cmd_args_to_init_regions(args): + regions = [] + for arg in args.regions.split(): + addrs = arg.split('-') + try: + if len(addrs) != 2: + raise Exception('two addresses not given') + start = int(addrs[0]) + end = int(addrs[1]) + if start >= end: + raise Exception('start >= end') + if regions and regions[-1][1] > start: + raise Exception('regions overlap') + except Exception as e: + print('Wrong \'--regions\' argument (%s)' % e) + exit(1) + + regions.append([start, end]) + return regions + def set_attrs_argparser(parser): parser.add_argument('-d', '--debugfs', metavar='', type=str, default='/sys/kernel/debug', help='debugfs mounted path') @@ -144,3 +179,7 @@ def set_attrs_argparser(parser): default=10, help='minimal number of regions') parser.add_argument('-m', '--maxr', metavar='<# regions>', type=int, default=1000, help='maximum number of regions') + +def set_init_regions_argparser(parser): + parser.add_argument('-r', '--regions', metavar='"- ..."', + type=str, default='', help='monitoring target address regions') diff --git a/tools/damon/record.py b/tools/damon/record.py index 44fa3a12af35..6ce8721d782a 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -13,7 +13,7 @@ import time import _damon -def do_record(target, is_target_cmd, attrs, old_attrs): +def do_record(target, is_target_cmd, init_regions, attrs, old_attrs): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -24,8 +24,8 @@ def do_record(target, is_target_cmd, attrs, old_attrs): if is_target_cmd: p = subprocess.Popen(target, shell=True, executable='/bin/bash') target = p.pid - if _damon.set_target_pid(target): - print('pid setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -65,6 +65,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('-l', '--rbuf', metavar='', type=int, @@ -88,19 +89,20 @@ def main(args=None): args.schemes = '' new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s > /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - do_record(target, True, new_attrs, orig_attrs) + do_record(target, True, init_regions, new_attrs, orig_attrs) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - do_record(target, False, new_attrs, orig_attrs) + do_record(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main() diff --git a/tools/damon/schemes.py b/tools/damon/schemes.py index 2d23dfb4fd13..654345dbdb62 100644 --- a/tools/damon/schemes.py +++ b/tools/damon/schemes.py @@ -14,7 +14,7 @@ import time import _convert_damos import _damon -def run_damon(target, is_target_cmd, attrs, old_attrs): +def run_damon(target, is_target_cmd, init_regions, attrs, old_attrs): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -27,8 +27,8 @@ def run_damon(target, is_target_cmd, attrs, old_attrs): if is_target_cmd: p = subprocess.Popen(target, shell=True, executable='/bin/bash') target = p.pid - if _damon.set_target_pid(target): - print('pid setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -67,6 +67,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('-c', '--schemes', metavar='', type=str, @@ -91,19 +92,20 @@ def main(args=None): args.out = 'null' args.schemes = _convert_damos.convert(args.schemes, args.sample, args.aggr) new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s > /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - run_damon(target, True, new_attrs, orig_attrs) + run_damon(target, True, init_regions, new_attrs, orig_attrs) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - run_damon(target, False, new_attrs, orig_attrs) + run_damon(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main() From patchwork Tue Jun 9 14:19:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595819 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 1A928618 for ; Tue, 9 Jun 2020 14:22:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB2AE206D5 for ; Tue, 9 Jun 2020 14:22:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="pb8usziu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB2AE206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1FC266B0002; Tue, 9 Jun 2020 10:22:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1ADAC6B000A; Tue, 9 Jun 2020 10:22:03 -0400 (EDT) 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 075986B000D; Tue, 9 Jun 2020 10:22:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id E45496B0002 for ; Tue, 9 Jun 2020 10:22:02 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9EF0C185044B9 for ; Tue, 9 Jun 2020 14:22:02 +0000 (UTC) X-FDA: 76909887684.19.leaf41_34112b926dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 606184307A9 for ; Tue, 9 Jun 2020 14:22:02 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30054:30064:30070,0,RBL:72.21.196.25:@amazon.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: leaf41_34112b926dc3 X-Filterd-Recvd-Size: 5565 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:22:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712522; x=1623248522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=v6Vmzq5EIDAZEFmnvXrN4Ci7XeSQ+6uNTzvYLYOmCMg=; b=pb8usziuC+fs/n+G+/Qy+woXfJmm2sEKfAj4VidLiSkUXwqgjRSBy+EG dGryqdBNY3HqiVk1MrRxAybGkuGgX8UMV5bSn9su0CKiY3xbeGlKEtfdK zZe1NSCEEc8ySMuhwA7NKw9v3d6hynS8Q8E0Oaeb3evCgzWi0YL2ar55l w=; IronPort-SDR: nEpkDPK0Sk41CVJJYXq9cww3EDIAVJgQCfJearg4PLeUq/AU2/79A5knzDXjrum2RiFlD66pp1 qSSxpNs97AnA== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="35297528" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 09 Jun 2020 14:22:01 +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-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id 6529F24230A; Tue, 9 Jun 2020 14:21:50 +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; Tue, 9 Jun 2020 14:21:49 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:21:33 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 05/10] Docs/damon: Document 'initial_regions' feature Date: Tue, 9 Jun 2020 16:19:36 +0200 Message-ID: <20200609141941.19184-6-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 606184307A9 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 This commit documents the 'initial_regions' feature. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index 18a19c35b4f3..f600366cdd4e 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -326,6 +326,40 @@ having pids 42 and 4242 as the processes to be monitored and check it again:: Note that setting the pids doesn't start the monitoring. +Initial Monitoring Target Regions +--------------------------------- + +DAMON automatically sets and updates the monitoring target regions so that +entire memory mappings of target processes can be covered. However, users +might want to limit the monitoring region to specific address ranges, such as +the heap, the stack, or specific file-mapped area. Or, some users might know +the initial access pattern of their workloads and therefore want to set optimal +initial regions for the 'adaptive regions adjustment'. + +In such cases, users can explicitly set the initial monitoring target regions +as they want, by writing proper values to the ``init_regions`` file. Each line +of the input should represent one region in below form.:: + + + +The ``pid`` should be already in ``pids`` file, and the regions should be +passed in address order. For example, below commands will set a couple of +address ranges, ``1-100`` and ``100-200`` as the initial monitoring target +region of process 42, and another couple of address ranges, ``20-40`` and +``50-100`` as that of process 4242.:: + + # cd /damon + # echo "42 1 100 + 42 100 200 + 4242 20 40 + 4242 50 100" > init_regions + +Note that this sets the initial monitoring target regions only. DAMON will +automatically updates the boundary of the regions after one ``regions update +interval``. Therefore, users should set the ``regions update interval`` large +enough. + + Record ------ From patchwork Tue Jun 9 14:19:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595827 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 0D34B618 for ; Tue, 9 Jun 2020 14:23:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD2AF207C3 for ; Tue, 9 Jun 2020 14:23:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="UuQjLAji" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD2AF207C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D6CC26B0007; Tue, 9 Jun 2020 10:23:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D1EBB6B000A; Tue, 9 Jun 2020 10:23:35 -0400 (EDT) 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 C32FB6B000C; Tue, 9 Jun 2020 10:23:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id A7EC56B0007 for ; Tue, 9 Jun 2020 10:23:35 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5C5511825FC6F for ; Tue, 9 Jun 2020 14:23:35 +0000 (UTC) X-FDA: 76909891590.12.woman51_630bbce26dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id B6BAF18036FE5 for ; Tue, 9 Jun 2020 14:22:20 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30054:30064:30070,0,RBL:72.21.198.25:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: woman51_630bbce26dc3 X-Filterd-Recvd-Size: 9358 Received: from smtp-fw-4101.amazon.com (smtp-fw-4101.amazon.com [72.21.198.25]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712540; x=1623248540; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=efag3GSalrV9NyyxpFArLX6aVPnGQkAMhSZzOaYu92g=; b=UuQjLAjiPGuvjQ41TYJ5VcZIK5PQSz5ElguQI2LnkR23Tlr14IlzDnOZ uzkhxer6c65flvlItOb+S7OHje0NL6QxY52Drking5NZTsUMxTxMqWJn+ cKGdBRI5vxf+0qx/xUSVECtuYjppKcjJ9w6H9FxqIkGY7xNeCb6O5cax5 Y=; IronPort-SDR: qmxu68i8ysiuerSo8dSgImOKcE6x8FjwCKPcDqs8o1kEzkmHRZRp9toomHUCHti9msGw5SzHrP DSW0s07CcnLg== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="35296075" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 09 Jun 2020 14:22:19 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com (Postfix) with ESMTPS id A5964282443; Tue, 9 Jun 2020 14:22:08 +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; Tue, 9 Jun 2020 14:22:07 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:21:51 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 06/10] mm/damon: Make access check primitive configurable Date: Tue, 9 Jun 2020 16:19:37 +0200 Message-ID: <20200609141941.19184-7-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: B6BAF18036FE5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 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 2d8322e6558f..95a4a7fedf4d 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -90,6 +90,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, }; /* @@ -613,7 +615,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); @@ -621,7 +623,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; @@ -632,7 +634,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); } } @@ -670,7 +672,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; @@ -694,7 +696,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; @@ -706,12 +708,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; } @@ -1141,13 +1143,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); From patchwork Tue Jun 9 14:19:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595821 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 35DD5618 for ; Tue, 9 Jun 2020 14:22:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E9943206D5 for ; Tue, 9 Jun 2020 14:22:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="j4nDCpqN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9943206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 299F86B0005; Tue, 9 Jun 2020 10:22:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2705D6B0006; Tue, 9 Jun 2020 10:22:50 -0400 (EDT) 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 160366B0007; Tue, 9 Jun 2020 10:22:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id F25D26B0005 for ; Tue, 9 Jun 2020 10:22:49 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A95D4183E9035 for ; Tue, 9 Jun 2020 14:22:49 +0000 (UTC) X-FDA: 76909889658.26.fish62_331608626dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 5FFB91802FA75 for ; Tue, 9 Jun 2020 14:22:49 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30012:30051:30054:30064:30070,0,RBL:207.171.184.29:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: fish62_331608626dc3 X-Filterd-Recvd-Size: 11401 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712569; x=1623248569; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Rl9IZAdjvtLy0i5XqcYAyQIz/L0Rb/0rnimZVvc44GI=; b=j4nDCpqN103EAfotQ+8vLQNLS4Hv2aAOEb0DSwJZAoYQuMxsELXZseqB DcgopkIijkF2EHuNuZCxp6GIFdkPNz/gULOoaWoHwkA33rA2j/pJ2rOiq NWK8a7AAS7SrcnZIlvH3WvHGd/ssjbQAYxWfu79/+hZhQ72bQJAMb3+YP U=; IronPort-SDR: 3PH7ZOH9gg5g9b5zsKURJLf8+/a/P2OYhKVvV2CcErB4Ty48JezU4wRIxVRvTQZw2G4B0fOCL5 zeoCFmgUhzYA== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="50932516" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-9ec21598.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 09 Jun 2020 14:22:43 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-9ec21598.us-east-1.amazon.com (Postfix) with ESMTPS id 07D23A1D0C; Tue, 9 Jun 2020 14:22:31 +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; Tue, 9 Jun 2020 14:22:31 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:22:14 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 07/10] mm/damon: Implement callbacks for physical memory monitoring Date: Tue, 9 Jun 2020 16:19:38 +0200 Message-ID: <20200609141941.19184-8-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 5FFB91802FA75 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 This commit implements the four callbacks (->init_target_regions, ->update_target_regions, ->prepare_access_check, and ->check_accesses) for the basic access monitoring of the physical memory address space. By setting the callback pointers to point those, users can easily monitor the accesses to the physical memory. Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed. Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 ++ mm/damon.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 1a788bfd1b4e..f96503a532ea 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -216,6 +216,11 @@ 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); +void kdamond_init_phys_regions(struct damon_ctx *ctx); +void kdamond_update_phys_regions(struct damon_ctx *ctx); +void kdamond_prepare_phys_access_checks(struct damon_ctx *ctx); +unsigned int kdamond_check_phys_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, unsigned long aggr_int, unsigned long regions_update_int, diff --git a/mm/damon.c b/mm/damon.c index 95a4a7fedf4d..3a5d14720cb7 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -27,10 +27,13 @@ #include #include #include +#include #include #include #include +#include #include +#include #include #include #include @@ -499,6 +502,18 @@ void kdamond_init_vm_regions(struct damon_ctx *ctx) } } +/* + * The initial regions construction function for the physical address space. + * + * This default version does nothing in actual. Users should set the initial + * regions by themselves before passing their damon_ctx to 'start_damon()', or + * implement their version of this and set '->init_target_regions' of their + * damon_ctx to point it. + */ +void kdamond_init_phys_regions(struct damon_ctx *ctx) +{ +} + /* * Functions for the dynamic monitoring target regions update */ @@ -582,6 +597,19 @@ void kdamond_update_vm_regions(struct damon_ctx *ctx) } } +/* + * The dynamic monitoring target regions update function for the physical + * address space. + * + * This default version does nothing in actual. Users should update the + * regions in other callbacks such as '->aggregate_cb', or implement their + * version of this and set the '->init_target_regions' of their damon_ctx to + * point it. + */ +void kdamond_update_phys_regions(struct damon_ctx *ctx) +{ +} + /* * Functions for the access checking of the regions */ @@ -717,6 +745,179 @@ unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) return max_nr_accesses; } +/* access check functions for physical address based regions */ + +/* + * Get a page by pfn if it is in the LRU list. Otherwise, returns NULL. + * + * The body of this function is stollen from the 'page_idle_get_page()'. We + * steal rather than reuse it because the code is quite simple . + */ +static struct page *damon_phys_get_page(unsigned long pfn) +{ + struct page *page = pfn_to_online_page(pfn); + pg_data_t *pgdat; + + if (!page || !PageLRU(page) || + !get_page_unless_zero(page)) + return NULL; + + pgdat = page_pgdat(page); + spin_lock_irq(&pgdat->lru_lock); + if (unlikely(!PageLRU(page))) { + put_page(page); + page = NULL; + } + spin_unlock_irq(&pgdat->lru_lock); + return page; +} + +static bool damon_page_mkold(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + damon_mkold(vma->vm_mm, addr); + return true; +} + +static void damon_phys_mkold(unsigned long paddr) +{ + struct page *page = damon_phys_get_page(PHYS_PFN(paddr)); + struct rmap_walk_control rwc = { + .rmap_one = damon_page_mkold, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return; + + if (!page_mapped(page) || !page_rmapping(page)) + return; + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) + return; + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); +} + +static void damon_prepare_phys_access_check(struct damon_ctx *ctx, + struct damon_region *r) +{ + r->sampling_addr = damon_rand(r->ar.start, r->ar.end); + + damon_phys_mkold(r->sampling_addr); +} + +void kdamond_prepare_phys_access_checks(struct damon_ctx *ctx) +{ + struct damon_task *t; + struct damon_region *r; + + damon_for_each_task(t, ctx) { + damon_for_each_region(r, t) + damon_prepare_phys_access_check(ctx, r); + } +} + +struct damon_phys_access_chk_result { + unsigned long page_sz; + bool accessed; +}; + +static bool damon_page_accessed(struct page *page, struct vm_area_struct *vma, + unsigned long addr, void *arg) +{ + struct damon_phys_access_chk_result *result = arg; + + result->accessed = damon_young(vma->vm_mm, addr, &result->page_sz); + + /* If accessed, stop walking */ + return !result->accessed; +} + +static bool damon_phys_young(unsigned long paddr, unsigned long *page_sz) +{ + struct page *page = damon_phys_get_page(PHYS_PFN(paddr)); + struct damon_phys_access_chk_result result = { + .page_sz = PAGE_SIZE, + .accessed = false, + }; + struct rmap_walk_control rwc = { + .arg = &result, + .rmap_one = damon_page_accessed, + .anon_lock = page_lock_anon_vma_read, + }; + bool need_lock; + + if (!page) + return false; + + if (!page_mapped(page) || !page_rmapping(page)) + return false; + + need_lock = !PageAnon(page) || PageKsm(page); + if (need_lock && !trylock_page(page)) + return false; + + rmap_walk(page, &rwc); + + if (need_lock) + unlock_page(page); + put_page(page); + + *page_sz = result.page_sz; + return result.accessed; +} + +/* + * Check whether the region was accessed after the last preparation + * + * mm 'mm_struct' for the given virtual address space + * r the region of physical address space that needs to be checked + */ +static void damon_check_phys_access(struct damon_ctx *ctx, + struct damon_region *r) +{ + static unsigned long last_addr; + static unsigned long last_page_sz = PAGE_SIZE; + static bool last_accessed; + + /* If the region is in the last checked page, reuse the result */ + if (ALIGN_DOWN(last_addr, last_page_sz) == + ALIGN_DOWN(r->sampling_addr, last_page_sz)) { + if (last_accessed) + r->nr_accesses++; + return; + } + + last_accessed = damon_phys_young(r->sampling_addr, &last_page_sz); + if (last_accessed) + r->nr_accesses++; + + last_addr = r->sampling_addr; +} + +unsigned int kdamond_check_phys_accesses(struct damon_ctx *ctx) +{ + struct damon_task *t; + struct damon_region *r; + unsigned int max_nr_accesses = 0; + + damon_for_each_task(t, ctx) { + damon_for_each_region(r, t) { + damon_check_phys_access(ctx, r); + max_nr_accesses = max(r->nr_accesses, max_nr_accesses); + } + } + + return max_nr_accesses; +} + /* * Functions for DAMON core logics and features */ From patchwork Tue Jun 9 14:19:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595825 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 9EE7A90 for ; Tue, 9 Jun 2020 14:23:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6B29D2078D for ; Tue, 9 Jun 2020 14:23:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="S1rZ2mQv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B29D2078D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9EA586B0002; Tue, 9 Jun 2020 10:23:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 99BE36B0006; Tue, 9 Jun 2020 10:23:11 -0400 (EDT) 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 889BE6B0007; Tue, 9 Jun 2020 10:23:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 6EC176B0002 for ; Tue, 9 Jun 2020 10:23:11 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2AE5CD5043 for ; Tue, 9 Jun 2020 14:23:11 +0000 (UTC) X-FDA: 76909890582.18.bit89_3f1661926dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 00D03100349BB for ; Tue, 9 Jun 2020 14:23:10 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30051:30054:30064:30070,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:20,LUA_SUMMARY:none X-HE-Tag: bit89_3f1661926dc3 X-Filterd-Recvd-Size: 5774 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712591; x=1623248591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=IPd4MAGBWxg6kOh+k8voQ+4pluey7PcsDkEHOVO6xUg=; b=S1rZ2mQvqT92tE+BtR0pilGMoKunwiUxLK63gjzdxlHbEVPlz22r6fhp eJAUHEsX90tYpfDSl8hZzZ4R12WxFe48sd2m7l3HBpfRtn2fIHT0MU14g AS0rTwwfOuG0hdcZmb2Jdd3QbQIBTHJ79nh92m7XTOkE+Zqjq5ihGQxl9 s=; IronPort-SDR: wwPwNkR4Zj9cANfnfbprtrW6WycDxHCId//+PvCS6TMpwF/Tbo+KxU76ZQVkbbyamwTCzS7oK+ GyqRUW2Kbggg== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="36626317" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-a70de69e.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 09 Jun 2020 14:23:10 +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-a70de69e.us-east-1.amazon.com (Postfix) with ESMTPS id 4BC44A2091; Tue, 9 Jun 2020 14:22:58 +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; Tue, 9 Jun 2020 14:22:58 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:22:41 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 08/10] mm/damon/debugfs: Support physical memory monitoring Date: Tue, 9 Jun 2020 16:19:39 +0200 Message-ID: <20200609141941.19184-9-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 00D03100349BB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mm/damon.c b/mm/damon.c index 3a5d14720cb7..b9cec7766b6c 100644 --- a/mm/damon.c +++ b/mm/damon.c @@ -1310,6 +1310,9 @@ static bool kdamond_need_stop(struct damon_ctx *ctx) return true; damon_for_each_task(t, ctx) { + if (t->pid == -1) + return false; + task = damon_get_task_struct(t); if (task) { put_task_struct(task); @@ -1849,6 +1852,23 @@ static ssize_t debugfs_pids_write(struct file *file, if (ret < 0) goto out; + 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; + + /* Set the fake target task pid as -1 */ + 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; + } + targets = str_to_pids(kbuf, ret, &nr_targets); if (!targets) { ret = -ENOMEM; From patchwork Tue Jun 9 14:19:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595829 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 BD6DC90 for ; Tue, 9 Jun 2020 14:23:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 899B220774 for ; Tue, 9 Jun 2020 14:23:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="s09lguO8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 899B220774 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A3A696B000A; Tue, 9 Jun 2020 10:23:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9EAA96B000C; Tue, 9 Jun 2020 10:23:40 -0400 (EDT) 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 900026B000D; Tue, 9 Jun 2020 10:23:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 7506B6B000A for ; Tue, 9 Jun 2020 10:23:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3A001CF9D5 for ; Tue, 9 Jun 2020 14:23:40 +0000 (UTC) X-FDA: 76909891800.17.spy57_0d1451b26dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id B44181839C9A0 for ; Tue, 9 Jun 2020 14:23:34 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30029:30054:30064:30070,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: spy57_0d1451b26dc3 X-Filterd-Recvd-Size: 6757 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712615; x=1623248615; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=w1Wrf62e73x+SRZTs2supCzGH7vYA1IEmIfHRiOCQt8=; b=s09lguO8/CV9QmhetNrma+OCcpkLC/Pto/35Me9yrnmWNzIvObopueNU s+NZO0tVpNbgDw7G5K6LEI32/KNg7StO5a/OwMESXE4Zyke4SSRMfD9lr ydhTdUgFYbfXHp+qISWRQcZO45lNcGhg3Pg+fjLt/pCuZ1YvCqhfDiqyU A=; IronPort-SDR: yJ7f98cY7UglrbJx40+DWO+UzQVdRhy7f7KWtH9D9Rg24eKV+ctgu91IcWa8GI4Pz9O/5wsC1Z CiDYOvc2lKQg== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="36626381" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-38ae4ad2.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 09 Jun 2020 14:23:34 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-38ae4ad2.us-east-1.amazon.com (Postfix) with ESMTPS id F364BA2600; Tue, 9 Jun 2020 14:23:22 +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; Tue, 9 Jun 2020 14:23:22 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:23:05 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 09/10] tools/damon/record: Support physical memory address spce Date: Tue, 9 Jun 2020 16:19:40 +0200 Message-ID: <20200609141941.19184-10-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: B44181839C9A0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 This commit allows users to record the data accesses on physical memory address space by passing 'paddr' as target to 'damo-record'. If the init regions are given, the regions will be monitored. Else, it will monitor biggest conitguous 'System RAM' region in '/proc/iomem' and monitor the region. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 2 ++ tools/damon/heats.py | 2 +- tools/damon/record.py | 29 ++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index ad476cc61421..95d23c2ab6ee 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -27,6 +27,8 @@ def set_target(pid, init_regions=[]): if not os.path.exists(debugfs_init_regions): return 0 + if pid == 'paddr': + pid = -1 string = ' '.join(['%s %d %d' % (pid, r[0], r[1]) for r in init_regions]) return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), shell=True, executable='/bin/bash') diff --git a/tools/damon/heats.py b/tools/damon/heats.py index 99837083874e..34dbcf1a839d 100644 --- a/tools/damon/heats.py +++ b/tools/damon/heats.py @@ -307,7 +307,7 @@ def plot_heatmap(data_file, output_file): set xrange [0:]; set yrange [0:]; set xlabel 'Time (ns)'; - set ylabel 'Virtual Address (bytes)'; + set ylabel 'Address (bytes)'; plot '%s' using 1:2:3 with image;""" % (terminal, output_file, data_file) subprocess.call(['gnuplot', '-e', gnuplot_cmd]) os.remove(data_file) diff --git a/tools/damon/record.py b/tools/damon/record.py index 6ce8721d782a..416dca940c1d 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -73,6 +73,29 @@ def set_argparser(parser): parser.add_argument('-o', '--out', metavar='', type=str, default='damon.data', help='output file path') +def default_paddr_region(): + "Largest System RAM region becomes the default" + ret = [] + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) != 2: + continue + name = fields[1].strip() + if name != 'System RAM': + continue + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + + sz_region = end - start + if not ret or sz_region > (ret[1] - ret[0]): + ret = [start, end] + return ret + def main(args=None): global orig_attrs if not args: @@ -93,7 +116,11 @@ def main(args=None): target = args.target target_fields = target.split() - if not subprocess.call('which %s > /dev/null' % target_fields[0], + if target == 'paddr': # physical memory address space + if not init_regions: + init_regions = [default_paddr_region()] + do_record(target, False, init_regions, new_attrs, orig_attrs) + elif not subprocess.call('which %s > /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): do_record(target, True, init_regions, new_attrs, orig_attrs) else: From patchwork Tue Jun 9 14:19:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11595831 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 BCC93618 for ; Tue, 9 Jun 2020 14:23:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7BE1B2081A for ; Tue, 9 Jun 2020 14:23:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fVr48oYR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BE1B2081A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9271C6B0005; Tue, 9 Jun 2020 10:23:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8B1776B000E; Tue, 9 Jun 2020 10:23:53 -0400 (EDT) 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 7A9E96B0005; Tue, 9 Jun 2020 10:23:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 61C646B0005 for ; Tue, 9 Jun 2020 10:23:53 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2EB9A824377E for ; Tue, 9 Jun 2020 14:23:53 +0000 (UTC) X-FDA: 76909892346.05.son42_4e0b54b26dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id E9239182D699A for ; Tue, 9 Jun 2020 14:23:52 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=422492b2c=sjpark@amazon.com,,RULES_HIT:30003:30054:30064:30070,0,RBL:72.21.196.25:@amazon.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: son42_4e0b54b26dc3 X-Filterd-Recvd-Size: 12895 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 14:23:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591712633; x=1623248633; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=lkv2Bo/3IctZrTSbBNlygdbTcIm2Ki8g0wDs1n3f3dA=; b=fVr48oYRUR9adz9nOhqEvhHSKXL6RhxTM0EkXMSK/WwSz5Qv2FIJmSWF EgJ2Fm3OrfB5B+cOvdIWOvrsd5Luabls41QhJZsmN9cIFZkxZoj59HPKv SSId8p3YvqZIgk2Dctk7ZspX1YjYxdSYH7yts3iUBaQJ1AzKP257TBJDD M=; IronPort-SDR: IB/F3te4GXNvy+j70MRkn080NGUmhRMc/djYPyReE4xxnzLFX3xRgopWCk5dRynwpdPzUePJjg tsJlLYjU0ivg== X-IronPort-AV: E=Sophos;i="5.73,492,1583193600"; d="scan'208";a="35297925" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-98acfc19.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 09 Jun 2020 14:23:52 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-98acfc19.us-east-1.amazon.com (Postfix) with ESMTPS id 3CCF6A07FF; Tue, 9 Jun 2020 14:23:40 +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; Tue, 9 Jun 2020 14:23:40 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.109) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 9 Jun 2020 14:23:24 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v3 10/10] Docs/damon: Document physical memory monitoring support Date: Tue, 9 Jun 2020 16:19:41 +0200 Message-ID: <20200609141941.19184-11-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609141941.19184-1-sjpark@amazon.com> References: <20200609141941.19184-1-sjpark@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.162.109] X-ClientProxiedBy: EX13D30UWC004.ant.amazon.com (10.43.162.4) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: E9239182D699A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 This commit adds description for the physical memory monitoring usage in the DAMON document. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/faq.rst | 16 +++-- Documentation/admin-guide/mm/damon/index.rst | 1 - .../admin-guide/mm/damon/mechanisms.rst | 4 +- Documentation/admin-guide/mm/damon/plans.rst | 29 --------- Documentation/admin-guide/mm/damon/usage.rst | 59 ++++++++++++++----- 5 files changed, 54 insertions(+), 55 deletions(-) delete mode 100644 Documentation/admin-guide/mm/damon/plans.rst diff --git a/Documentation/admin-guide/mm/damon/faq.rst b/Documentation/admin-guide/mm/damon/faq.rst index 02f7581b05f6..e9b69d1bf975 100644 --- a/Documentation/admin-guide/mm/damon/faq.rst +++ b/Documentation/admin-guide/mm/damon/faq.rst @@ -38,9 +38,13 @@ separate document, :doc:`guide`. Please refer to that. Does DAMON support virtual memory only? ======================================== -For now, yes. But, DAMON will be able to support various address spaces -including physical memory in near future. An RFC patchset [1]_ for this -extension is already available. Please refer :doc:`plans` for detailed plan -for this. - -.. [1] https://lore.kernel.org/linux-mm/20200409094232.29680-1-sjpark@amazon.com/ +No. DAMON supports the virtual memory address spaces and the physical memory +address space for now. However, it can be extended to support any address +space, because the core logic of the DAMON can be configured with the low level +primitives for each address space. + +In other words, DAMON provides the reference implementations of the low level +primitives for the virtual memory address spaces and the physical memory +address spaces. The programming interface users can further implement their +own low level primitives for their special use cases and configure those in +DAMON if they need. diff --git a/Documentation/admin-guide/mm/damon/index.rst b/Documentation/admin-guide/mm/damon/index.rst index 4d128e4fd9c8..7b2939d50408 100644 --- a/Documentation/admin-guide/mm/damon/index.rst +++ b/Documentation/admin-guide/mm/damon/index.rst @@ -33,4 +33,3 @@ optimizations of their systems. faq mechanisms eval - plans diff --git a/Documentation/admin-guide/mm/damon/mechanisms.rst b/Documentation/admin-guide/mm/damon/mechanisms.rst index f0bc52c698a6..8a93a945cacf 100644 --- a/Documentation/admin-guide/mm/damon/mechanisms.rst +++ b/Documentation/admin-guide/mm/damon/mechanisms.rst @@ -76,9 +76,7 @@ keeping the bounds users set for their trade-off. Handling Virtual Memory Mappings ================================ -This is for monitoring of virtual memory address space only. It is the only -one address space that supported by DAMON as of now, but other address spaces -will be supported in the future. +This is for monitoring of virtual memory address space only. Only small parts in the super-huge virtual address space of the processes are mapped to physical memory and accessed. Thus, tracking the unmapped address diff --git a/Documentation/admin-guide/mm/damon/plans.rst b/Documentation/admin-guide/mm/damon/plans.rst deleted file mode 100644 index 8eba8a1dcb98..000000000000 --- a/Documentation/admin-guide/mm/damon/plans.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0 - -============ -Future Plans -============ - -DAMON is still on its early stage. Below plans are still under development. - - -Support Various Address Spaces -============================== - -Currently, DAMON supports only virtual memory address spaces because it -utilizes PTE Accessed bits as its low-level access check primitive and ``struct -vma`` as a way to address the monitoring target regions. However, the core -idea of DAMON is in a separate higher layer. Therefore, DAMON can support -other various address spaces by changing the two low primitives to others for -the address spaces. - -In the future, DAMON will make the lower level primitives configurable so that -it can support various address spaces including physical memory. The -configuration will be highly flexible so that users can even implement the -primitives by themselves for their special use cases. Monitoring of -clean/dirty/entire page cache, NUMA nodes, specific files, or block devices -would be examples of such use cases. - -An RFC patchset for this plan is available [1]_. - -.. [1] https://lore.kernel.org/linux-mm/20200409094232.29680-1-sjpark@amazon.com/ diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index f600366cdd4e..8942d09bfd49 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -58,9 +58,11 @@ Recording Data Access Pattern ----------------------------- The ``record`` subcommand records the data access pattern of target processes -in a file (``./damon.data`` by default). You can specify the target as either -pid of running target or a command for execution of the process. Below example -shows a command target usage:: +in a file (``./damon.data`` by default). You can specify the target with 1) +the command for execution of the monitoring target process, 2) pid of running +target process, or 3) the special keyword, 'paddr', if you want to monitor the +system's physical memory address space. Below example shows a command target +usage:: # cd /tools/damon/ # damo record "sleep 5" @@ -71,6 +73,15 @@ of the process. Below example shows a pid target usage:: # sleep 5 & # damo record `pidof sleep` +Finally, below example shows the use of the special keyword, 'paddr':: + + # damo record paddr + +In this case, the monitoring target regions defaults to the largetst 'System +RAM' region specified in '/proc/iomem' file. Note that the initial monitoring +target region is maintained rather than dynamically updated like the virtual +memory address spaces monitoring mode. + You can tune this by setting the monitoring attributes and path to the record file using optional arguments to the subcommand. To know about the monitoring attributes in detail, please refer to :doc:`mechanisms`. @@ -314,27 +325,42 @@ check it again:: Target PIDs ----------- -Users can get and set the pids of monitoring target processes by reading from -and writing to the ``pids`` file. For example, below commands set processes -having pids 42 and 4242 as the processes to be monitored and check it again:: +To monitor the virtual memory address spaces of specific processes, users can +get and set the pids of monitoring target processes by reading from and writing +to the ``pids`` file. For example, below commands set processes having pids 42 +and 4242 as the processes to be monitored and check it again:: # cd /damon # echo 42 4242 > pids # cat pids 42 4242 +Users can also monitor the physical memory address space of the system by +writing a special keyword, "``paddr\n``" to the file. In this case, reading the +file will show ``-1``, as below:: + + # cd /damon + # echo paddr > pids + # cat pids + -1 + Note that setting the pids doesn't start the monitoring. Initial Monitoring Target Regions --------------------------------- -DAMON automatically sets and updates the monitoring target regions so that -entire memory mappings of target processes can be covered. However, users -might want to limit the monitoring region to specific address ranges, such as -the heap, the stack, or specific file-mapped area. Or, some users might know -the initial access pattern of their workloads and therefore want to set optimal -initial regions for the 'adaptive regions adjustment'. +In case of the virtual memory monitoring, DAMON automatically sets and updates +the monitoring target regions so that entire memory mappings of target +processes can be covered. However, users might want to limit the monitoring +region to specific address ranges, such as the heap, the stack, or specific +file-mapped area. Or, some users might know the initial access pattern of +their workloads and therefore want to set optimal initial regions for the +'adaptive regions adjustment'. + +In contrast, DAMON do not automatically sets and updates the monitoring target +regions in case of physical memory monitoring. Therefore, users should set the +monitoring target regions by themselves. In such cases, users can explicitly set the initial monitoring target regions as they want, by writing proper values to the ``init_regions`` file. Each line @@ -354,10 +380,11 @@ region of process 42, and another couple of address ranges, ``20-40`` and 4242 20 40 4242 50 100" > init_regions -Note that this sets the initial monitoring target regions only. DAMON will -automatically updates the boundary of the regions after one ``regions update -interval``. Therefore, users should set the ``regions update interval`` large -enough. +Note that this sets the initial monitoring target regions only. In case of +virtual memory monitoring, DAMON will automatically updates the boundary of the +regions after one ``regions update interval``. Therefore, users should set the +``regions update interval`` large enough in this case, if they don't want the +update. Record