DAMON: Support Physical Memory Address Space Monitoring
Subsystems (5)
v7 cover DAMON: Support Physical Memory Address Space Monitoring
From: SeongJae Park <[email protected]>
Changes from Previous Version
=============================
- Use 42 as the fake target id for paddr instead of -1
- Fix a typo
Introduction
============
DAMON[1] programming interface users can extend DAMON for any address space by configuring the address-space specific low level primitives with appropriate ones including their own implementations. However, because the implementation for the virtual address space is only available now, the users should implement their own for other address spaces. Worse yet, the user space users who rely on the debugfs interface and user space tool, cannot implement their own.
This patchset implements another reference implementation of the low level primitives for the physical memory address space. With this change, hence, the kernel space users can monitor both the virtual and the physical address spaces by simply changing the configuration in the runtime. Further, this patchset links the implementation to the debugfs interface and the user space tool for the user space users.
Note that the implementation supports only the user memory, as same to the idle page access tracking feature.
[1] https://lore.kernel.org/linux-mm/[email protected]/
Baseline and Complete Git Trees
===============================
The patches are based on the v5.8 plus DAMON v20 patchset[1] and DAMOS RFC v14 patchset[2]. You can also clone the complete git tree:
$ git clone git://github.com/sjp38/linux -b cdamon/rfc/v7
The web is also available:
https://github.com/sjp38/linux/releases/tag/cdamon/rfc/v7
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/
Sequence of Patches
===================
The sequence of patches is as follow.
The first 5 patches allow the user space users manually set the monitoring regions. The 1st and 2nd patches implements the features in the debugfs interface and the user space tool . Following two patches each implement unittests (the 3rd patch) and selftests (the 4th patch) for the new feature. Finally, the 5th patch documents this new feature.
Following 5 patches implement the physical memory monitoring. The 6th patch implements the low level primitives. The 7th and the 8th patches links the primitives to the debugfs and the user space tool, respectively. The 9th patch further implement a handy NUMA specific memory monitoring feature on the user space tool. Finally, the 10th patch documents this new features.
Patch History
=============
Changes from RFC v6
(https://lore.kernel.org/linux-mm/[email protected]/)
- Use 42 as the fake target id for paddr instead of -1
- Fix typo
Changes from RFC v5
(https://lore.kernel.org/linux-mm/[email protected]/)
- Support nested iomem sections (Du Fan)
- Rebase on v5.8
Changes from RFC v4
(https://lore.kernel.org/linux-mm/[email protected]/)
- Support NUMA specific physical memory monitoring
Changes from RFC v3
(https://lore.kernel.org/linux-mm/[email protected]/)
- Export rmap functions
- Reorganize for physical memory monitoring support only
- Clean up debugfs code
Changes from RFC v2
(https://lore.kernel.org/linux-mm/[email protected]/)
- Support the physical memory monitoring with the user space tool
- Use 'pfn_to_online_page()' (David Hildenbrand)
- Document more detail on random 'pfn' and its safeness (David Hildenbrand)
Changes from RFC v1
(https://lore.kernel.org/linux-mm/[email protected]/)
- Provide the reference primitive implementations for the physical memory
- Connect the extensions with the debugfs interface
SeongJae Park (10):
mm/damon/debugfs: Allow users to set initial monitoring target regions tools/damon: Support init target regions specification mm/damon-test: Add more unit tests for 'init_regions' selftests/damon/_chk_record: Do not check number of gaps Docs/admin-guide/mm/damon: Document 'init_regions' feature mm/damon: Implement callbacks for physical memory monitoring mm/damon/debugfs: Support physical memory monitoring tools/damon/record: Support physical memory monitoring tools/damon/record: Support NUMA specific recording Docs/DAMON: Document physical memory monitoring support
Documentation/admin-guide/mm/damon/usage.rst | 77 +++- Documentation/vm/damon/design.rst | 29 +- Documentation/vm/damon/faq.rst | 5 +- include/linux/damon.h | 6 + mm/damon-test.h | 53 +++ mm/damon.c | 382 ++++++++++++++++++- tools/damon/_damon.py | 41 ++ tools/damon/_paddr_layout.py | 147 +++++++ tools/damon/record.py | 57 ++- tools/damon/schemes.py | 12 +- tools/testing/selftests/damon/_chk_record.py | 6 - 11 files changed, 770 insertions(+), 45 deletions(-) create mode 100644 tools/damon/_paddr_layout.py
Signature · 1 line
2.17.1
RFC v7 1/10 mm/damon/debugfs: Allow users to set initial monitoring target regions
From: SeongJae Park <[email protected]>
Some users would want to monitor only a part of the entire virtual memory address space. The '->init_target_regions' callback is therefore provided, but only programming interface can use it.
For the reason, this commit introduces a new debugfs file, 'init_region'. Users can specify which initial monitoring target address regions they want by writing special input to the file. The input should describe each region in each line in below form:
<pid> <start address> <end address>
This commit also makes the default '->init_target_regions' callback, 'kdamon_init_vm_regions()' to do nothing if the user has set the initial target regions already.
Note that the regions will be updated to cover entire memory mapped regions after 'regions update interval'. If you want the regions to not be updated after the initial setting, you could set the interval as a very long time, say, a few decades.
--- mm/damon.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 152 insertions(+), 4 deletions(-)
mm/damon.c +152 -4
@@ -2001,6 +2001,147 @@ static ssize_t debugfs_record_write(struct file *file,return ret; } +static ssize_t sprint_init_regions (struct damon_ctx *c,char *buf,ssize_t len) +{ +struct damon_target *t; +struct damon_region *r; +int written =0 ; +int rc; + +damon_for_each_target (t, c) { +damon_for_each_region (r, t) { + rc =snprintf (&buf[written], len - written, +"%lu %lu %lu\n" , + t->id, r->ar.start, r->ar.end); +if (!rc) +return -ENOMEM ; + written += rc; + } + } +return written; +} + +static ssize_t debugfs_init_regions_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct damon_ctx *ctx = &damon_user_ctx; +char *kbuf; +ssize_t len; + + kbuf =kmalloc (count,GFP_KERNEL ); +if (!kbuf) +return -ENOMEM ; + +mutex_lock (&ctx->kdamond_lock); +if (ctx->kdamond) { +mutex_unlock (&ctx->kdamond_lock); +return -EBUSY ; + } + + len =sprint_init_regions (ctx, kbuf, count); +mutex_unlock (&ctx->kdamond_lock); +if (len <0 ) + goto out; + len =simple_read_from_buffer (buf, count, ppos, kbuf, len); + +out: +kfree (kbuf); +return len; +} + +static int add_init_region (struct damon_ctx *c, +unsigned long target_id,struct damon_addr_range *ar) +{ +struct damon_target *t; +struct damon_region *r, *prev; +int rc = -EINVAL ; + +if (ar->start >= ar->end) +return -EINVAL ; + +damon_for_each_target (t, c) { +if (t->id == target_id) { + r =damon_new_region (ar->start, ar->end); +if (!r) +return -ENOMEM ; +damon_add_region (r, t); +if (nr_damon_regions (t) >1 ) { + prev =damon_prev_region (r); +if (prev->ar.end > r->ar.start) { +damon_destroy_region (r); +return -EINVAL ; + } + } + rc =0 ; + } + } +return rc; +} + +static int set_init_regions (struct damon_ctx *c,const char *str,ssize_t len) +{ +struct damon_target *t; +struct damon_region *r, *next; +int pos =0 , parsed, ret; +unsigned long target_id; +struct damon_addr_range ar; +int err; + +damon_for_each_target (t, c) { +damon_for_each_region_safe (r, next, t) +damon_destroy_region (r); + } + +while (pos < len) { + ret =sscanf (&str[pos],"%lu %lu %lu%n" , + &target_id, &ar.start, &ar.end, &parsed); +if (ret !=3 ) +break ; + err =add_init_region (c, target_id, &ar); +if (err) + goto fail; + pos += parsed; + } + +return 0 ; + +fail: +damon_for_each_target (t, c) { +damon_for_each_region_safe (r, next, t) +damon_destroy_region (r); + } +return err; +} + +static ssize_t debugfs_init_regions_write (struct file *file, +const char __user *buf,size_t count, +loff_t *ppos) +{ +struct damon_ctx *ctx = &damon_user_ctx; +char *kbuf; +ssize_t ret = count; +int err; + + kbuf =user_input_str (buf, count, ppos); +if (IS_ERR (kbuf)) +return PTR_ERR (kbuf); + +mutex_lock (&ctx->kdamond_lock); +if (ctx->kdamond) { + ret = -EBUSY ; + goto unlock_out; + } + + err =set_init_regions (ctx, kbuf, ret); +if (err) + ret = err; + +unlock_out: +mutex_unlock (&ctx->kdamond_lock); +kfree (kbuf); +return ret; +} +static ssize_t debugfs_attrs_read (struct file *file,char __user *buf,size_t count,loff_t *ppos) {
@@ -2077,6 +2218,12 @@ static const struct file_operations record_fops = { .write = debugfs_record_write, }; +static const struct file_operations init_regions_fops = { + .owner =THIS_MODULE , + .read = debugfs_init_regions_read, + .write = debugfs_init_regions_write, +}; +static const struct file_operations attrs_fops = { .owner =THIS_MODULE , .read = debugfs_attrs_read,
@@ -2087,10 +2234,11 @@ static struct dentry *debugfs_root;static int __init damon_debugfs_init (void ) { -const char *const file_names[] = {"attrs" ,"record" ,"schemes" , -"target_ids" ,"monitor_on" }; -const struct file_operations *fops[] = {&attrs_fops, &record_fops, - &schemes_fops, &target_ids_fops, &monitor_on_fops}; +const char *const file_names[] = {"attrs" ,"init_regions" ,"record" , +"schemes" ,"target_ids" ,"monitor_on" }; +const struct file_operations *fops[] = {&attrs_fops, + &init_regions_fops, &record_fops, &schemes_fops, + &target_ids_fops, &monitor_on_fops};int i; debugfs_root =debugfs_create_dir ("damon" ,NULL );
Signature · 1 line
2.17.1
RFC v7 2/10 tools/damon: Support init target regions specification
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit updates the damon user space tool to support the initial monitoring target regions specification.
--- tools/damon/_damon.py | 39 +++++++++++++++++++++++++++++++++++++++ tools/damon/record.py | 12 +++++++----- tools/damon/schemes.py | 12 +++++++----- 3 files changed, 53 insertions(+), 10 deletions(-)
tools/damon/_damon.py +39 -0
@@ -12,12 +12,25 @@ debugfs_attrs = None debugfs_record = None debugfs_schemes = None debugfs_target_ids = None +debugfs_init_regions = None debugfs_monitor_on = None def set_target_id(tid): with open(debugfs_target_ids, 'w') as f: f.write('%s\n' % tid) +def set_target(tid, init_regions=[]): + rc = set_target_id(tid) + if rc: + return rc + + if not os.path.exists(debugfs_init_regions): + return 0 + + string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions]) + return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), + shell=True, executable='/bin/bash') + def turn_damon(on_off): return subprocess.call("echo %s > %s" % (on_off, debugfs_monitor_on), shell=True, executable="/bin/bash")
@@ -97,6 +110,7 @@ def chk_update_debugfs(debugfs): global debugfs_record global debugfs_schemes global debugfs_target_ids + global debugfs_init_regions global debugfs_monitor_on debugfs_damon = os.path.join(debugfs, 'damon')
@@ -104,6 +118,7 @@ def chk_update_debugfs(debugfs): debugfs_record = os.path.join(debugfs_damon, 'record') debugfs_schemes = os.path.join(debugfs_damon, 'schemes') debugfs_target_ids = os.path.join(debugfs_damon, 'target_ids') + debugfs_init_regions = os.path.join(debugfs_damon, 'init_regions') debugfs_monitor_on = os.path.join(debugfs_damon, 'monitor_on') if not os.path.isdir(debugfs_damon):
@@ -131,6 +146,26 @@ def cmd_args_to_attrs(args): return Attrs(sample_interval, aggr_interval, regions_update_interval, min_nr_regions, max_nr_regions, rbuf_len, rfile_path, schemes) +def cmd_args_to_init_regions(args): + regions = [] + for arg in args.regions.split(): + addrs = arg.split('-') + try: + if len(addrs) != 2: + raise Exception('two addresses not given') + start = int(addrs[0]) + end = int(addrs[1]) + if start >= end: + raise Exception('start >= end') + if regions and regions[-1][1] > start: + raise Exception('regions overlap') + except Exception as e: + print('Wrong \'--regions\' argument (%s)' % e) + exit(1) + + regions.append([start, end]) + return regions + def set_attrs_argparser(parser): parser.add_argument('-d', '--debugfs', metavar='<debugfs>', type=str, default='/sys/kernel/debug', help='debugfs mounted path')
@@ -144,3 +179,7 @@ def set_attrs_argparser(parser): default=10, help='minimal number of regions') parser.add_argument('-m', '--maxr', metavar='<# regions>', type=int, default=1000, help='maximum number of regions') + +def set_init_regions_argparser(parser): + parser.add_argument('-r', '--regions', metavar='"<start>-<end> ..."', + type=str, default='', help='monitoring target address regions')
tools/damon/record.py +7 -5
@@ -24,7 +24,7 @@ def pidfd_open(pid): return syscall(NR_pidfd_open, pid, 0) -def do_record(target, is_target_cmd, attrs, old_attrs, pidfd): +def do_record(target, is_target_cmd, init_regions, attrs, old_attrs, pidfd): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old')
@@ -48,8 +48,8 @@ def do_record(target, is_target_cmd, attrs, old_attrs, pidfd): # only for reference of the pidfd usage. target = 'pidfd %s' % fd - if _damon.set_target_id(target): - print('target id setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target)
@@ -91,6 +91,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='<target>', help='the target command or the pid to record') parser.add_argument('--pidfd', action='store_true',
@@ -117,19 +118,20 @@ def main(args=None): args.schemes = '' pidfd = args.pidfd new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - do_record(target, True, new_attrs, orig_attrs, pidfd) + do_record(target, True, init_regions, new_attrs, orig_attrs, pidfd) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - do_record(target, False, new_attrs, orig_attrs, pidfd) + do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) if __name__ == '__main__': main()
tools/damon/schemes.py +7 -5
@@ -14,7 +14,7 @@ import time import _convert_damos import _damon -def run_damon(target, is_target_cmd, attrs, old_attrs): +def run_damon(target, is_target_cmd, init_regions, attrs, old_attrs): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old')
@@ -27,8 +27,8 @@ def run_damon(target, is_target_cmd, attrs, old_attrs): if is_target_cmd: p = subprocess.Popen(target, shell=True, executable='/bin/bash') target = p.pid - if _damon.set_target_pid(target): - print('pid setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target)
@@ -68,6 +68,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='<target>', help='the target command or the pid to record') parser.add_argument('-c', '--schemes', metavar='<file>', type=str,
@@ -92,19 +93,20 @@ def main(args=None): args.out = 'null' args.schemes = _convert_damos.convert(args.schemes, args.sample, args.aggr) new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - run_damon(target, True, new_attrs, orig_attrs) + run_damon(target, True, init_regions, new_attrs, orig_attrs) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - run_damon(target, False, new_attrs, orig_attrs) + run_damon(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main()
Signature · 1 line
2.17.1
RFC v7 3/10 mm/damon-test: Add more unit tests for 'init_regions'
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit adds more test cases for the new feature, 'init_regions'.
--- mm/damon-test.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
mm/damon-test.h +53 -0
@@ -161,6 +161,58 @@ static void damon_test_set_recording(struct kunit *test)KUNIT_EXPECT_STREQ (test, ctx->rfile_path,"foo" ); } +static void damon_test_set_init_regions (struct kunit *test) +{ +struct damon_ctx *ctx = &damon_user_ctx; +unsigned long ids[] = {1 ,2 ,3 }; +/* Each line represents one region in ``<target id> <start> <end>`` */ +char *const valid_inputs[] = {"2 10 20\n 2 20 30\n2 35 45" , +"2 10 20\n" , +"2 10 20\n1 39 59\n1 70 134\n 2 20 25\n" , +"" }; +/* Reading the file again will show sorted, clean output */ +char *const valid_expects[] = {"2 10 20\n2 20 30\n2 35 45\n" , +"2 10 20\n" , +"1 39 59\n1 70 134\n2 10 20\n2 20 25\n" , +"" }; +char *const invalid_inputs[] = {"4 10 20\n" ,/* target not exists */ +"2 10 20\n 2 14 26\n" ,/* regions overlap */ +"1 10 20\n2 30 40\n 1 5 8" };/* not sorted by address */ +char *input, *expect; +int i, rc; +char buf[256 ]; + +damon_set_targets (ctx, ids,3 ); + +/* Put valid inputs and check the results */ +for (i =0 ; i <ARRAY_SIZE (valid_inputs); i++) { + input = valid_inputs[i]; + expect = valid_expects[i]; + + rc =set_init_regions (ctx, input,strnlen (input,256 )); +KUNIT_EXPECT_EQ (test, rc,0 ); + +memset (buf,0 ,256 ); +sprint_init_regions (ctx, buf,256 ); + +KUNIT_EXPECT_STREQ (test, (char *)buf, expect); + } +/* Put invlid inputs and check the return error code */ +for (i =0 ; i <ARRAY_SIZE (invalid_inputs); i++) { + input = invalid_inputs[i]; +pr_info ("input: %s\n" , input); + rc =set_init_regions (ctx, input,strnlen (input,256 )); +KUNIT_EXPECT_EQ (test, rc, -EINVAL ); + +memset (buf,0 ,256 ); +sprint_init_regions (ctx, buf,256 ); + +KUNIT_EXPECT_STREQ (test, (char *)buf,"" ); + } + +damon_set_targets (ctx,NULL ,0 ); +} +static void __link_vmas (struct vm_area_struct *vmas,ssize_t nr_vmas) {int i, j;
@@ -645,6 +697,7 @@ static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damon_test_regions),KUNIT_CASE (damon_test_set_targets),KUNIT_CASE (damon_test_set_recording), +KUNIT_CASE (damon_test_set_init_regions),KUNIT_CASE (damon_test_three_regions_in_vmas),KUNIT_CASE (damon_test_aggregate), KUNIT_CASE(damon_test_write_rbuf),
Signature · 1 line
2.17.1
RFC v7 4/10 selftests/damon/_chk_record: Do not check number of gaps
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
Now the regions can be explicitly set as users want. Therefore checking the number of gaps doesn't make sense. Remove the condition.
--- tools/testing/selftests/damon/_chk_record.py | 6 ------ 1 file changed, 6 deletions(-)
tools/testing/selftests/damon/_chk_record.py +0 -6
@@ -37,12 +37,9 @@ def chk_task_info(f): print('too many regions: %d > %d' % (nr_regions, max_nr_regions)) exit(1) - nr_gaps = 0 eaddr = 0 for r in range(nr_regions): saddr = struct.unpack('L', f.read(8))[0] - if eaddr and saddr != eaddr: - nr_gaps += 1 eaddr = struct.unpack('L', f.read(8))[0] nr_accesses = struct.unpack('I', f.read(4))[0]
@@ -56,9 +53,6 @@ def chk_task_info(f): print('too high nr_access: expected %d but %d' % (max_nr_accesses, nr_accesses)) exit(1) - if nr_gaps != 2: - print('number of gaps are not two but %d' % nr_gaps) - exit(1) def parse_time_us(bindat): sec = struct.unpack('l', bindat[0:8])[0]
Signature · 1 line
2.17.1
RFC v7 5/10 Docs/admin-guide/mm/damon: Document 'init_regions' feature
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit adds description of the 'init_regions' feature in the DAMON usage document.
--- Documentation/admin-guide/mm/damon/usage.rst | 41 +++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +39 -2
@@ -281,8 +281,9 @@ for at least 100 milliseconds using below commands:: debugfs Interface ================= -DAMON exports five files, ``attrs``, ``target_ids``, ``record``, ``schemes`` -and ``monitor_on`` under its debugfs directory, ``<debugfs>/damon/``. +DAMON exports six files, ``attrs``, ``target_ids``, ``init_regions``, +``record``, ``schemes`` and ``monitor_on`` under its debugfs directory, +``<debugfs>/damon/``. Attributes
@@ -321,6 +322,42 @@ check it again:: Note that setting the target ids doesn't start the monitoring. +Initial Monitoring Target Regions +--------------------------------- + +In case of the debugfs based monitoring, DAMON automatically sets and updates +the monitoring target regions so that entire memory mappings of target +processes can be covered. However, users might want to limit the monitoring +region to specific address ranges, such as the heap, the stack, or specific +file-mapped area. Or, some users might know the initial access pattern of +their workloads and therefore want to set optimal initial regions for the +'adaptive regions adjustment'. + +In such cases, users can explicitly set the initial monitoring target regions +as they want, by writing proper values to the ``init_regions`` file. Each line +of the input should represent one region in below form.:: + + <target id> <start address> <end address> + +The ``target id`` should already in ``target_ids`` file, and the regions should +be passed in address order. For example, below commands will set a couple of +address ranges, ``1-100`` and ``100-200`` as the initial monitoring target +region of process 42, and another couple of address ranges, ``20-40`` and +``50-100`` as that of process 4242.:: + + # cd <debugfs>/damon + # echo "42 1 100 + 42 100 200 + 4242 20 40 + 4242 50 100" > init_regions + +Note that this sets the initial monitoring target regions only. In case of +virtual memory monitoring, DAMON will automatically updates the boundary of the +regions after one ``regions update interval``. Therefore, users should set the +``regions update interval`` large enough in this case, if they don't want the +update. + + Record ------
Signature · 1 line
2.17.1
RFC v7 6/10 mm/damon: Implement callbacks for physical memory monitoring
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit implements the four callbacks (->init_target_regions, ->update_target_regions, ->prepare_access_check, and ->check_accesses) for the basic access monitoring of the physical memory address space. By setting the callback pointers to point those, users can easily monitor the accesses to the physical memory.
Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed.
Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks.
--- include/linux/damon.h | 6 ++ mm/damon.c | 200 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+)
include/linux/damon.h +6 -0
@@ -242,6 +242,12 @@ unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx);bool kdamond_vm_target_valid (struct damon_target *t);void kdamond_vm_cleanup (struct damon_ctx *ctx); +/* Reference callback implementations for physical memory */ +void kdamond_init_phys_regions (struct damon_ctx *ctx); +void kdamond_update_phys_regions (struct damon_ctx *ctx); +void kdamond_prepare_phys_access_checks (struct damon_ctx *ctx); +unsigned int kdamond_check_phys_accesses (struct damon_ctx *ctx); +int damon_set_targets (struct damon_ctx *ctx,unsigned long *ids,ssize_t nr_ids); int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int,
mm/damon.c +200 -0
229 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC v7 7/10 mm/damon/debugfs: Support physical memory monitoring
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit makes the debugfs interface to support the physical memory monitoring, in addition to the virtual memory monitoring.
Users can do the physical memory monitoring by writing a special keyword, 'paddr\n' to the 'pids' debugfs file. Then, DAMON will check the special keyword and configure the callbacks of the monitoring context for the debugfs user for physical memory. This will internally add one fake monitoring target process, which has pid as -1.
Unlike the virtual memory monitoring, DAMON debugfs will not automatically set the monitoring target region. Therefore, users should also set the monitoring target address region using the 'init_regions' debugfs file. While doing this, the 'pid' in the input should be '-1'.
Finally, the physical memory monitoring will not automatically terminated because it has fake monitoring target process. The user should explicitly turn off the monitoring by writing 'off' to the 'monitor_on' debugfs file.
--- mm/damon.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
mm/damon.c +23 -3
@@ -2113,9 +2113,29 @@ static ssize_t debugfs_target_ids_write(struct file *file,return PTR_ERR (kbuf); nrs = kbuf; -if (!strncmp (kbuf,"pidfd " ,6 )) { - received_pidfds = true; - nrs = &kbuf[6 ]; +if (!strncmp (kbuf,"paddr\n" , count)) { +/* Configure the context for physical memory monitoring */ + ctx->init_target_regions = kdamond_init_phys_regions; + ctx->update_target_regions = kdamond_update_phys_regions; + ctx->prepare_access_checks = kdamond_prepare_phys_access_checks; + ctx->check_accesses = kdamond_check_phys_accesses; + ctx->target_valid =NULL ; + ctx->cleanup =NULL ; + +/* target id is meaningless here, but we set it just for fun */ +snprintf (kbuf, count,"42 " ); + }else { +/* Configure the context for virtual memory monitoring */ + ctx->init_target_regions = kdamond_init_vm_regions; + ctx->update_target_regions = kdamond_update_vm_regions; + ctx->prepare_access_checks = kdamond_prepare_vm_access_checks; + ctx->check_accesses = kdamond_check_vm_accesses; + ctx->target_valid = kdamond_vm_target_valid; + ctx->cleanup = kdamond_vm_cleanup; +if (!strncmp (kbuf,"pidfd " ,6 )) { + received_pidfds = true; + nrs = &kbuf[6 ]; + } } targets =str_to_target_ids (nrs, ret, &nr_targets);
Signature · 1 line
2.17.1
RFC v7 8/10 tools/damon/record: Support physical memory monitoring
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit allows users to record the data accesses on physical memory address space by passing 'paddr' as target to 'damo-record'. If the init regions are given, the regions will be monitored. Else, it will monitor biggest conitguous 'System RAM' region in '/proc/iomem' and monitor the region.
--- tools/damon/_damon.py | 2 ++ tools/damon/record.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-)
tools/damon/_damon.py +2 -0
@@ -27,6 +27,8 @@ def set_target(tid, init_regions=[]): if not os.path.exists(debugfs_init_regions): return 0 + if tid == 'paddr': + tid = 42 string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions]) return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), shell=True, executable='/bin/bash')
tools/damon/record.py +28 -1
@@ -101,6 +101,29 @@ def set_argparser(parser): parser.add_argument('-o', '--out', metavar='<file path>', type=str, default='damon.data', help='output file path') +def default_paddr_region(): + "Largest System RAM region becomes the default" + ret = [] + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) != 2: + continue + name = fields[1].strip() + if name != 'System RAM': + continue + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + + sz_region = end - start + if not ret or sz_region > (ret[1] - ret[0]): + ret = [start, end] + return ret + def main(args=None): global orig_attrs if not args:
@@ -122,7 +145,11 @@ def main(args=None): target = args.target target_fields = target.split() - if not subprocess.call('which %s &> /dev/null' % target_fields[0], + if target == 'paddr': # physical memory address space + if not init_regions: + init_regions = [default_paddr_region()] + do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) + elif not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): do_record(target, True, init_regions, new_attrs, orig_attrs, pidfd) else:
Signature · 1 line
2.17.1
RFC v7 9/10 tools/damon/record: Support NUMA specific recording
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit updates the DAMON user space tool (damo-record) for NUMA specific physical memory monitoring. With this change, users can monitor accesses to physical memory of specific NUMA node.
--- tools/damon/_paddr_layout.py | 147 +++++++++++++++++++++++++++++++++++ tools/damon/record.py | 18 ++++- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tools/damon/_paddr_layout.py
tools/damon/_paddr_layout.py new file +147 -0
@@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import os + +class PaddrRange: + start = None + end = None + nid = None + state = None + name = None + + def __init__(self, start, end, nid, state, name): + self.start = start + self.end = end + self.nid = nid + self.state = state + self.name = name + + def interleaved(self, prange): + if self.end <= prange.start: + return None + if prange.end <= self.start: + return None + return [max(self.start, prange.start), min(self.end, prange.end)] + + def __str__(self): + return '%x-%x, nid %s, state %s, name %s' % (self.start, self.end, + self.nid, self.state, self.name) + +class MemBlock: + nid = None + index = None + state = None + + def __init__(self, nid, index, state): + self.nid = nid + self.index = index + self.state = state + + def __str__(self): + return '%d (%s)' % (self.index, self.state) + + def __repr__(self): + return self.__str__() + +def readfile(file_path): + with open(file_path, 'r') as f: + return f.read() + +def collapse_ranges(ranges): + ranges = sorted(ranges, key=lambda x: x.start) + merged = [] + for r in ranges: + if not merged: + merged.append(r) + continue + last = merged[-1] + if last.end != r.start or last.nid != r.nid or last.state != r.state: + merged.append(r) + else: + last.end = r.end + return merged + +def memblocks_to_ranges(blocks, block_size): + ranges = [] + for b in blocks: + ranges.append(PaddrRange(b.index * block_size, + (b.index + 1) * block_size, b.nid, b.state, None)) + + return collapse_ranges(ranges) + +def memblock_ranges(): + SYSFS='/sys/devices/system/node' + sz_block = int(readfile('/sys/devices/system/memory/block_size_bytes'), 16) + sys_nodes = [x for x in os.listdir(SYSFS) if x.startswith('node')] + + blocks = [] + for sys_node in sys_nodes: + nid = int(sys_node[4:]) + + sys_node_files = os.listdir(os.path.join(SYSFS, sys_node)) + for f in sys_node_files: + if not f.startswith('memory'): + continue + index = int(f[6:]) + sys_state = os.path.join(SYSFS, sys_node, f, 'state') + state = readfile(sys_state).strip() + + blocks.append(MemBlock(nid, index, state)) + + return memblocks_to_ranges(blocks, sz_block) + +def iomem_ranges(): + ranges = [] + + with open('/proc/iomem', 'r') as f: + # example of the line: '100000000-42b201fff : System RAM' + for line in f: + fields = line.split(':') + if len(fields) < 2: + continue + name = ':'.join(fields[1:]).strip() + addrs = fields[0].split('-') + if len(addrs) != 2: + continue + start = int(addrs[0], 16) + end = int(addrs[1], 16) + 1 + ranges.append(PaddrRange(start, end, None, None, name)) + + return ranges + +def integrate(memblock_parsed, iomem_parsed): + merged = [] + + for r in iomem_parsed: + for r2 in memblock_parsed: + if r2.start <= r.start and r.end <= r2.end: + r.nid = r2.nid + r.state = r2.state + merged.append(r) + elif r2.start <= r.start and r.start < r2.end and r2.end < r.end: + sub = PaddrRange(r2.end, r.end, None, None, r.name) + iomem_parsed.append(sub) + r.end = r2.end + r.nid = r2.nid + r.state = r2.state + merged.append(r) + merged = sorted(merged, key=lambda x: x.start) + return merged + +def paddr_ranges(): + return integrate(memblock_ranges(), iomem_ranges()) + +def pr_ranges(ranges): + print('#%12s %13s\tnode\tstate\tresource\tsize' % ('start', 'end')) + for r in ranges: + print('%13d %13d\t%s\t%s\t%s\t%d' % (r.start, r.end, r.nid, + r.state, r.name, r.end - r.start)) + +def main(): + ranges = paddr_ranges() + + pr_ranges(ranges) + +if __name__ == '__main__': + main()
tools/damon/record.py +17 -1
@@ -12,6 +12,7 @@ import subprocess import time import _damon +import _paddr_layout def pidfd_open(pid): import ctypes
@@ -98,6 +99,8 @@ def set_argparser(parser): help='use pidfd type target id') parser.add_argument('-l', '--rbuf', metavar='<len>', type=int, default=1024*1024, help='length of record result buffer') + parser.add_argument('--numa_node', metavar='<node id>', type=int, + help='if target is \'paddr\', limit it to the numa node') parser.add_argument('-o', '--out', metavar='<file path>', type=str, default='damon.data', help='output file path')
@@ -124,6 +127,15 @@ def default_paddr_region(): ret = [start, end] return ret +def paddr_region_of(numa_node): + regions = [] + paddr_ranges = _paddr_layout.paddr_ranges() + for r in paddr_ranges: + if r.nid == numa_node and r.name == 'System RAM': + regions.append([r.start, r.end]) + + return regions + def main(args=None): global orig_attrs if not args:
@@ -142,12 +154,16 @@ def main(args=None): pidfd = args.pidfd new_attrs = _damon.cmd_args_to_attrs(args) init_regions = _damon.cmd_args_to_init_regions(args) + numa_node = args.numa_node target = args.target target_fields = target.split() if target == 'paddr': # physical memory address space if not init_regions: - init_regions = [default_paddr_region()] + if numa_node: + init_regions = paddr_region_of(numa_node) + else: + init_regions = [default_paddr_region()] do_record(target, False, init_regions, new_attrs, orig_attrs, pidfd) elif not subprocess.call('which %s &> /dev/null' % target_fields[0], shell=True, executable='/bin/bash'):
Signature · 1 line
2.17.1
RFC v7 10/10 Docs/DAMON: Document physical memory monitoring support
In reply to SeongJae ParkFrom: SeongJae Park <[email protected]>
This commit updates the DAMON documents for the physical memory monitoring support.
--- Documentation/admin-guide/mm/damon/usage.rst | 42 ++++++++++++++++---- Documentation/vm/damon/design.rst | 29 +++++++++----- Documentation/vm/damon/faq.rst | 5 +-- 3 files changed, 54 insertions(+), 22 deletions(-)
Documentation/admin-guide/mm/damon/usage.rst +34 -8
@@ -10,15 +10,16 @@ DAMON provides below three interfaces for different users. This is for privileged people such as system administrators who want a just-working human-friendly interface. Using this, users can use the DAMON’s major features in a human-friendly way. It may not be highly tuned for - special cases, though. It supports only virtual address spaces monitoring. + special cases, though. It supports both virtual and physical address spaces + monitoring. - *debugfs interface.* This is for privileged user space programmers who want more optimized use of DAMON. Using this, users can use DAMON’s major features by reading from and writing to special debugfs files. Therefore, you can write and use your personalized DAMON debugfs wrapper programs that reads/writes the debugfs files instead of you. The DAMON user space tool is also a reference - implementation of such programs. It supports only virtual address spaces - monitoring. + implementation of such programs. It supports both virtual and physical + address spaces monitoring. - *Kernel Space Programming Interface.* This is for kernel space programmers. Using this, users can utilize every feature of DAMON most flexibly and efficiently by writing kernel space
@@ -49,8 +50,10 @@ Recording Data Access Pattern The ``record`` subcommand records the data access pattern of target workloads in a file (``./damon.data`` by default). You can specify the target with 1) -the command for execution of the monitoring target process, or 2) pid of -running target process. Below example shows a command target usage:: +the command for execution of the monitoring target process, 2) pid of running +target process, or 3) the special keyword, 'paddr', if you want to monitor the +system's physical memory address space. Below example shows a command target +usage:: # cd <kernel>/tools/damon/ # damo record "sleep 5"
@@ -61,6 +64,15 @@ of the process. Below example shows a pid target usage:: # sleep 5 & # damo record `pidof sleep` +Finally, below example shows the use of the special keyword, 'paddr':: + + # damo record paddr + +In this case, the monitoring target regions defaults to the largetst 'System +RAM' region specified in '/proc/iomem' file. Note that the initial monitoring +target region is maintained rather than dynamically updated like the virtual +memory address spaces monitoring case. + The location of the recorded file can be explicitly set using ``-o`` option. You can further tune this by setting the monitoring attributes. To know about the monitoring attributes in detail, please refer to the
@@ -319,20 +331,34 @@ check it again:: # cat target_ids 42 4242 +Users can also monitor the physical memory address space of the system by +writing a special keyword, "``paddr\n``" to the file. Because physical address +space monitoring doesn't support multiple targets, reading the file will show a +fake value, ``42``, as below:: + + # cd <debugfs>/damon + # echo paddr > target_ids + # cat target_ids + 42 + Note that setting the target ids doesn't start the monitoring. Initial Monitoring Target Regions --------------------------------- -In case of the debugfs based monitoring, DAMON automatically sets and updates -the monitoring target regions so that entire memory mappings of target -processes can be covered. However, users might want to limit the monitoring +In case of the virtual address space monitoring, DAMON automatically sets and +updates the monitoring target regions so that entire memory mappings of target +processes can be covered. However, users might want to limit the monitoring region to specific address ranges, such as the heap, the stack, or specific file-mapped area. Or, some users might know the initial access pattern of their workloads and therefore want to set optimal initial regions for the 'adaptive regions adjustment'. +In contrast, DAMON do not automatically sets and updates the monitoring target +regions in case of physical memory monitoring. Therefore, users should set the +monitoring target regions by themselves. + In such cases, users can explicitly set the initial monitoring target regions as they want, by writing proper values to the ``init_regions`` file. Each line of the input should represent one region in below form.::
Documentation/vm/damon/design.rst +18 -11
@@ -35,27 +35,34 @@ 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. -DAMON currently provides the implementation of the primitives for only the -virtual address spaces. Below two subsections describe how it works. +DAMON currently provides the implementations of the primitives for the physical +and virtual address spaces. Below two subsections describe how those work. PTE Accessed-bit Based Access Check ----------------------------------- -The implementation for the virtual address space uses PTE Accessed-bit for -basic access checks. It finds the relevant PTE Accessed bit from the address -by walking the page table for the target task of the address. In this way, the -implementation finds and clears the bit for next sampling target address and -checks whether the bit 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 logic, as Idle page tracking does. +Both of the implementations for physical and virtual address spaces use PTE +Accessed-bit for basic access checks. Only one difference is the way of +finding the relevant PTE Accessed bit(s) from the address. While the +implementation for the virtual address walks the page table for the target task +of the address, the implementation for the physical address walks every page +table having a mapping to the address. In this way, the implementations find +and clear the bit(s) for next sampling target address and checks whether the +bit(s) 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 logic, as Idle page tracking does. VMA-based Target Address Range Construction ------------------------------------------- +This is only for the virtual address space primitives implementation. That for +the physical address space simply asks users to manually set the monitoring +target address ranges. + Only small parts in the super-huge virtual address space of the processes are mapped to the physical memory and accessed. Thus, tracking the unmapped address regions is just wasteful. However, because DAMON can deal with some
Documentation/vm/damon/faq.rst +2 -3
@@ -43,10 +43,9 @@ constructions and actual access checks can be implemented and configured on the DAMON core by the users. In this way, DAMON users can monitor any address space with any access check technique. -Nonetheless, DAMON provides vma tracking and PTE Accessed bit check based +Nonetheless, DAMON provides vma/rmap tracking and PTE Accessed bit check based implementations of the address space dependent functions for the virtual memory -by default, for a reference and convenient use. In near future, we will -provide those for physical memory address space. +and the physical memory by default, for a reference and convenient use. Can I simply monitor page granularity?
Signature · 1 line
2.17.1
Re: [RFC v7 03/10] mm/damon-test: Add more unit tests for 'init_regions'
In reply to SeongJae ParkQuoted 6 lines · SeongJae Park
From: SeongJae Park <[email protected]>
This commit adds more test cases for the new feature, '
init_regions'.Signed-off-by SeongJae Park <[email protected]>
Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
In reply to SeongJae ParkQuoted 20 lines · SeongJae Park
From: SeongJae Park <[email protected]>
This commit implements the four callbacks (->init_target_regions, ->update_target_regions, ->prepare_access_check, and ->check_accesses) for the basic access monitoring of the physical memory address space. By setting the callback pointers to point those, users can easily monitor the accesses to the physical memory.
Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed.
Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks.
Signed-off-by SeongJae Park <[email protected]>
[snip]
Quoted 4 lines
mm/damon.c +4
-0+static void damon_phys_mkold (unsigned long paddr) +{ +struct page *page =damon_phys_get_page (PHYS_PFN (paddr)); +struct rmap_walk_control rwc = {
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 883
Quoted 10 lines
mm/damon.c +10
-0+ .rmap_one = damon_page_mkold, + .anon_lock = page_lock_anon_vma_read, + }; +bool need_lock; + +if (!page) +return ; + +if (!page_mapped (page) || !page_rmapping (page)) +return ;
I don't think you want to skip the unmapped pages. The point of physical address space monitoring was to include the monitoring of unmapped pages, so, skipping them invalidates the underlying motivation.
Quoted 12 lines
mm/damon.c +12
-0+ + need_lock = !PageAnon (page) ||PageKsm (page); +if (need_lock && !trylock_page (page)) +return ; + +rmap_walk (page, &rwc); + +if (need_lock) +unlock_page (page); +put_page (page); +} +
[snip]
Quoted 10 lines
mm/damon.c +10
-0+ +static bool damon_phys_young (unsigned long paddr,unsigned long *page_sz) +{ +struct page *page =damon_phys_get_page (PHYS_PFN (paddr)); +struct damon_phys_access_chk_result result = { + .page_sz =PAGE_SIZE , + .accessed = false, + }; +struct rmap_walk_control rwc = { + .arg = &result,
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 949
Quoted 10 lines
mm/damon.c +10
-0+ .rmap_one = damon_page_accessed, + .anon_lock = page_lock_anon_vma_read, + }; +bool need_lock; + +if (!page) +return false; + +if (!page_mapped (page) || !page_rmapping (page)) +return false;
Same here.
Quoted 15 lines
mm/damon.c +15
-0+ + need_lock = !PageAnon (page) ||PageKsm (page); +if (need_lock && !trylock_page (page)) +return false; + +rmap_walk (page, &rwc); + +if (need_lock) +unlock_page (page); +put_page (page); + + *page_sz = result.page_sz; +return result.accessed; +} +
Quoted 26 lines · SeongJae Park
From: SeongJae Park <[email protected]>
Changes from Previous Version
=============================- Use 42 as the fake target id for paddr instead of -1
- Fix a typoIntroduction
============DAMON[1] programming interface users can extend DAMON for any address space by configuring the address-space specific low level primitives with appropriate ones including their own implementations. However, because the implementation for the virtual address space is only available now, the users should implement their own for other address spaces. Worse yet, the user space users who rely on the debugfs interface and user space tool, cannot implement their own.
This patchset implements another reference implementation of the low level primitives for the physical memory address space. With this change, hence, the kernel space users can monitor both the virtual and the physical address spaces by simply changing the configuration in the runtime. Further, this patchset links the implementation to the debugfs interface and the user space tool for the user space users.
Quoted 5 lines
Note that the implementation supports only the user memory, as same to the idle page access tracking feature.
I am still struggling to find the benefit of this feature the way it is implemented i.e. region based physical address space monitoring. What exactly am I supposed to do for a given hot (or cold) physical region? In a containerized world, that region can contain pages from any cgroup. I can not really do anything about the accesses PHY-DAMON provides me for a region.
Now if you give me per-page information that would be useful as I can at least get per-cgroup accesses (idle or re-use data) but that would be as costly as Page Idle Tracking.
Quoted 33 lines · On Wed, 19 Aug 2020 18:21:44 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 26 lines · SeongJae Park
From: SeongJae Park <[email protected]>
Changes from Previous Version
=============================- Use 42 as the fake target id for paddr instead of -1
- Fix a typoIntroduction
============DAMON[1] programming interface users can extend DAMON for any address space by configuring the address-space specific low level primitives with appropriate ones including their own implementations. However, because the implementation for the virtual address space is only available now, the users should implement their own for other address spaces. Worse yet, the user space users who rely on the debugfs interface and user space tool, cannot implement their own.
This patchset implements another reference implementation of the low level primitives for the physical memory address space. With this change, hence, the kernel space users can monitor both the virtual and the physical address spaces by simply changing the configuration in the runtime. Further, this patchset links the implementation to the debugfs interface and the user space tool for the user space users.
Quoted 5 lines
Note that the implementation supports only the user memory, as same to the idle page access tracking feature.
Quoted 6 lines
I am still struggling to find the benefit of this feature the way it is implemented i.e. region based physical address space monitoring. What exactly am I supposed to do for a given hot (or cold) physical region? In a containerized world, that region can contain pages from any cgroup. I can not really do anything about the accesses PHY-DAMON provides me for a region.
Technically speaking, this patchset introduces an implementation of DAMON's low level primitives for physical address space of LRU-listed pages. In other words, it is not designed for cgroups case. Also, please note that this patchset is only RFC, because it aims to only show the future plan of DAMON and get opinions about the concept before being serious. It will be serious only after the DAMON patchset is merged. Maybe I didn' made this point clear in the CV, sorry. I will state this clearly in the next spin.
However, owing to the flexible design of DAMON, you can still use DAMON for cgroups case, though you need to make some efforts. There could be a number of ways.
First, you could figure out the physical address regions for the target cgroups by yourself, set the target regions by yourself in 'damon_ctx' object and pass it to 'damon_start()'. For dynamic page allocations, you could check if a monitored region belongs to your target cgroup or not from your action making code, which could be implemented in the '->sample_cb()' or '->aggregate_cb()' callbacks.
Note that you can even update the regions inside the callbacks. That is, you can remove regions containing pages of other containers, add new pages allocated for your target containers, adjust regions having pages of both other container and your target containers to represent only your target container's.
Second, you could expand DAMON for cgroups by implementing your own low level primitives. You could also reuse some of the current implementation. For example, you could implement only '->init_target_regions' and '->update_target_regions' callbacks again so that only the pages of your target cgroup belongs in the target regions. However, if you need to monitor non-LRU-listed pages, you should implement '->prepare_access_checks()' and '->check_accesses()' callbacks.
Quoted 4 lines
Now if you give me per-page information that would be useful as I can at least get per-cgroup accesses (idle or re-use data) but that would be as costly as Page Idle Tracking.
So, seems you are saying about the 'adaptive regions adjustment' disabled page granularity monitoring case.
Indeed. Same information comes with same overhead. Moreover, in the page granularity monitoring case, DAMON will make more space overhead (at least 8 bytes per page), because DAMON will represent each page as a physical address region having start address and end address, while Idle Pages Tracking can use only pfn. I'm planning optimizations for this page granularity case as a future work.
However, if you don't strictly need page granularity accuracy, you could reduce the overhead by using larger granularity. That is, you can set the monitoring granularity as you want while the adaptive regions adjustment is disabled. You could even use variable granularity in this case using the callbacks mentioned above.
So, DAMON is a framework rather than a tool. Though it comes with basic applications using DAMON as a framework (e.g., the virtual address space low primitives implementation, DAMON debugfs interface, and the DAMON user space tool) that could be useful in simple use cases, you need to code your application on it if your use cases are out of the simple cases. I will also develop more of such applications for more use-cases, but it will be only after the framework is complete enough to be merged in the mainline.
Thanks,
SeongJae Park
Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
In reply to Shakeel ButtQuoted 33 lines · On Wed, 19 Aug 2020 17:26:15 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 20 lines · SeongJae Park
From: SeongJae Park <[email protected]>
This commit implements the four callbacks (->init_target_regions, ->update_target_regions, ->prepare_access_check, and ->check_accesses) for the basic access monitoring of the physical memory address space. By setting the callback pointers to point those, users can easily monitor the accesses to the physical memory.
Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed.
Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks.
Signed-off-by SeongJae Park <[email protected]>[snip]
Quoted 11 lines
mm/damon.c +11
-0+static void damon_phys_mkold (unsigned long paddr) +{ +struct page *page =damon_phys_get_page (PHYS_PFN (paddr)); +struct rmap_walk_control rwc = { + .rmap_one = damon_page_mkold, + .anon_lock = page_lock_anon_vma_read, + }; +bool need_lock; + +if (!page) +return ;
Quoted 8 lines
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 883
Quoted 3 lines
mm/damon.c +3
-0+ +if (!page_mapped (page) || !page_rmapping (page)) +return ;I don't think you want to skip the unmapped pages. The point of physical address space monitoring was to include the monitoring of unmapped pages, so, skipping them invalidates the underlying motivation.
I think my answer to your other mail[1] could be an answer to this. Let me quote some from it:
``` Technically speaking, this patchset introduces an implementation of DAMON's low level primitives for physical address space of LRU-listed pages. In other words, it is not designed for cgroups case. Also, please note that this patchset is only RFC, because it aims to only show the future plan of DAMON and get opinions about the concept before being serious. It will be serious only after the DAMON patchset is merged. Maybe I didn' made this point clear in the CV, sorry. I will state this clearly in the next spin. ```
``` So, DAMON is a framework rather than a tool. Though it comes with basic applications using DAMON as a framework (e.g., the virtual address space low primitives implementation, DAMON debugfs interface, and the DAMON user space tool) that could be useful in simple use cases, you need to code your application on it if your use cases are out of the simple cases. I will also develop more of such applications for more use-cases, but it will be only after the framework is complete enough to be merged in the mainline. ```
Of course, we could prioritize the cgroup support if strongly required, though I still prefer focusing on the framework itself for now.
[1] https://lore.kernel.org/linux-mm/[email protected]/
Thanks,
SeongJae Park
Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
Quoted 48 lines · SeongJae Park
Quoted 33 lines · On Wed, 19 Aug 2020 17:26:15 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 20 lines · SeongJae Park
From: SeongJae Park <[email protected]>
This commit implements the four callbacks (->init_target_regions, ->update_target_regions, ->prepare_access_check, and ->check_accesses) for the basic access monitoring of the physical memory address space. By setting the callback pointers to point those, users can easily monitor the accesses to the physical memory.
Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed.
Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks.
Signed-off-by SeongJae Park <[email protected]>[snip]
Quoted 11 lines
mm/damon.c +11
-0+static void damon_phys_mkold (unsigned long paddr) +{ +struct page *page =damon_phys_get_page (PHYS_PFN (paddr)); +struct rmap_walk_control rwc = { + .rmap_one = damon_page_mkold, + .anon_lock = page_lock_anon_vma_read, + }; +bool need_lock; + +if (!page) +return ;Quoted 8 lines
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 883
Quoted 3 lines
mm/damon.c +3
-0+ +if (!page_mapped (page) || !page_rmapping (page)) +return ;I don't think you want to skip the unmapped pages. The point of physical address space monitoring was to include the monitoring of unmapped pages, so, skipping them invalidates the underlying motivation.
I think my answer to your other mail[1] could be an answer to this. Let me quote some from it:
Quoted 9 lines
``` Technically speaking, this patchset introduces an implementation of DAMON's low level primitives for physical address space of LRU-listed pages. In other words, it is not designed for cgroups case. Also, please note that this patchset is only RFC, because it aims to only show the future plan of DAMON and get opinions about the concept before being serious. It will be serious only after the DAMON patchset is merged. Maybe I didn' made this point clear in the CV, sorry. I will state this clearly in the next spin. ```
The unmapped pages are also LRU pages. Let's forget about the cgroups support for a moment, the only reason to use DAMON's physical address space monitoring is also to track the accesses of unmapped pages otherwise virtual address space monitoring already does the monitoring for mapped pages.
Quoted 19 lines
``` So, DAMON is a framework rather than a tool. Though it comes with basic applications using DAMON as a framework (e.g., the virtual address space low primitives implementation, DAMON debugfs interface, and the DAMON user space tool) that could be useful in simple use cases, you need to code your application on it if your use cases are out of the simple cases. I will also develop more of such applications for more use-cases, but it will be only after the framework is complete enough to be merged in the mainline. ```Of course, we could prioritize the cgroup support if strongly required, though I still prefer focusing on the framework itself for now.
[1] https://lore.kernel.org/linux-mm/[email protected]/
Thanks,
SeongJae Park
Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
Quoted 59 lines · On Thu, 20 Aug 2020 06:26:49 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 48 lines · SeongJae Park
Quoted 33 lines · On Wed, 19 Aug 2020 17:26:15 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 20 lines · SeongJae Park
From: SeongJae Park <[email protected]>
This commit implements the four callbacks (->init_target_regions, ->update_target_regions, ->prepare_access_check, and ->check_accesses) for the basic access monitoring of the physical memory address space. By setting the callback pointers to point those, users can easily monitor the accesses to the physical memory.
Internally, it uses the PTE Accessed bit, as similar to that of the virtual memory support. Also, it supports only user memory pages, as idle page tracking also does, for the same reason. If the monitoring target physical memory address range contains non-user memory pages, access check of the pages will do nothing but simply treat the pages as not accessed.
Users who want to use other access check primitives and/or monitor the non-user memory regions could implement and use their own callbacks.
Signed-off-by SeongJae Park <[email protected]>[snip]
Quoted 11 lines
mm/damon.c +11
-0+static void damon_phys_mkold (unsigned long paddr) +{ +struct page *page =damon_phys_get_page (PHYS_PFN (paddr)); +struct rmap_walk_control rwc = { + .rmap_one = damon_page_mkold, + .anon_lock = page_lock_anon_vma_read, + }; +bool need_lock; + +if (!page) +return ;Quoted 8 lines
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 883
Quoted 3 lines
mm/damon.c +3
-0+ +if (!page_mapped (page) || !page_rmapping (page)) +return ;I don't think you want to skip the unmapped pages. The point of physical address space monitoring was to include the monitoring of unmapped pages, so, skipping them invalidates the underlying motivation.
I think my answer to your other mail[1] could be an answer to this. Let me quote some from it:
Quoted 9 lines
``` Technically speaking, this patchset introduces an implementation of DAMON's low level primitives for physical address space of LRU-listed pages. In other words, it is not designed for cgroups case. Also, please note that this patchset is only RFC, because it aims to only show the future plan of DAMON and get opinions about the concept before being serious. It will be serious only after the DAMON patchset is merged. Maybe I didn' made this point clear in the CV, sorry. I will state this clearly in the next spin. ```
Quoted 1 line
The unmapped pages are also LRU pages.
Sorry, I missed the detail. So, the description should be updated to:
This patchset introduces an implementation of DAMON's low level primitives for physical addressspace of _mapped_ LRU pages.
Quoted 5 lines
Let's forget about the cgroups
support for a moment, the only reason to use DAMON's physical address space monitoring is also to track the accesses of unmapped pages otherwise virtual address space monitoring already does the monitoring for mapped pages.
Well, I didn't intended the use case... I just wanted to let people see the data accesses on physical address space without tracking every mappings of the pages.
Anyway, ok, we could consider supporting unmapped pages, but I'm unsure why and how much it is necessary. After all, who could access unmapped pages? Could you give me more details on the needs for access monitoring of the unmapped pages?
Thanks,
SeongJae Park
Quoted 43 lines · SeongJae Park
Quoted 33 lines · On Wed, 19 Aug 2020 18:21:44 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 26 lines · SeongJae Park
From: SeongJae Park <[email protected]>
Changes from Previous Version
=============================- Use 42 as the fake target id for paddr instead of -1
- Fix a typoIntroduction
============DAMON[1] programming interface users can extend DAMON for any address space by configuring the address-space specific low level primitives with appropriate ones including their own implementations. However, because the implementation for the virtual address space is only available now, the users should implement their own for other address spaces. Worse yet, the user space users who rely on the debugfs interface and user space tool, cannot implement their own.
This patchset implements another reference implementation of the low level primitives for the physical memory address space. With this change, hence, the kernel space users can monitor both the virtual and the physical address spaces by simply changing the configuration in the runtime. Further, this patchset links the implementation to the debugfs interface and the user space tool for the user space users.
Quoted 5 lines
Note that the implementation supports only the user memory, as same to the idle page access tracking feature.
Quoted 6 lines
I am still struggling to find the benefit of this feature the way it is implemented i.e. region based physical address space monitoring. What exactly am I supposed to do for a given hot (or cold) physical region? In a containerized world, that region can contain pages from any cgroup. I can not really do anything about the accesses PHY-DAMON provides me for a region.
Quoted 3 lines
Technically speaking, this patchset introduces an implementation of DAMON's low level primitives for physical address space of LRU-listed pages. In other words, it is not designed for cgroups case.
So, this RFC is for a system running a single workload which comprises multiple processes. Instead of registering each process with DAMON, just monitor the whole physical memory, right?
Though I am still not sure how the output from DAMON can be used in this case. DAMON told me a physical region is cold, how do I find out processes that have mapped the pages in that region to do process_madvise(PAGEOUT) on them?
Quoted 44 lines · On Thu, 20 Aug 2020 08:44:33 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 43 lines · SeongJae Park
Quoted 39 lines · On Wed, 19 Aug 2020 18:21:44 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 26 lines · SeongJae Park
From: SeongJae Park <[email protected]>
Changes from Previous Version
=============================- Use 42 as the fake target id for paddr instead of -1
- Fix a typoIntroduction
============DAMON[1] programming interface users can extend DAMON for any address space by configuring the address-space specific low level primitives with appropriate ones including their own implementations. However, because the implementation for the virtual address space is only available now, the users should implement their own for other address spaces. Worse yet, the user space users who rely on the debugfs interface and user space tool, cannot implement their own.
This patchset implements another reference implementation of the low level primitives for the physical memory address space. With this change, hence, the kernel space users can monitor both the virtual and the physical address spaces by simply changing the configuration in the runtime. Further, this patchset links the implementation to the debugfs interface and the user space tool for the user space users.
Quoted 5 lines
Note that the implementation supports only the user memory, as same to the idle page access tracking feature.
I am still struggling to find the benefit of this feature the way it is implemented i.e. region based physical address space monitoring. What exactly am I supposed to do for a given hot (or cold) physical region? In a containerized world, that region can contain pages from any cgroup. I can not really do anything about the accesses PHY-DAMON provides me for a region.
Quoted 7 lines
Quoted 3 lines
Technically speaking, this patchset introduces an implementation of DAMON's low level primitives for physical address space of LRU-listed pages. In other words, it is not designed for cgroups case.
So, this RFC is for a system running a single workload which comprises multiple processes. Instead of registering each process with DAMON, just monitor the whole physical memory, right?
Right. Also I assumed the kernel space DAMON users as the primary users of this feature.
Quoted 5 lines
Though I am still not sure how the output from DAMON can be used in this case. DAMON told me a physical region is cold, how do I find out processes that have mapped the pages in that region to do
process_madvise(PAGEOUT)on them?
Seems you are saying about the user space DAMON use. Indeed, it would be quite complicated. For example, maybe the user space could read '/proc/pid/pagemap' of every process, but this really sounds awkward. Thank you for pointing this :) Even in the virtual address case, it could be complicated.
For this reason, I am developing DAMON-based Operation Schemes[1]. It is designed to do the monitoring and optimization of specific regions fit in special monitoring result by DAMON itself. Nonetheless, current version of it supports only virtual address spaces. A support of physical address space from the feature will be another future work.
If the user space really need to do that by itself, we could provide the physical address to virtual address mapping info in addition to the monitoring result in future.
And, yes, we have so many TODO tasks that really necessary. I will eventually do all of those, but also concerning about my limited time. Nevertheless, I believe it would better to focus on the core of DAMON[2] for now and continue further TODO tasks after it is merged in the mainline, because maintainance of the code will be much easier and hopefully more developers could collaborate for the many TODO tasks.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/
Thanks,
SeongJae Park
Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
In reply to SeongJae ParkHi SeongJae,
I think there are potential memory leaks in the following execution paths
+static bool damon_page_mkold(struct page *page, struct vm_area_struct *vma,
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 872
Quoted 10 lines
mm/damon.c +9
-0+ unsigned long addr, void *arg) +{ + damon_mkold(vma->vm_mm, addr); +return true; +} + +static void damon_phys_mkold (unsigned long paddr) +{ +struct page *page =damon_phys_get_page (PHYS_PFN (paddr));
get_page() here
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 883
Quoted 12 lines
mm/damon.c +11
-0+struct rmap_walk_control rwc = { + .rmap_one = damon_page_mkold, + .anon_lock = page_lock_anon_vma_read, + }; +bool need_lock; + +if (!page) +return ; + +if (!page_mapped (page) || !page_rmapping (page)) +return ;
return without put_page()
Quoted 6 lines
mm/damon.c +5
-0+ + need_lock = !PageAnon (page) ||PageKsm (page); +if (need_lock && !trylock_page (page)) +return ; +
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 933
Quoted 10 lines
mm/damon.c +10
-0+rmap_walk (page, &rwc); + +if (need_lock) +unlock_page (page); +put_page (page); +} + +static bool damon_phys_young (unsigned long paddr,unsigned long *page_sz) +{ +struct page *page =damon_phys_get_page (PHYS_PFN (paddr));
get_page() here
Quoted 7 lines
mm/damon.c +6
-0+struct damon_phys_access_chk_result result = { + .page_sz =PAGE_SIZE , + .accessed = false, + }; +struct rmap_walk_control rwc = { + .arg = &result,
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 949
Quoted 10 lines
mm/damon.c +10
-0+ .rmap_one = damon_page_accessed, + .anon_lock = page_lock_anon_vma_read, + }; +bool need_lock; + +if (!page) +return false; + +if (!page_mapped (page) || !page_rmapping (page)) +return false;
return without put_page()
Quoted 5 lines
mm/damon.c +4
-0+ + need_lock = !PageAnon (page) ||PageKsm (page); +if (need_lock && !trylock_page (page)) +return false;
mm/damon.c unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx) · line 963
Quoted 10 lines
mm/damon.c +10
-0+ +rmap_walk (page, &rwc); + +if (need_lock) +unlock_page (page); +put_page (page); + + *page_sz = result.page_sz; +return result.accessed; +}
I observed the memory leak problem by running your userprog [1] in a kvm vm. Compare /proc/meminfo before and after running damon + userprog for about 30min then I observe a noticeable amount of DRAM is not freed even if userprog exits.
I tried to add two put_page() and the problem went away. I am not exactly sure whether adding a put_page before return is the desired behavior, nor can I think of a case to explain why put_page is necessary here for "unmapped" pages.
[1] https://github.com/sjp38/idle_page_tracking/blob/master/userprog.c
Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
Quoted 6 lines · On Fri, 28 Aug 2020 04:11:56 -0400 Alkaid <[email protected]> wrote:
[-- Attachment #1: Type: text/plain, Size: 2677 bytes --]
Hi SeongJae,
I think there are potential memory leaks in the following execution paths
Agreed, definitely memory leaks exists. Thank you for let me know this! I will post a patch for this soon.
Thanks,
SeongJae Park
[...]
Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring
Quoted 11 lines · On Fri, 28 Aug 2020 11:53:15 +0200 SeongJae Park <[email protected]> wrote:
Quoted 6 lines · On Fri, 28 Aug 2020 04:11:56 -0400 Alkaid <[email protected]> wrote:
[-- Attachment #1: Type: text/plain, Size: 2677 bytes --]
Hi SeongJae,
I think there are potential memory leaks in the following execution paths
Agreed, definitely memory leaks exists. Thank you for let me know this! I will post a patch for this soon.
And, below is the patch. The complete tree is available at:
https://github.com/sjp38/linux/tree/damon/next
Thanks,
SeongJae Park
==================================== >8 ======================================= From 8f605d807c55b536ab5b0f87306ac78033dc4499 Mon Sep 17 00:00:00 2001
From: SeongJae Park <[email protected]>
Date: Fri, 28 Aug 2020 11:29:30 +0000
Subject: [PATCH] mm/damon/paddr: Add missed 'put_page()' calls
Exceptional cases handlings in 'damon_phys_mkold()' and 'damon_phys_young()' doesn't properly put pages. This commit fixes the problem by adding the 'put_page()' call.
--- mm/damon.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-)
mm/damon.c +28 -25
@@ -836,12 +836,16 @@ unsigned int kdamond_check_vm_accesses(struct damon_ctx *ctx)/* access check functions for physical address based regions */ /* -* Get a page by pfn if it is in the LRU list. Otherwise, returns NULL. +* Get a page by @pfn if it is in the LRU list and mapped. If the page needs +* locked, do the lock and save the result in @locked. Otherwise, returns +* NULL. * -* The body of this function is stollen from the 'page_idle_get_page()'. We -* steal rather than reuse it because the code is quite simple . +* The body of this function is mostly stollen from the 'page_idle_get_page()' +* and 'page_idle_clear_pte_refs()'. We steal rather than reuse it not because +* we are great artists but the code is quite simple and we need to unify parts +* of the two functions. */ -static struct page *damon_phys_get_page (unsigned long pfn) +static struct page *damon_phys_get_page (unsigned long pfn,bool *locked) {struct page *page =pfn_to_online_page (pfn);pg_data_t *pgdat;
@@ -854,9 +858,22 @@ static struct page *damon_phys_get_page(unsigned long pfn)spin_lock_irq (&pgdat->lru_lock);if (unlikely (!PageLRU (page))) {put_page (page); - page =NULL ; +spin_unlock_irq (&pgdat->lru_lock); +return NULL ; }spin_unlock_irq (&pgdat->lru_lock); + +if (!page_mapped (page) || !page_rmapping (page)) { +put_page (page); +return NULL ; + } + + *locked = !PageAnon (page) ||PageKsm (page); +if (*locked && !trylock_page (page)) { +put_page (page); +return NULL ; + } +return page; }
@@ -869,26 +886,19 @@ static bool damon_page_mkold(struct page *page, struct vm_area_struct *vma,static void damon_phys_mkold (unsigned long paddr) { -struct page *page =damon_phys_get_page (PHYS_PFN (paddr)); +bool locked; +struct page *page =damon_phys_get_page (PHYS_PFN (paddr), &locked);struct rmap_walk_control rwc = { .rmap_one = damon_page_mkold, .anon_lock = page_lock_anon_vma_read, }; -bool need_lock;if (!page)return ; -if (!page_mapped (page) || !page_rmapping (page)) -return ; - - need_lock = !PageAnon (page) ||PageKsm (page); -if (need_lock && !trylock_page (page)) -return ; -rmap_walk (page, &rwc); -if (need_lock) +if (locked)unlock_page (page);put_page (page); }
@@ -930,7 +940,8 @@ static bool damon_page_accessed(struct page *page, struct vm_area_struct *vma,static bool damon_phys_young (unsigned long paddr,unsigned long *page_sz) { -struct page *page =damon_phys_get_page (PHYS_PFN (paddr)); +bool locked; +struct page *page =damon_phys_get_page (PHYS_PFN (paddr), &locked);struct damon_phys_access_chk_result result = { .page_sz =PAGE_SIZE , .accessed = false,
@@ -940,21 +951,13 @@ static bool damon_phys_young(unsigned long paddr, unsigned long *page_sz) .rmap_one = damon_page_accessed, .anon_lock = page_lock_anon_vma_read, }; -bool need_lock;if (!page)return false; -if (!page_mapped (page) || !page_rmapping (page)) -return false; - - need_lock = !PageAnon (page) ||PageKsm (page); -if (need_lock && !trylock_page (page)) -return false; -rmap_walk (page, &rwc); -if (need_lock) +if (locked)unlock_page (page);put_page (page);
Signature · 1 line
2.17.1