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 10D7BC433F5 for ; Thu, 21 Oct 2021 16:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4F0D613A6 for ; Thu, 21 Oct 2021 16:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231891AbhJUQqg (ORCPT ); Thu, 21 Oct 2021 12:46:36 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:38870 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbhJUQqf (ORCPT ); Thu, 21 Oct 2021 12:46:35 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UtAXCKO_1634834657; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UtAXCKO_1634834657) by smtp.aliyun-inc.com(127.0.0.1); Fri, 22 Oct 2021 00:44:17 +0800 From: Xin Hao To: sjpark@amazon.de Cc: xhao@linux.alibaba.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH V2] mm/damon/dbgfs: Optimize target_ids interface write operation Date: Fri, 22 Oct 2021 00:44:16 +0800 Message-Id: X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we want to clear 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 in 'dbgfs_target_ids_write', there is no need to execute other codes, except call 'damon_set_targets' to clear previously set target ids. So there adds the 'nr_targets' judgment, if the value is 0, just call 'damon_set_targets', and then return. Signed-off-by: Xin Hao --- mm/damon/dbgfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index a02cf6bee8e8..1d83f4138fad 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -362,6 +362,12 @@ static ssize_t dbgfs_target_ids_write(struct file *file, goto out; } + if (!nr_targets) { + /* remove targets with previously-set primitive */ + damon_set_targets(ctx, NULL, 0); + goto free_targets_out; + } + if (id_is_pid) { for (i = 0; i < nr_targets; i++) { targets[i] = (unsigned long)find_get_pid( -- 2.31.0