Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp551914pxu; Thu, 26 Nov 2020 05:39:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZuCb01A5lm4rnRxKGoFhmgdbPtZ+QLSYNj+LWQTziHclGYuQIl9edwdteEAMKT8tcHPlk X-Received: by 2002:a50:d617:: with SMTP id x23mr2544487edi.361.1606397984029; Thu, 26 Nov 2020 05:39:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606397984; cv=none; d=google.com; s=arc-20160816; b=MTiX9YvqIlOKq3X2+iaY6eV7iLrXt8ccMDPf8OBbz+g2xvb8TwwPN2Yrw8lnB1hY8D RBAKYAhj93nBQuEQcaxsvAcoNWqtHn3I+Ow0GrmuZmBvbN3dCS0r3U1Uu4pKenWqQRC6 DOs4dR2CeG/O0UA3wLwP93DwemOs4H4sVz6MCcfU9b1LXauy1QZdZfeg9rTSGP7vuV4j uRpJfpQTjMn+G/AyEojmBKzrB8O4debZEeXtbSOl3bM6aEJ9H1GwDRTsKQOyufNdSxT9 cMeGfwKHHMKIhajZbkbe8dWHsBfifJiX3iaMZU9JWRV667cwfjR9+00c21yumL1B/vPO vSIQ== 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=ZzE6apVr+NBCq2ey7Bb9uQl8U1AZvvrD2/7u2VMKxsI=; b=QzFL83vaxUxmsqaarVgXdH6WvfKjoPF67MinCMi8ZQn3M0Ll6OpZ3FqKfrpFchiRYG s8vKtO6T3n+8rvHHowYm0gMB5kw7gee58fYjIds7XauNXcRIqdufdZ6PoHgIrGLbq8qo zSJYAyIQHdaU7GDfvtv0pksBlekzSb4LUQL7JoZadEhDqcqCH0OWDsO2syOOYzc+F6Do 6jNFAi3gOSRh6TOuLqR+XH3Pjr8fXu7AXj1UuUI7KbRIX0RFvrKzATC7LfF/rZh8xVdG 1rFjfNkqEjWBRivCA+SdsZ34JwErLzig6ZdM3HGDWZcHciB1yL+z5yoTqBigaFeI/gBS YlRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=B0K4IZCM; 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 o13si3763137ejb.68.2020.11.26.05.39.21; Thu, 26 Nov 2020 05:39:44 -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=B0K4IZCM; 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 S2390457AbgKZNfU (ORCPT + 99 others); Thu, 26 Nov 2020 08:35:20 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:49258 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389919AbgKZNfT (ORCPT ); Thu, 26 Nov 2020 08:35:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1606397719; x=1637933719; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=ZzE6apVr+NBCq2ey7Bb9uQl8U1AZvvrD2/7u2VMKxsI=; b=B0K4IZCM92G3QScOp2yrGzP5cjhPLdTGgGqyjZ/9erJrwKDjEL7PIpvV R1zCReUlSlL/+RP+n9ICHlecog1hgfIqmbTxDwNGY+igi3QMl3ZAG+mKg FuxiXzaYgpKsmWny8sU1huZbQKCZKtdqDHlI0HTG1ycD5iBqZtoJUsuHv c=; X-IronPort-AV: E=Sophos;i="5.78,372,1599523200"; d="scan'208";a="67484231" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-42f764a0.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 26 Nov 2020 13:35:12 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-42f764a0.us-east-1.amazon.com (Postfix) with ESMTPS id 5324EC1B51; Thu, 26 Nov 2020 13:35:00 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.124) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 26 Nov 2020 13:34:43 +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 v22 06/18] mm/damon: Implement primitives for the virtual memory address spaces Date: Thu, 26 Nov 2020 14:34:27 +0100 Message-ID: <20201126133427.3677-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.161.124] X-ClientProxiedBy: EX13D42UWB004.ant.amazon.com (10.43.161.99) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 25 Nov 2020 07:30:18 -0800 Shakeel Butt wrote: > On Tue, Oct 20, 2020 at 2:06 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 provided by > > this commit is designed 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 > > it set again after one sampling period. This could disturb other kernel > > subsystems using the Accessed bits, namely Idle page tracking and the > > reclaim logic. To avoid such disturbances, DAMON makes it mutually > > exclusive with Idle page tracking and uses ``PG_idle`` and ``PG_young`` > > page flags to solve the conflict with the reclaim logics, 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 > > 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 | 14 + > > mm/damon/Kconfig | 10 + > > mm/damon/Makefile | 1 + > > mm/damon/primitives.c | 582 ++++++++++++++++++++++++++++++++++++++++++ > > 4 files changed, 607 insertions(+) > > create mode 100644 mm/damon/primitives.c > > > > diff --git a/include/linux/damon.h b/include/linux/damon.h > > index b8562814751e..70cc4b54212e 100644 > > --- a/include/linux/damon.h > > +++ b/include/linux/damon.h > > @@ -238,4 +238,18 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); > > > > #endif /* CONFIG_DAMON */ > > > > +#ifdef CONFIG_DAMON_PRIMITIVES > > + > > +/* Reference callback implementations for virtual memory */ > > +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(struct damon_target *t); > > +void damon_va_cleanup(struct damon_ctx *ctx); > > +void damon_va_set_primitives(struct damon_ctx *ctx); > > + > > +#endif /* CONFIG_DAMON_PRIMITIVES */ > > + > > + > > #endif > > diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig > > index d00e99ac1a15..0d2a18ddb9d8 100644 > > --- a/mm/damon/Kconfig > > +++ b/mm/damon/Kconfig > > @@ -12,4 +12,14 @@ config DAMON > > See https://damonitor.github.io/doc/html/latest-damon/index.html for > > more information. > > > > +config DAMON_PRIMITIVES > > I would rather name this base on virtual address space monitoring > maybe like DAMON_VMA_OPTIMIZED_MONITORING or something similar. > PRIMITIVES does not seem like a good name for this. Agreed, will rename in the next version. How about DAMON_PRIMITIVES_VADDR? > > > + bool "Monitoring primitives for virtual address spaces monitoring" > > + depends on DAMON && MMU && !IDLE_PAGE_TRACKING > > + select PAGE_EXTENSION if !64BIT > > + select PAGE_IDLE_FLAG > > + help > > + This builds the default data access monitoring primitives for DAMON. > > + The primitives support only virtual address spaces. If this cannot > > + cover your use case, you can implement and use your own primitives. > > + > > endmenu > > diff --git a/mm/damon/Makefile b/mm/damon/Makefile > > index 4fd2edb4becf..2f3235a52e5e 100644 > > --- a/mm/damon/Makefile > > +++ b/mm/damon/Makefile > > @@ -1,3 +1,4 @@ > > # SPDX-License-Identifier: GPL-2.0 > > > > obj-$(CONFIG_DAMON) := core.o > > +obj-$(CONFIG_DAMON_PRIMITIVES) += primitives.o > > diff --git a/mm/damon/primitives.c b/mm/damon/primitives.c > > new file mode 100644 > > index 000000000000..9b603ac0077c > > --- /dev/null > > +++ b/mm/damon/primitives.c > > Same with the filename. Agreed. > > > @@ -0,0 +1,582 @@ > > +// SPDX-License-Identifier: GPL-2.0 > [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; > > 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 am still looking more into this patch Looking forward your more comments! Thanks, SeongJae Park