• SeongJae Park's avatar
    mm/damon: implement primitives for the virtual memory address spaces · 3f49584b
    SeongJae Park authored
    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 the next sampling target page and checks whether
    it is set again after one sampling period.  This could disturb the reclaim
    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 spaces,
    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>
    
    [akpm@linux-foundation.org: mm/damon/vaddr.c needs highmem.h for kunmap_atomic()]
    [sjpark@amazon.de: remove unnecessary PAGE_EXTENSION setup]
      Link: https://lkml.kernel.org/r/20210806095153.6444-2-sj38.park@gmail.com
    [sjpark@amazon.de: safely walk page table]
      Link: https://lkml.kernel.org/r/20210831161800.29419-1-sj38.park@gmail.com
    
    Link: https://lkml.kernel.org/r/20210716081449.22187-6-sj38.park@gmail.comSigned-off-by: default avatarSeongJae Park <sjpark@amazon.de>
    Reviewed-by: default avatarLeonard Foerster <foersleo@amazon.de>
    Reviewed-by: default avatarFernand Sieber <sieberf@amazon.com>
    Acked-by: default avatarShakeel Butt <shakeelb@google.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Amit Shah <amit@kernel.org>
    Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
    Cc: Brendan Higgins <brendanhiggins@google.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: David Rientjes <rientjes@google.com>
    Cc: David Woodhouse <dwmw@amazon.com>
    Cc: Fan Du <fan.du@intel.com>
    Cc: Greg Kroah-Hartman <greg@kroah.com>
    Cc: Greg Thelen <gthelen@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Joe Perches <joe@perches.com>
    Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Marco Elver <elver@google.com>
    Cc: Markus Boehme <markubo@amazon.de>
    Cc: Maximilian Heyne <mheyne@amazon.de>
    Cc: Mel Gorman <mgorman@suse.de>
    Cc: Minchan Kim <minchan@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Rik van Riel <riel@surriel.com>
    Cc: Shuah Khan <shuah@kernel.org>
    Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    3f49584b
vaddr.c 16.4 KB