Thread (14 messages) 14 messages, 2 authors, 2020-09-01

Re: [RFC v8 01/10] mm/damon/debugfs: Allow users to set initial monitoring target regions

From: SeongJae Park <hidden>
Date: 2020-09-01 06:36:34
Also in: linux-mm, lkml

On Mon, 31 Aug 2020 20:08:44 +0200 Marco Elver [off-list ref] wrote:
On Mon, Aug 31, 2020 at 12:47PM +0200, SeongJae Park wrote:
[...]
quoted
diff --git a/mm/damon.c b/mm/damon.c
index 7e3c8c82a010..9815d22fc4de 100644
--- a/mm/damon.c
+++ b/mm/damon.c
@@ -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);
This most likely will not work as intended, because snprintf() returns
"[...] the number of characters which would be generated for the given
input, excluding the trailing null [...]". Would scnprintf() -- which
returns "[...] the number of characters written into @buf not including
the trailing '\0' [...]" -- do what you intended?
Ah, you're right!  I will use 'scnprintf' instead, not only here but in other
relevant parts.


Thanks,
SeongJae Park
quoted
+			if (!rc)
+				return -ENOMEM;
+			written += rc;
+		}
+	}
+	return written;
+}
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help