Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5874324pxu; Wed, 23 Dec 2020 07:34:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXDW+QaNw9Pd/v/lirmZrCB+c1MqufoWqfuVv8mizREUcrQuSYtmnW/udoF1CaDA38D4Ub X-Received: by 2002:a17:906:7f13:: with SMTP id d19mr25313335ejr.54.1608737652850; Wed, 23 Dec 2020 07:34:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608737652; cv=none; d=google.com; s=arc-20160816; b=IEQkCoTfCkKRYUVzW2A9K8i49KcicNiVQVTWc6q3O7zGaLQf8Q/LJhV23UwvH7rMZF TNwbKBq5TcPNUM3tZRbqmOzybd4F0HgSNlMzldbUM1tAX75F0dy3UZicZ9nWn2ZldYC7 obsNg6xtqsx9WCtQVI2Req66ceDWDxYHmgjf6gEAiZnW8lBUYdNgN9bFZv57ladhTaGl Ig3HqSx6Pg2xXEcz8KsGnNauyta2VdRB42LBdOI2yWmmyXXzvkac7dzmm0g+ZoKes9Wp 9sjaAS8Vn0G3Tfkc8dau6LnSNH0U2wl5rEswCS1LqlIWzBfPqU0sp84w9ghYcXAaNdIV Ot+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=lfA6xo7ZY2UezgEnberC47d7lINIUx2tdvlXx5dRSMg=; b=TzDjMX6NpeQ14jHTZw2jAybu5kEJty3blcrPoZrUIxKX025KyvHTkti688jjeYIZ13 szNFNzM+tt/r/4QAvPkw0PxK3tj6PwA1sbDiSqrwSnqj4bee0FaRmAOCOxl09kszJ/rR ho3a/vhkCyYPxexjpplinivWrTzDwHd2rzFs4OqxwD/9G6yoqEIFG6Q5TXnRWMk0Kk/q V/NBj2Qf2tnXXpL/Ggg1L/m2R0WNlMO4fNUW5kMWjXle8C/PUFRavZbYU2spnFQdRM0b CA15LNmRY8/h4agSRdv0U9LnCczAfO0hLQPCc6OiEK0H8n7ZBCntF2KY9IarefVper80 T6yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="s/8pfm9/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx26si14511640edb.358.2020.12.23.07.33.50; Wed, 23 Dec 2020 07:34:12 -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=@google.com header.s=20161025 header.b="s/8pfm9/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727338AbgLWPcj (ORCPT + 99 others); Wed, 23 Dec 2020 10:32:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726361AbgLWPcj (ORCPT ); Wed, 23 Dec 2020 10:32:39 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A8A9C06179C for ; Wed, 23 Dec 2020 07:31:58 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id m12so40985001lfo.7 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=o/Z32G+Kn3lD8RiNFFuMXibywUFKFdGiFFrUVwJNXEdsNVlqriRnyRA8mCcQYUfoNf n5HtyH3idrFg9KwLuYqszzcfYXbjQBRLaaG4VipvDJDND1goH1HpNB9NJYgtraBIcu/i XphHdzgzOZoP2HpSP+uQodpMvVmeZOpaEVBaQ7f6KsosWi2d5jC1VJdqmOfTMJyHNJk1 H8wBlCdTSlViXTd3ApUNZSqXWPHKL2wQCRDP0aSqf49yZlwJYzsZgLjQut468HYA9GIN loYTkg5Pz5U9ZnL9Pkx8QZ0pGIoe9ZMOpnxkaf0pd8M5XOV5VPuKQVKK0JMUNT+6S6oc 0idw== X-Gm-Message-State: AOAM5330Xanvyy2F3tB01GcFgW4lD8PDF6y1dQWxguxXfv2wwQcPJ18J +/Vz3JJ/z0OVMYRdiCm7+Bm7UpYp+XNxeTy5WK7euA== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.