From patchwork Sat Oct 16 16:59:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12563733 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 456C7C433EF for ; Sat, 16 Oct 2021 16:59:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1AA761058 for ; Sat, 16 Oct 2021 16:59:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D1AA761058 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 788ED6B0072; Sat, 16 Oct 2021 12:59:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 711B86B0073; Sat, 16 Oct 2021 12:59:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DA19900002; Sat, 16 Oct 2021 12:59:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 4F0086B0072 for ; Sat, 16 Oct 2021 12:59:24 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0547A181AC544 for ; Sat, 16 Oct 2021 16:59:24 +0000 (UTC) X-FDA: 78702911448.07.7F0101A Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf07.hostedemail.com (Postfix) with ESMTP id 7DCF510000AB for ; Sat, 16 Oct 2021 16:59:24 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R831e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UsL28A6_1634403558; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UsL28A6_1634403558) by smtp.aliyun-inc.com(127.0.0.1); Sun, 17 Oct 2021 00:59:19 +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/core: Optimize kdamod.%d thread creation code Date: Sun, 17 Oct 2021 00:59:14 +0800 Message-Id: <20211016165914.96049-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: 7DCF510000AB X-Stat-Signature: nqexmmryappoqwrn959gmodookzdnu1b 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 115.124.30.130 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-HE-Tag: 1634403564-732106 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 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(-) -- 2.31.0 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);