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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 CD850C433DB for ; Wed, 23 Dec 2020 15:32:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 459D32333D for ; Wed, 23 Dec 2020 15:31:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 459D32333D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5FC988D002F; Wed, 23 Dec 2020 10:31:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AE4C8D0026; Wed, 23 Dec 2020 10:31:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49CA88D002F; Wed, 23 Dec 2020 10:31:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 344DD8D0026 for ; Wed, 23 Dec 2020 10:31:59 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DA164181AEF2A for ; Wed, 23 Dec 2020 15:31:58 +0000 (UTC) X-FDA: 77624937516.26.brake14_1f0c76d27469 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id B64ED1804B661 for ; Wed, 23 Dec 2020 15:31:58 +0000 (UTC) X-HE-Tag: brake14_1f0c76d27469 X-Filterd-Recvd-Size: 9178 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Dec 2020 15:31:58 +0000 (UTC) Received: by mail-lf1-f43.google.com with SMTP id h205so40971471lfd.5 for ; Wed, 23 Dec 2020 07:31:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lfA6xo7ZY2UezgEnberC47d7lINIUx2tdvlXx5dRSMg=; b=s/8pfm9/q4KfoeQvoJVRXQYJtrJyV5wt67cLf6OH8aJZ9xMuZ0kLlddsj3P4245KVa hDO7uI8+GQ6g4nPDS9W4qyXOKaZc+8u4qOngi8eBPry7KQjtq+ewrrdJHan8RLHQ+OhH 0GFWEAAgNymVb00cSWD9bt45nqtmh9VlB956ds/Vbh9qDBjO8GNz2E+IsIDGCzLKI6uG L7WHpFrIG+4/PVrDT2vUKAZQOTh1vfLrrLFFgwpTneI+rSBYEUXRMLtWZuY2xRBXWIyN dWA+MmWhr8nmDlDyvSAnWs+2I0kPEtF2fj2ioA0R2kzwqawOvjBnG/KhppV+RcjN1z0F prAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lfA6xo7ZY2UezgEnberC47d7lINIUx2tdvlXx5dRSMg=; b=K6UKYwUThQCeAgPJ90fQjfxsypUjbvNhmHjwAyD2+YXiJNyBnfE/d3ojqCIQZLnlz9 yQT7FFLYx6zOA5ivW/V63iRf0VNTuCrhcCBtCR+vOcYlZPzhojsnizGuBHOMKXX56DoD C+lO1NlfMwgv9C6PZB55UHT6eRd83N495UJX3zxxKzzut9MjFL7mGimg5K8KG82jdBfl 1r8f/vMT7hZvq2KGeeJv9Jr7GsQ/0rfubpzn9LCRRVFQVOZIwXcSmRfqFPv2qCWV+aoS UXMF8gFPLX208lhEKI9VS/8SRr2329a5FTHeLH1jSpLrgFsBJ1ai5XU9/VLgc+ckvc6j SkYg== X-Gm-Message-State: AOAM530FjIQ0vznALzXDM9phxtrZfuQMHiWFz2LdvysfrCvr0g9l+pVL hqTuJ5uxvhcgT4E154OhMf4E34ukfTHKdgHY9/9kqg== X-Google-Smtp-Source: ABdhPJw6vH/wnmn6eKuUm5Fv3lxVK7tu2XrsM98EgKp+9QKzLEImKbHMeAnyS49GCpdpcIa4OFDlvxiGPnHlKKAnVRs= X-Received: by 2002:ac2:47e7:: with SMTP id b7mr10573632lfp.117.1608737516435; Wed, 23 Dec 2020 07:31:56 -0800 (PST) MIME-Version: 1.0 References: <20201215115448.25633-1-sjpark@amazon.com> <20201215115448.25633-6-sjpark@amazon.com> In-Reply-To: <20201215115448.25633-6-sjpark@amazon.com> From: Shakeel Butt Date: Wed, 23 Dec 2020 07:31:45 -0800 Message-ID: Subject: Re: [PATCH v23 05/15] mm/damon: Implement primitives for the virtual memory address spaces To: SeongJae Park Cc: Andrew Morton , SeongJae Park , Jonathan.Cameron@huawei.com, Andrea Arcangeli , acme@kernel.org, alexander.shishkin@linux.intel.com, amit@kernel.org, benh@kernel.crashing.org, brendan.d.gregg@gmail.com, Brendan Higgins , Qian Cai , Colin Ian King , Jonathan Corbet , David Hildenbrand , dwmw@amazon.com, Marco Elver , "Du, Fan" , foersleo@amazon.de, Greg Thelen , Ian Rogers , jolsa@redhat.com, "Kirill A. Shutemov" , Mark Rutland , Mel Gorman , Minchan Kim , Ingo Molnar , namhyung@kernel.org, "Peter Zijlstra (Intel)" , Randy Dunlap , Rik van Riel , David Rientjes , Steven Rostedt , Mike Rapoport , sblbir@amazon.com, Shuah Khan , sj38.park@gmail.com, snu@amazon.de, Vlastimil Babka , Vladimir Davydov , Yang Shi , Huang Ying , zgf574564920@gmail.com, linux-damon@amazon.com, Linux MM , linux-doc@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" 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 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' > 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 > 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? > + [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. BTW have you tested this on a VM? The patch looks good overall.