Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5928809pxu; Wed, 23 Dec 2020 08:49:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOYanvVFNnUdVxg6+cywqk0f9ki0PElXH9XuQ9ariI0X7vwtEAOKhjQX6PNmHKhfcuLIzw X-Received: by 2002:a05:6402:310f:: with SMTP id dc15mr25358006edb.225.1608742167790; Wed, 23 Dec 2020 08:49:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608742167; cv=none; d=google.com; s=arc-20160816; b=EAaHeQZJrSVLXRAAdTwynR5whyXoXh/+85S3UDxmkkmOBEAJk0t7NI31EzhfHocxZ6 S0+bq3JaetPCAySH5hGvfD3xi3bC71MWfD5LVm/BG/VlwpDDm+TUlN77A8trKUuCznrx gx2x3mndJ4JPZua+14IfRTYhBQbmA5MzlHeQzRMvyuvk49CiEg5Y1W6+y6b7r6jP7rA8 8m9GTQixGvQvOsS1QqDF1ybEtL3sP7Pi+Y5vOETT3bVaPZkxqK0Czq/Ea1/TjopFq8U6 wUt4iagtxhaVNy9zG1iupeYNM4RAYbn/3XEB86NdJY/nM5bGoBYj/UiARLuR0rtcKvrD VO0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=oCbn+BtjmSbDnkdD3LkKFsSfsMdG/SsfM5rXzn781H4=; b=OL/LClHS0m7TKiFCcDcH0s/arMpWUlOg86at/uBiyeFMHuMuOJHfV/bUzD9PRaTExf 7PNe926x2X+PsutkEr6ClZ0wp7xWYMFlQaxkany0vrQq4ODkToFzWs3bshmXU1iMB5ma u/XMFt4lOGZVi/91LLr9Ha25Av6cFhLIk85u1RGbVxN9QMewO8WnDw8x4LCqbCDd6ReV 9CUc9eot7+jrqz58CTweV5h2JUT9seEnviHJP18HdNaDxqN89KnkodKK/uBLZUT//lFG 2reSAmVGVm7kOZGQKPXGzatk/p5wdS4uh/uUZJcIyEiRUOoGKKQrFGkH6/9QaQRx3QVv 8W1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Ovb9WldX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r5si13906143edo.330.2020.12.23.08.49.04; Wed, 23 Dec 2020 08:49:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Ovb9WldX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726112AbgLWQsf (ORCPT + 99 others); Wed, 23 Dec 2020 11:48:35 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:48208 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbgLWQsf (ORCPT ); Wed, 23 Dec 2020 11:48:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608742114; x=1640278114; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=oCbn+BtjmSbDnkdD3LkKFsSfsMdG/SsfM5rXzn781H4=; b=Ovb9WldXG1DCBUIeiUBeuqD9xBUJTgPaIdE0/kGCjlj4GRNq66EMZWJP 49iz6p/Ilh1ohc6Sc5tbhMT3/kUv0cBAnTzc/V3VUQfv+hDHiQ0dUZJYt HWNj2+lzdAAXz/oTrkU/tW24qhjJ/lsrGN5UYFnihM7DETdYLoG7NrGcG c=; X-IronPort-AV: E=Sophos;i="5.78,441,1599523200"; d="scan'208";a="105643871" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 23 Dec 2020 16:47:44 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com (Postfix) with ESMTPS id 1C486A1E5D; Wed, 23 Dec 2020 16:47:31 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.160.66) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 23 Dec 2020 16:47:14 +0000 From: SeongJae Park To: Shakeel Butt CC: SeongJae Park , SeongJae Park , , Andrea Arcangeli , , , , , , Brendan Higgins , Qian Cai , Colin Ian King , Jonathan Corbet , "David Hildenbrand" , , Marco Elver , "Du, Fan" , , "Greg Thelen" , Ian Rogers , , "Kirill A. Shutemov" , Mark Rutland , Mel Gorman , Minchan Kim , Ingo Molnar , , "Peter Zijlstra (Intel)" , Randy Dunlap , Rik van Riel , David Rientjes , Steven Rostedt , Mike Rapoport , , Shuah Khan , , , Vlastimil Babka , Vladimir Davydov , Yang Shi , Huang Ying , , , Linux MM , , LKML Subject: Re: [PATCH v23 05/15] mm/damon: Implement primitives for the virtual memory address spaces Date: Wed, 23 Dec 2020 17:47:00 +0100 Message-ID: <20201223164700.29723-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.66] X-ClientProxiedBy: EX13D36UWB003.ant.amazon.com (10.43.161.118) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 23 Dec 2020 07:31:45 -0800 Shakeel Butt wrote: > On Tue, Dec 15, 2020 at 3:58 AM SeongJae Park wrote: > > > > From: SeongJae Park > > > > This commit introduces a reference implementation of the address space > > specific low level primitives for the virtual address space, so that > > users of DAMON can easily monitor the data accesses on virtual address > > spaces of specific processes by simply configuring the implementation to > > be used by DAMON. > > > > The low level primitives for the fundamental access monitoring are > > defined in two parts: > > > > 1. Identification of the monitoring target address range for the address > > space. > > 2. Access check of specific address range in the target space. > > > > The reference implementation for the virtual address space does the > > works as below. > > > > PTE Accessed-bit Based Access Check > > ----------------------------------- > > > > The implementation uses PTE Accessed-bit for basic access checks. That > > is, it clears the bit for next sampling target page and checks whether > > 'for the next' > > > it set again after one sampling period. This could disturb the reclaim > > 'it is set' Good catch! Will fix in the next version. > > > logic. DAMON uses ``PG_idle`` and ``PG_young`` page flags to solve the > > conflict, as Idle page tracking does. > > > > VMA-based Target Address Range Construction > > ------------------------------------------- > > > > 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 regions is just wasteful. However, because DAMON > > can deal with some level of noise using the adaptive regions adjustment > > mechanism, tracking every mapping is not strictly required but could > > even incur a high overhead in some cases. That said, too huge unmapped > > areas inside the monitoring target should be removed to not take the > > time for the adaptive mechanism. > > > > For the reason, this implementation converts the complex mappings to > > three distinct regions that cover every mapped area of the address > > space. Also, the two gaps between the three regions are the two biggest > > unmapped areas in the given address space. The two biggest unmapped > > areas would be the gap between the heap and the uppermost mmap()-ed > > region, and the gap between the lowermost mmap()-ed region and the stack > > in most of the cases. Because these gaps are exceptionally huge in > > usual address spacees, excluding these will be sufficient to make a > > *spaces Good eye! Will fix in the next version. > > > reasonable trade-off. Below shows this in detail:: > > > > > > > > > > (small mmap()-ed regions and munmap()-ed regions) > > > > > > > > > > Signed-off-by: SeongJae Park > > Reviewed-by: Leonard Foerster > > --- > > include/linux/damon.h | 13 + > > mm/damon/Kconfig | 9 + > > mm/damon/Makefile | 1 + > > mm/damon/vaddr.c | 579 ++++++++++++++++++++++++++++++++++++++++++ > > 4 files changed, 602 insertions(+) > > create mode 100644 mm/damon/vaddr.c > > > > diff --git a/include/linux/damon.h b/include/linux/damon.h > > index f446f8433599..39b4d6d3ddee 100644 > > --- a/include/linux/damon.h > > +++ b/include/linux/damon.h > > @@ -274,4 +274,17 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); > > > > #endif /* CONFIG_DAMON */ > > > > +#ifdef CONFIG_DAMON_VADDR > > + > > +/* Monitoring primitives for virtual memory address spaces */ > > +void damon_va_init_regions(struct damon_ctx *ctx); > > +void damon_va_update_regions(struct damon_ctx *ctx); > > +void damon_va_prepare_access_checks(struct damon_ctx *ctx); > > +unsigned int damon_va_check_accesses(struct damon_ctx *ctx); > > +bool damon_va_target_valid(void *t); > > +void damon_va_cleanup(struct damon_ctx *ctx); > > +void damon_va_set_primitives(struct damon_ctx *ctx); > > Any reason for these to be in the header? To let DAMON API users (in kernel space) and other primitives developers to use those. > > > + > [snip] > > + > > +static bool damon_va_young(struct mm_struct *mm, unsigned long addr, > > + unsigned long *page_sz) > > +{ > > + pte_t *pte = NULL; > > + pmd_t *pmd = NULL; > > + spinlock_t *ptl; > > + bool young = false; > > + > > + if (follow_pte_pmd(mm, addr, NULL, &pte, &pmd, &ptl)) > > + return false; > > + > > + *page_sz = PAGE_SIZE; > > + if (pte) { > > + young = pte_young(*pte); > > + if (!young) > > + young = !page_is_idle(pte_page(*pte)); > > + pte_unmap_unlock(pte, ptl); > > + return young; > > + } > > + > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > + young = pmd_young(*pmd); > > + if (!young) > > + young = !page_is_idle(pmd_page(*pmd)); > > + spin_unlock(ptl); > > + *page_sz = ((1UL) << HPAGE_PMD_SHIFT); > > +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ > > + > > + return young; > > You need mmu_notifier_test_young() here. Hmm I remember mentioning > this in some previous version as well. Your question and my answer was as below: > Don't you need mmu_notifier_clear_young() here? I think we don't need it here because we only read the Accessed bit and PG_Idle if Accessed bit was not set. I should notice that you mean 'test_young()' but didn't, sorry. I will add it in the next version. > > BTW have you tested this on a VM? Yes. Indeed, I'm testing this on a QEMU/KVM environment. You can get more detail at: https://damonitor.github.io/doc/html/latest/vm/damon/eval.html#setup > > The patch looks good overall. Thanks. I will fix above things in the next version. Thanks, SeongJae Park