From patchwork Wed Nov 24 14:52:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12637025 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 7208CC433F5 for ; Wed, 24 Nov 2021 14:52:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D61E56B007B; Wed, 24 Nov 2021 09:52:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D0F896B007D; Wed, 24 Nov 2021 09:52:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C25F86B007E; Wed, 24 Nov 2021 09:52:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id AF2EF6B007B for ; Wed, 24 Nov 2021 09:52:38 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6AC86181C9655 for ; Wed, 24 Nov 2021 14:52:28 +0000 (UTC) X-FDA: 78844114776.29.A9BA452 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP id 2B0E6900067A for ; Wed, 24 Nov 2021 14:52:25 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 6990D60524; Wed, 24 Nov 2021 14:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637765547; bh=5dhCOHOPDLaykpUjwDvndyMO8fDWAczCxAEVkK7Z7WM=; h=From:To:Cc:Subject:Date:From; b=pxZMCdE36FKsG3OKrHfqS8gJ/XQb+zDkgcjWs1LT1CwIW6boCLsAc62ocselrpKPc do1tVWsaG4Fm5fpODLW3v0sz1ovCTL9oSrw0M211Nd5u0FDuAFQ/EG6lu5/9bTKcLQ hcL5k+GW46zEtP7RRGxygNDt+KWrCqkcuW4y9GzagvtATa5m/TfiKuY1jL0tS9P0Lg xuCLDg6JqNaeLjtgx/nZ2sn8KZFLdcgN0vGmLa333f2d886diok6nCi9bfS7PabdnA LKdtZ6gTTkzXkJvIP8bTPeCwJlJW7ZSqg+4xyE9CDrFnIdHx+Eddut/ZnTqXQmz+B0 Qo3k1AQcPC+UQ== From: SeongJae Park To: akpm@linux-foundation.org Cc: shakeelb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park , stable@vger.kernel.org Subject: [PATCH] mm/damon/core: Avoid fake load reports due to uninterruptible sleeps Date: Wed, 24 Nov 2021 14:52:19 +0000 Message-Id: <20211124145219.32866-1-sj@kernel.org> X-Mailer: git-send-email 2.17.1 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2B0E6900067A X-Stat-Signature: iqa4wjbkobc17di4xk1bi75iuhuxrmdh Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pxZMCdE3; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1637765545-999626 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: Because DAMON sleeps in uninterruptible mode, /proc/loadavg reports fake load while DAMON is turned on, though it is doing nothing. This can confuse users[1]. To avoid the case, this commit makes DAMON sleeps in idle mode. [1] https://lore.kernel.org/all/11868371.O9o76ZdvQC@natalenko.name/ Fixes: 2224d8485492 ("mm: introduce Data Access MONitor (DAMON)") Reported-by: Oleksandr Natalenko Signed-off-by: SeongJae Park Cc: # 5.15.x --- I think this needs to be applied on v5.15.y, but this cannot cleanly applied there as is. I will back-port this on v5.15.y and post later once this is merged in the mainline. mm/damon/core.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index daacd9536c7c..7813f47aadc9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -976,12 +978,25 @@ static unsigned long damos_wmark_wait_us(struct damos *scheme) return 0; } +/* sleep for @usecs in idle mode */ +static void __sched damon_usleep_idle(unsigned long usecs) +{ + ktime_t exp = ktime_add_us(ktime_get(), usecs); + u64 delta = usecs * NSEC_PER_USEC / 100; /* allow 1% error */ + + for (;;) { + __set_current_state(TASK_IDLE); + if (!schedule_hrtimeout_range(&exp, delta, HRTIMER_MODE_ABS)) + break; + } +} + static void kdamond_usleep(unsigned long usecs) { if (usecs > 100 * 1000) - schedule_timeout_interruptible(usecs_to_jiffies(usecs)); + schedule_timeout_idle(usecs_to_jiffies(usecs)); else - usleep_range(usecs, usecs + 1); + damon_usleep_idle(usecs); } /* Returns negative error code if it's not activated but should return */ @@ -1036,7 +1051,7 @@ static int kdamond_fn(void *data) ctx->callback.after_sampling(ctx)) done = true; - usleep_range(ctx->sample_interval, ctx->sample_interval + 1); + kdamond_usleep(ctx->sample_interval); if (ctx->primitive.check_accesses) max_nr_accesses = ctx->primitive.check_accesses(ctx);