From patchwork Sat Oct 16 16:56:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12563727 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 50B7CC433EF for ; Sat, 16 Oct 2021 16:56:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D68F560F36 for ; Sat, 16 Oct 2021 16:56:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D68F560F36 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 5426F6B0071; Sat, 16 Oct 2021 12:56:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F2B8900002; Sat, 16 Oct 2021 12:56:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 408BA6B0073; Sat, 16 Oct 2021 12:56:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 317E96B0071 for ; Sat, 16 Oct 2021 12:56:29 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D61A98249980 for ; Sat, 16 Oct 2021 16:56:28 +0000 (UTC) X-FDA: 78702904056.21.5E8E0E5 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by imf25.hostedemail.com (Postfix) with ESMTP id 7E31BB00008E for ; Sat, 16 Oct 2021 16:56:24 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UsLiVv4_1634403381; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UsLiVv4_1634403381) by smtp.aliyun-inc.com(127.0.0.1); Sun, 17 Oct 2021 00:56:22 +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] mm/damon/core: Optimize kdamod.%d thread creation code Date: Sun, 17 Oct 2021 00:56:16 +0800 Message-Id: <20211016165616.95849-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7E31BB00008E X-Stat-Signature: un4z1szhbdzbcsqdjuy7tnzi83ox3yjy Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf25.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.44 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-HE-Tag: 1634403384-378026 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 the ctx->adaptive_targets list is empty, i did some test on monitor_on interface like this. echo on > /sys/kernel/debug/damon/monitor_on [ 851.988307] damon: kdamond (5390) starts Though the ctx->adaptive_targets list is empty, but the kthread_run still be called, and the kdamond.x thread still be created, this is meaningless, so t So there adds a judgment. only if the ctx->adaptive_targets list is not empty, and ctx->kdamond pointer is NULL, then call the __damon_start function. Signed-off-by: Xin Hao --- mm/damon/core.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 30e9211f494a..998c707fdca2 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -107,6 +107,11 @@ void damon_add_target(struct damon_ctx *ctx, struct damon_target *t) list_add_tail(&t->list, &ctx->adaptive_targets); } +static int damon_target_empty(struct damon_ctx *ctx) +{ + return list_empty(&ctx->adaptive_targets); +} + static void damon_del_target(struct damon_target *t) { list_del(&t->list); @@ -307,15 +312,14 @@ static int __damon_start(struct damon_ctx *ctx) int err = -EBUSY; mutex_lock(&ctx->kdamond_lock); - if (!ctx->kdamond) { + ctx->kdamond_stop = false; + ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond.%d", + nr_running_ctxs); + if (IS_ERR(ctx->kdamond)) { + err = PTR_ERR(ctx->kdamond); + ctx->kdamond = 0; + } else { err = 0; - ctx->kdamond_stop = false; - ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond.%d", - nr_running_ctxs); - if (IS_ERR(ctx->kdamond)) { - err = PTR_ERR(ctx->kdamond); - ctx->kdamond = 0; - } } mutex_unlock(&ctx->kdamond_lock); @@ -347,10 +351,12 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs) } for (i = 0; i < nr_ctxs; i++) { - err = __damon_start(ctxs[i]); - if (err) - break; - nr_running_ctxs++; + if (!damon_target_empty(ctxs[i]) && !ctxs[i]->kdamond) { + err = __damon_start(ctxs[i]); + if (err) + break; + nr_running_ctxs++; + } } mutex_unlock(&damon_lock);