From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 671CDC433FE for ; Thu, 21 Oct 2021 09:45:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DC2B860D42 for ; Thu, 21 Oct 2021 09:45:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DC2B860D42 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 328C26B0071; Thu, 21 Oct 2021 05:45:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D8556B0072; Thu, 21 Oct 2021 05:45:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C700900002; Thu, 21 Oct 2021 05:45:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 0AC1E6B0071 for ; Thu, 21 Oct 2021 05:45:47 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BF001182056C6 for ; Thu, 21 Oct 2021 09:45:46 +0000 (UTC) X-FDA: 78719962692.14.349FC88 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf26.hostedemail.com (Postfix) with ESMTP id 59AA220019C6 for ; Thu, 21 Oct 2021 09:45:47 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id E545560D42; Thu, 21 Oct 2021 09:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634809545; bh=NuZx+U/WxTn5Q2ibHJGCY7ADWDnU5+tPf1X/TctvQJU=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=q0wx56PS65O5Q9/2a6JpJWoLvO+J1VzrNqqfaIHulEaKiPZBLxJ0qJFoiyWIDfAmz wq+4baxbyTech5ooBruqWOdQ1GDKTLyEEXz3OG+u3j9pr89plD8b/CV/aAXWZv2djf 9iNofABqAqPTZobAOGtocqQGd95SY0BRkkHoE7gJ8hkqpaTzvSRn9yBL0mzico2XsY 6+yD4zWvRA8rcJDkA6GPJtwJ32A6OqbjBZD/dL/3iP68VtlhpHTApRXjSiNw/QssC8 FG9dDHFI/ZsYujdRVrKJGcfBfTdEKMdSXQKwz6siLKMUn5POODmiyJay6RQzC3SJi2 3WpRf9KYEyJug== From: SeongJae Park To: Xin Hao 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 Message-Id: <20211021094543.1846-1-sj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211021085611.81211-1-xhao@linux.alibaba.com> X-Stat-Signature: r7nuhpjxt77h8p83y4c563bcgpum6zka X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 59AA220019C6 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=q0wx56PS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sj@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sj@kernel.org X-HE-Tag: 1634809547-183044 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello Xin, On Thu, 21 Oct 2021 16:56:11 +0800 Xin Hao 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 > --- > 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