From patchwork Wed Apr 20 18:00:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hailong Tu X-Patchwork-Id: 12820619 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA47AC433EF for ; Wed, 20 Apr 2022 18:01:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F35C6B0071; Wed, 20 Apr 2022 14:01:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37BB26B0073; Wed, 20 Apr 2022 14:01:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F51E6B0074; Wed, 20 Apr 2022 14:01:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 0B4CA6B0071 for ; Wed, 20 Apr 2022 14:01:04 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id D0F6E62ACC for ; Wed, 20 Apr 2022 18:01:03 +0000 (UTC) X-FDA: 79378023606.01.0638795 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf14.hostedemail.com (Postfix) with ESMTP id 851F7100025 for ; Wed, 20 Apr 2022 18:01:02 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id o5so2690565pjr.0 for ; Wed, 20 Apr 2022 11:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KY4R5w5+7zc+fZH1IdR0AGCbVYW+KVOSO3xBeZFrfJQ=; b=CVZAMDN7+9NUfqLRbn/uQRDUAWyggte9ufVr5LkFvWPJ3hUe0R3W8HTOCXnmCAWBy/ Re3XtpHKie0l6ibHKuVmpxJIv0vKpJ5hN+gJMMZjiDVjAiK1mQx+fYHzWv5zCEWNKt+b iNCJeQWJO6LrU+9xzlHrcVghWkb3iR0BvXQVR7bWJ2e/g1K9PB2oDi1efEbbt5UdQo0y ZmB5AB4lMh5KAYHV5yhBRzJfk+x6c2GuqO9YJ7u6sEzBMRxWMYwvB/BqwUagBp8k5eUd KVOzmGHQsRpWqv2PigzLtkUDnAhXk3TJ/s8r3Zzu57Q7TPIeg7QHJ0ek/druALLgRWa+ k4DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KY4R5w5+7zc+fZH1IdR0AGCbVYW+KVOSO3xBeZFrfJQ=; b=AeqItJEp6sa3fMnqkYKxbwOVsq7HS59xtqQge3dugfdxhTIlX05pJZm3iC/5wzYrey PGTI9KlPgXClgpnniHwIux2ZtUJoNHU0+gG70Qmy3RhA0v69PZYFBhNSChzANknHli45 MuKhLIXf3DzoCkX0temffOUyaeTStnuwAEfWh+VrT9odwzy2Yd48XMRNySWFmMy3QZdF Ny6iGmI0NgZrsVVE6j1tgfDn2qTDo4kSpX4nTXhlUogvHcNEpk0iAzqXbET4UtbCSSzm mjhXs/GuGj/Y925ROC5tjHYC3ZPHHxN5MBBxlAb3qLgyW+By5hfsTa2k242BqT8Z1pvp OAvg== X-Gm-Message-State: AOAM531pmF7MfzS78Tm3fa6WQb05RpLvcwyhX2N4UOA8nqea3GQ5tPc0 VtecC+AHXMNqbd8I+3a7Xg== X-Google-Smtp-Source: ABdhPJxVm+cvEA1xitS+n6RPKRU8Ee6aSPSioDmvgVT9ggv412kYOJLAdmQLS+Ufnjf4scMHpNqmHA== X-Received: by 2002:a17:902:6acc:b0:149:8f60:a526 with SMTP id i12-20020a1709026acc00b001498f60a526mr21950929plt.25.1650477661559; Wed, 20 Apr 2022 11:01:01 -0700 (PDT) Received: from ubuntu.lan (64.64.231.132.16clouds.com. [64.64.231.132]) by smtp.gmail.com with ESMTPSA id j16-20020a634a50000000b003a82190a495sm14077560pgl.62.2022.04.20.11.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 11:01:01 -0700 (PDT) From: Hailong Tu To: tuhailong@gmail.com, sj@kernel.org, torvalds@linux-foundation.org, gregkh@google.com, surenb@google.com, linux-mm@kvack.org Cc: tuhailong@oppo.com, lichunpeng@oppo.com Subject: [PATCH] mm/damon: Fix the timer always stays active Date: Thu, 21 Apr 2022 02:00:31 +0800 Message-Id: <20220420180031.36396-1-tuhailong@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=CVZAMDN7; spf=pass (imf14.hostedemail.com: domain of tuhailong@gmail.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=tuhailong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 5qdizriaq6y3k41gkzqizyfemub5gdk5 X-Rspamd-Queue-Id: 851F7100025 X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650477662-461584 X-Bogosity: Ham, tests=bogofilter, spamicity=0.005394, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The timer stays active even if the reclaim mechanism is never enabled, it is unnecessary overhead can be completely avoided by using module_param_call() for enabled flag. --- mm/damon/reclaim.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index e34c4d0c4d93..389c4be4f62b 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -28,7 +28,6 @@ * this. */ static bool enabled __read_mostly; -module_param(enabled, bool, 0600); /* * Time threshold for cold memory regions identification in microseconds. @@ -358,11 +357,32 @@ static void damon_reclaim_timer_fn(struct work_struct *work) enabled = last_enabled; } - schedule_delayed_work(&damon_reclaim_timer, + if (enabled) + schedule_delayed_work(&damon_reclaim_timer, msecs_to_jiffies(ENABLE_CHECK_INTERVAL_MS)); } static DECLARE_DELAYED_WORK(damon_reclaim_timer, damon_reclaim_timer_fn); +static int enabled_show(char *buffer, const struct kernel_param *kp) +{ + return sprintf(buffer, "%c\n", enabled ? 'Y' : 'N'); +} + +static int enabled_store(const char *val, + const struct kernel_param *kp) +{ + int rc = param_set_bool(val, kp); + + if (rc < 0) + return rc; + + if (enabled) + schedule_delayed_work(&damon_reclaim_timer, 0); + + return 0; +} +module_param_call(enabled, enabled_store, enabled_show, &enabled, 0600); + static int damon_reclaim_after_aggregation(struct damon_ctx *c) { struct damos *s;