From patchwork Thu Oct 21 16:44:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12575841 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 07BA1C433F5 for ; Thu, 21 Oct 2021 16:44:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 981E061881 for ; Thu, 21 Oct 2021 16:44:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 981E061881 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 31BD76B006C; Thu, 21 Oct 2021 12:44:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CBA56B0071; Thu, 21 Oct 2021 12:44:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E2EB900002; Thu, 21 Oct 2021 12:44:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id 0FC566B006C for ; Thu, 21 Oct 2021 12:44:33 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AACB018098526 for ; Thu, 21 Oct 2021 16:44:32 +0000 (UTC) X-FDA: 78721017984.02.2FAE4A6 Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com [47.88.44.36]) by imf07.hostedemail.com (Postfix) with ESMTP id 20C3810004C2 for ; Thu, 21 Oct 2021 16:44:35 +0000 (UTC) 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 X-Stat-Signature: x3rarmdb1sxp9wiuuh5mxonbqr6bjikg Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf07.hostedemail.com: domain of xhao@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 20C3810004C2 X-HE-Tag: 1634834675-536071 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: 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(+) -- 2.31.0 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(