From: SeongJae Park <sj@kernel.org>
To: Xin Hao <xhao@linux.alibaba.com>
Cc: sjpark@amazon.de, akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/damon/dbgfs: Optimize target_ids interface write operation
Date: Thu, 21 Oct 2021 09:45:43 +0000 [thread overview]
Message-ID: <20211021094543.1846-1-sj@kernel.org> (raw)
In-Reply-To: <20211021085611.81211-1-xhao@linux.alibaba.com>
Hello Xin,
On Thu, 21 Oct 2021 16:56:11 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:
> When writing some pids to target_ids interface, calling scanf()
> to get 'id' may be failed. If the value of '*nr_ids' is 0 at this time,
> there is no need to return 'ids' here, we just need to release it and
> return NULL pointer to improve related code operation efficiency.
Thank you for the patch! But, I don't think this patch makes sense, because
the case (*nr_ids == 0) means not error but an ask to remove previously set
target ids. For example, it works as below now:
# echo 42 > target_ids
# cat target_ids
42
# echo > target_ids
# cat target_ids
#
But, with your patch, the behavior will be changed as below:
# echo 42 > target_ids
# cat target_ids
42
# echo > target_ids
bash: echo: write error: Cannot allocate memory
# cat target_ids
42
#
Also, this patch makes the DAMON selftest fails as below:
$ sudo make -C tools/testing/selftests/damon run_tests
make: Entering directory '/home/sjpark/linux/tools/testing/selftests/damon'
TAP version 13
1..2
# selftests: damon: debugfs_attrs.sh
# ./debugfs_attrs.sh: line 11: echo: write error: Invalid argument
# ./debugfs_attrs.sh: line 11: echo: write error: Invalid argument
# ./debugfs_attrs.sh: line 11: echo: write error: Invalid argument
# ./debugfs_attrs.sh: line 11: echo: write error: Invalid argument
# ./debugfs_attrs.sh: line 11: echo: write error: Invalid argument
# ./debugfs_attrs.sh: line 11: echo: write error: Cannot allocate memory
# writing abc 2 3 to /sys/kernel/debug/damon/target_ids doesn't return 0
# expected because: the file allows wrong input
not ok 1 selftests: damon: debugfs_attrs.sh # exit=1
If I'm missing something, please let me know.
Thanks,
SJ
>
> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
> ---
> mm/damon/dbgfs.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
> index a02cf6bee8e8..2d77bf579ffb 100644
> --- a/mm/damon/dbgfs.c
> +++ b/mm/damon/dbgfs.c
> @@ -308,21 +308,25 @@ static unsigned long *str_to_target_ids(const char *str, ssize_t len,
> unsigned long *ids;
> const int max_nr_ids = 32;
> unsigned long id;
> - int pos = 0, parsed, ret;
> + int pos = 0, parsed;
>
> *nr_ids = 0;
> ids = kmalloc_array(max_nr_ids, sizeof(id), GFP_KERNEL);
> if (!ids)
> return NULL;
> while (*nr_ids < max_nr_ids && pos < len) {
> - ret = sscanf(&str[pos], "%lu%n", &id, &parsed);
> - pos += parsed;
> - if (ret != 1)
> + if (sscanf(&str[pos], "%lu%n", &id, &parsed) != 1)
> break;
> + pos += parsed;
> ids[*nr_ids] = id;
> *nr_ids += 1;
> }
>
> + if (!*nr_ids) {
> + kfree(ids);
> + return NULL;
> + }
> +
> return ids;
> }
>
> --
> 2.31.0
next prev parent reply other threads:[~2021-10-21 9:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 8:56 [PATCH] mm/damon/dbgfs: Optimize target_ids interface write operation Xin Hao
2021-10-21 9:45 ` SeongJae Park [this message]
2021-10-21 16:42 ` Xin Hao
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=20211021094543.1846-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sjpark@amazon.de \
--cc=xhao@linux.alibaba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.