From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0286AC433DB for ; Wed, 23 Dec 2020 16:47:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 824E3221FA for ; Wed, 23 Dec 2020 16:47:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 824E3221FA 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 B348E8D0036; Wed, 23 Dec 2020 11:47:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE4D58D0026; Wed, 23 Dec 2020 11:47:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FAA48D0036; Wed, 23 Dec 2020 11:47:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 8992B8D0026 for ; Wed, 23 Dec 2020 11:47:55 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4AA248249980 for ; Wed, 23 Dec 2020 16:47:55 +0000 (UTC) X-FDA: 77625128910.22.fall39_61162fe2746a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 2BE1918038E6F for ; Wed, 23 Dec 2020 16:47:55 +0000 (UTC) X-HE-Tag: fall39_61162fe2746a X-Filterd-Recvd-Size: 9740 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Dec 2020 16:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608742075; x=1640278075; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=oCbn+BtjmSbDnkdD3LkKFsSfsMdG/SsfM5rXzn781H4=; b=Ghd7NXnMmtdrGMgA/nwlrDnDOUiybY1pzCEsPAcEdfIIe4J4fl3cMheN w6M0FB/llLfwEFehAmJkoHwDJ25CS+G6KSZ15R6hB8BHdOA3ME6dwLItm dCZKHyxxNpe2etle/HsOJhtpf62FbGYmlQvowkGLrtHHfOe0+PZS0bOOu E=; 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) 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: 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