diff mbox series

[V1,1/2] mm/damon/dbgfs: Put "paddr" check into damon_pa_check() func

Message ID 44060c744a3760b1ecf6ce52a9b4ec842fa55eef.1642722660.git.xhao@linux.alibaba.com (mailing list archive)
State New
Headers show
Series [V1,1/2] mm/damon/dbgfs: Put "paddr" check into damon_pa_check() func | expand

Commit Message

haoxin Jan. 20, 2022, 4:04 p.m. UTC
The purpose of putting "paddr" check into damon_pa_check() func
is to better solve "DAMON_DBGFS" dependency on both "DAMON_VADDR"
and "DAMON_PADDR".

Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
---
 include/linux/damon.h | 1 +
 mm/damon/dbgfs.c      | 2 +-
 mm/damon/paddr.c      | 8 ++++++++
 3 files changed, 10 insertions(+), 1 deletion(-)

--
2.27.0

Comments

SeongJae Park Jan. 20, 2022, 5:47 p.m. UTC | #1
Hi Xin,

On Fri, 21 Jan 2022 00:04:27 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:

> The purpose of putting "paddr" check into damon_pa_check() func
> is to better solve "DAMON_DBGFS" dependency on both "DAMON_VADDR"
> and "DAMON_PADDR".

Syntax of "paddr" is dbgfs's own.  I don't think handling it in paddr is a
right thing to do.


Thanks,
SJ

> 
> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
> ---
>  include/linux/damon.h | 1 +
>  mm/damon/dbgfs.c      | 2 +-
>  mm/damon/paddr.c      | 8 ++++++++
>  3 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index 5e1e3a128b77..794b5f453662 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -504,6 +504,7 @@ void damon_va_set_primitives(struct damon_ctx *ctx);
>  #endif	/* CONFIG_DAMON_VADDR */
> 
>  #ifdef CONFIG_DAMON_PADDR
> +bool damon_pa_check(char *buf, size_t count);
>  bool damon_pa_target_valid(void *t);
>  void damon_pa_set_primitives(struct damon_ctx *ctx);
>  #endif	/* CONFIG_DAMON_PADDR */
> diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
> index 5b899601e56c..cdb9c1e2ab29 100644
> --- a/mm/damon/dbgfs.c
> +++ b/mm/damon/dbgfs.c
> @@ -374,7 +374,7 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
>  	if (IS_ERR(kbuf))
>  		return PTR_ERR(kbuf);
> 
> -	if (!strncmp(kbuf, "paddr\n", count)) {
> +	if (damon_pa_check(kbuf, count)) {
>  		id_is_pid = false;
>  		/* target id is meaningless here, but we set it just for fun */
>  		scnprintf(kbuf, count, "42    ");
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 5e8244f65a1a..14a6bf2a2adb 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -208,6 +208,14 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
>  	return max_nr_accesses;
>  }
> 
> +bool damon_pa_check(char *buf, size_t count)
> +{
> +	if (!strncmp(buf, "paddr\n", count))
> +		return true;
> +
> +	return false;
> +}
> +
>  bool damon_pa_target_valid(void *t)
>  {
>  	return true;
> --
> 2.27.0
> 
>
diff mbox series

Patch

diff --git a/include/linux/damon.h b/include/linux/damon.h
index 5e1e3a128b77..794b5f453662 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -504,6 +504,7 @@  void damon_va_set_primitives(struct damon_ctx *ctx);
 #endif	/* CONFIG_DAMON_VADDR */

 #ifdef CONFIG_DAMON_PADDR
+bool damon_pa_check(char *buf, size_t count);
 bool damon_pa_target_valid(void *t);
 void damon_pa_set_primitives(struct damon_ctx *ctx);
 #endif	/* CONFIG_DAMON_PADDR */
diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
index 5b899601e56c..cdb9c1e2ab29 100644
--- a/mm/damon/dbgfs.c
+++ b/mm/damon/dbgfs.c
@@ -374,7 +374,7 @@  static ssize_t dbgfs_target_ids_write(struct file *file,
 	if (IS_ERR(kbuf))
 		return PTR_ERR(kbuf);

-	if (!strncmp(kbuf, "paddr\n", count)) {
+	if (damon_pa_check(kbuf, count)) {
 		id_is_pid = false;
 		/* target id is meaningless here, but we set it just for fun */
 		scnprintf(kbuf, count, "42    ");
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 5e8244f65a1a..14a6bf2a2adb 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -208,6 +208,14 @@  static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
 	return max_nr_accesses;
 }

+bool damon_pa_check(char *buf, size_t count)
+{
+	if (!strncmp(buf, "paddr\n", count))
+		return true;
+
+	return false;
+}
+
 bool damon_pa_target_valid(void *t)
 {
 	return true;