linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeelb@google.com>
To: SeongJae Park <sjpark@amazon.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	SeongJae Park <sjpark@amazon.de>,
	 Jonathan.Cameron@huawei.com,
	Andrea Arcangeli <aarcange@redhat.com>,
	acme@kernel.org,  alexander.shishkin@linux.intel.com,
	amit@kernel.org, benh@kernel.crashing.org,
	 brendan.d.gregg@gmail.com,
	Brendan Higgins <brendanhiggins@google.com>,
	 Qian Cai <cai@lca.pw>, Colin Ian King <colin.king@canonical.com>,
	Jonathan Corbet <corbet@lwn.net>,
	 David Hildenbrand <david@redhat.com>,
	dwmw@amazon.com, Marco Elver <elver@google.com>,
	 "Du, Fan" <fan.du@intel.com>,
	foersleo@amazon.de, Greg Thelen <gthelen@google.com>,
	 Ian Rogers <irogers@google.com>,
	jolsa@redhat.com,  "Kirill A. Shutemov" <kirill@shutemov.name>,
	Mark Rutland <mark.rutland@arm.com>,
	 Mel Gorman <mgorman@suse.de>, Minchan Kim <minchan@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	 namhyung@kernel.org,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Rik van Riel <riel@surriel.com>,
	 David Rientjes <rientjes@google.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Mike Rapoport <rppt@kernel.org>,
	sblbir@amazon.com, Shuah Khan <shuah@kernel.org>,
	 sj38.park@gmail.com, snu@amazon.de,
	Vlastimil Babka <vbabka@suse.cz>,
	 Vladimir Davydov <vdavydov.dev@gmail.com>,
	Yang Shi <yang.shi@linux.alibaba.com>,
	 Huang Ying <ying.huang@intel.com>,
	zgf574564920@gmail.com, linux-damon@amazon.com,
	 Linux MM <linux-mm@kvack.org>,
	linux-doc@vger.kernel.org,  LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v22 06/18] mm/damon: Implement primitives for the virtual memory address spaces
Date: Wed, 25 Nov 2020 07:30:18 -0800	[thread overview]
Message-ID: <CALvZod4hYx4nytwkDrxd9MOtzMUKe-YmRavfTOxZaHCfUK6dXA@mail.gmail.com> (raw)
In-Reply-To: <20201020085940.13875-7-sjpark@amazon.com>

On Tue, Oct 20, 2020 at 2:06 AM SeongJae Park <sjpark@amazon.com> wrote:
>
> From: SeongJae Park <sjpark@amazon.de>
>
> 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::
>
>     <heap>
>     <BIG UNMAPPED REGION 1>
>     <uppermost mmap()-ed region>
>     (small mmap()-ed regions and munmap()-ed regions)
>     <lowermost mmap()-ed region>
>     <BIG UNMAPPED REGION 2>
>     <stack>
>
> Signed-off-by: SeongJae Park <sjpark@amazon.de>
> Reviewed-by: Leonard Foerster <foersleo@amazon.de>
> ---
>  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.

> +       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.

> @@ -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 am still looking more into this patch


  reply	other threads:[~2020-11-25 15:30 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20  8:59 [PATCH v22 00/18] Introduce Data Access MONitor (DAMON) SeongJae Park
2020-10-20  8:59 ` [PATCH v22 01/18] mm: " SeongJae Park
2020-11-25 15:29   ` Shakeel Butt
2020-11-26 11:51     ` SeongJae Park
2020-12-08  7:41       ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 02/18] mm/damon: Implement region based sampling SeongJae Park
2020-11-25 15:29   ` Shakeel Butt
2020-11-26 12:09     ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 03/18] mm/damon: Adaptively adjust regions SeongJae Park
2020-11-25 15:29   ` Shakeel Butt
2020-11-26 12:12     ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 04/18] mm/damon: Track dynamic monitoring target regions update SeongJae Park
2020-11-25 15:29   ` Shakeel Butt
2020-11-26 12:18     ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 05/18] mm/idle_page_tracking: Make PG_(idle|young) reusable SeongJae Park
2020-11-25 15:30   ` Shakeel Butt
2020-11-26 12:31     ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 06/18] mm/damon: Implement primitives for the virtual memory address spaces SeongJae Park
2020-11-25 15:30   ` Shakeel Butt [this message]
2020-11-26 13:34     ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 07/18] mm/page_idle: Avoid interferences from concurrent users SeongJae Park
2020-11-25 15:30   ` Shakeel Butt
2020-11-26 13:37     ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 08/18] mm/damon/primitives: Make coexistable with Idle Page Tracking SeongJae Park
2020-10-20  8:59 ` [PATCH v22 09/18] mm/damon: Add a tracepoint SeongJae Park
2020-10-20  8:59 ` [PATCH v22 10/18] mm/damon: Implement a debugfs-based user space interface SeongJae Park
2020-11-25 15:30   ` Shakeel Butt
2020-11-26 13:45     ` SeongJae Park
2020-10-20  8:59 ` [PATCH v22 11/18] mm/damon/dbgfs: Implement recording feature SeongJae Park
2020-10-20  8:59 ` [PATCH v22 12/18] mm/damon/dbgfs: Export kdamond pid to the user space SeongJae Park
2020-10-20  8:59 ` [PATCH v22 13/18] mm/damon/dbgfs: Support multiple contexts SeongJae Park
2020-10-20  8:59 ` [PATCH v22 14/18] tools: Introduce a minimal user-space tool for DAMON SeongJae Park
2020-10-20  8:59 ` [PATCH v22 15/18] Documentation: Add documents " SeongJae Park
2020-10-20  8:59 ` [PATCH v22 16/18] mm/damon: Add kunit tests SeongJae Park
2020-10-20  8:59 ` [PATCH v22 17/18] mm/damon: Add user space selftests SeongJae Park
2020-10-20  8:59 ` [PATCH v22 18/18] MAINTAINERS: Update for DAMON SeongJae Park
2020-11-11 16:41 ` [PATCH v22 00/18] Introduce Data Access MONitor (DAMON) SeongJae Park
2020-11-17  8:05   ` SeongJae Park
2020-11-17 14:30     ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALvZod4hYx4nytwkDrxd9MOtzMUKe-YmRavfTOxZaHCfUK6dXA@mail.gmail.com \
    --to=shakeelb@google.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=aarcange@redhat.com \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=amit@kernel.org \
    --cc=benh@kernel.crashing.org \
    --cc=brendan.d.gregg@gmail.com \
    --cc=brendanhiggins@google.com \
    --cc=cai@lca.pw \
    --cc=colin.king@canonical.com \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=dwmw@amazon.com \
    --cc=elver@google.com \
    --cc=fan.du@intel.com \
    --cc=foersleo@amazon.de \
    --cc=gthelen@google.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=kirill@shutemov.name \
    --cc=linux-damon@amazon.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=mgorman@suse.de \
    --cc=minchan@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=riel@surriel.com \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=sblbir@amazon.com \
    --cc=shuah@kernel.org \
    --cc=sj38.park@gmail.com \
    --cc=sjpark@amazon.com \
    --cc=sjpark@amazon.de \
    --cc=snu@amazon.de \
    --cc=vbabka@suse.cz \
    --cc=vdavydov.dev@gmail.com \
    --cc=yang.shi@linux.alibaba.com \
    --cc=ying.huang@intel.com \
    --cc=zgf574564920@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).