From mboxrd@z Thu Jan 1 00:00:00 1970 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 8DD35CA0FE9 for ; Tue, 5 Sep 2023 03:49:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1AAC8E001B; Mon, 4 Sep 2023 23:49:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACA8E8E001A; Mon, 4 Sep 2023 23:49:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B9338E001B; Mon, 4 Sep 2023 23:49:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8BF1B8E001A for ; Mon, 4 Sep 2023 23:49:05 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 48B9740948 for ; Tue, 5 Sep 2023 03:49:05 +0000 (UTC) X-FDA: 81201163050.03.FC0C943 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 8264E40012 for ; Tue, 5 Sep 2023 03:49:03 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="lr3y/LfQ"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693885743; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lCMnRjEw7Y11suNMgvqKP3w+mCZbE5N08smf/BRKoCk=; b=u9ydg1Q2/Li2d1NXdFVQMqnjihvl+tGUHQPG6DfCIM/rYCbPIrmOsXLt5dogcDVzf0w8zb 03zLMss0z2nFSsc3JkwWXT9HyQIIzPfI4yD8eIOB7SyrWnKDMf0dHgr3Su2JKDTrCc7j5S 3mM2KwFgaf5E30sUpeIXOmqseCGF9uw= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="lr3y/LfQ"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693885743; a=rsa-sha256; cv=none; b=rH+Lz5er/4DVIEMKEuoVVkkzCf8JVKo81QOyBu/qJx0TFxcgz5mvbEcXIEQ3JsrqFO5Y6N gf4Eo5NdWhdWAK1KNcB7IsGyREAeVxrUommt9kTb8Z0hXaJM7X7NBKUiGhxDSt1+AtW+O8 y3MZkIb+5NqItnRRgebgeMsbSQEba7Q= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7D38261323; Tue, 5 Sep 2023 03:49:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AD83C433C7; Tue, 5 Sep 2023 03:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693885741; bh=lr8JZFOrIMmBf3b1VvvA03Ns1Iavbh5ZrCVGwpM6Nik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lr3y/LfQjAjdQkg0Cyq3KvExgeue5Yw7O9pcscK462LKG4pds0vVH3HK5jEzulHxk V8tZPPHjhjDQtaEe9wdO/DkaoSy2zYyCUp+2husOnGCtg3q+7xbxW3ZICoXOw2BlEz c667MQA2GVGMubLjQcFDpOrCRA2bl0NQPd88lbfCImp2EuTELjar1Of7YHtgI7hcUI Yv0ERYj9STG6pMjYf1qiNvlbTV7aFVHf9CmkLypJIR+R385mEUKcKllLnFSPXnIS2b 2s3QCEnwFJEIbSMEXnE904NOhypIm+1blPhgo5stDL1HG4QOD+AxM3kj0/BWk6iWKq Xh8gntPwmoIGA== From: SeongJae Park To: SeongJae Park Cc: damon@lists.linux.dev, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] mm/damon/core: use number of passed access sampling as a timer Date: Tue, 5 Sep 2023 03:48:58 +0000 Message-Id: <20230905034858.127810-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230827003727.49369-1-sj@kernel.org> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: u4xgm4hfu81wyd154owfxrpr3b3m7rrn X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8264E40012 X-HE-Tag: 1693885743-705293 X-HE-Meta: U2FsdGVkX1+4Fk62RQGfKN9w90qocgWu/yELIOLSaw0lWcFI9q03LaLA84cBytLwpPzBcPESd1vloPt6NSzRG9jfZAX0FBq/6S9w2fXoUMgTSFXEijLee69d64dxNv12gt1sawQE2mi5mCoJGsSz2XmlvX0e+1k8OZngemG7MNpYGmFxMIScJr2vtNFUU2xjrpe1U2GcOLbNprO7y142i8wKX8MgPU+usqL160DCCFmaPO9XuOxt9pjGunpvwBEtxbRiH1EF9bqdrLKFEbphSQupJl37VmRezj/KyXezSUeJJbeb6kU76xjJfW+Q1CN120PjFf2FJ7qB6V/vXvXupqIsoiF6vUi1ZEkeyZTHES0p0BeS35J1ADAPqYH81aLUR+al31cyKCDaEwAEPlqY/jklrTRRTKAZ8YqxxsLG1t8emV4qzmi7Zip2u4or1sAkuuJmmAfTN9jBDfzeE/ifrYsHIz9it/uWA+ijM1oBgZxfnjw6le8aBZeJ20LE2n8jidfgTDsfqRaqwaBySzrAe2AB2gRFl9ETNePdhdsoFCO5LBbCHKvpAi+EGh1+nxwTN4IyNot+n6otYw4aox9KqdRiitKyCIKe35YINfqpnqScVgc2TFpPYbAUNmjyvT0dGQemo+UI50lW126JWKExYR5q47oQir3j13ZilPYwxOH2shJ6omn69Gryy6HaX3xvix3lYOj0bTmOP/+VsgC8+OUbHH7B+sdyQ87n+E0oPQcgmW5fm3WqaIrWhN0khWCUKZOBEYjUavH2YHu1Dyt2oguYuEK/0NKVhlsX8N0gpGKq3Gvr/GcGuyhwJRBhEVjkfomDk6k1eazug1vGhhveFLcNv2QtwhLGkyEnk2dOYcH/JX+oO43Ls8t8cu99wwwo5ekn04xqrgd6vYGUOZaZ//qwv660hm0X/2VyE/JYtP7yhEeACneOceA84Za45iuTTSorb1NCjvIRaVIG5Xu GSlem/2I GLtmq0ofROdr3cKPpdldtb8Ku60QX+Ay3ZtY1Q/Bvm3YdYm94I/vaT5ru+TSxHL11iRjEFww31C1fJGVQaLWbQIv2oX9hDleUr1ti0+YKatVLCqKzWNkBuQasux363RiMhpU17pUZFfx83XFAagcipgzLL7WaAnjLK1GT11xjZjVHcgTSbuNuRQU/Ups0IM7FWCwmrGfBXr3JqsqZgH+CssG0F1r3LPsKcHnBuUWPy0gZtet0AwJQr3V+GT00Y3PAlYgiHRyNKo1RaGKk9jLPza5Y4kybwi0Uvi20+NrFW63twI5qddu09bUfGZQ32GpW8viSvlmYhxayR5wF1GSwrN5gJA== 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: On Sun, 27 Aug 2023 00:37:27 +0000 SeongJae Park wrote: > DAMON sleeps for sampling interval after each sampling, and check if > it's time for further doing aggregation and ops updating using > ktime_get_coarse_ts64() and baseline timestamps for the two periodic > operations. That's for making the operations occur at deterministic > timing. However, it turned out it could still result in indeterministic > and even not-that-intuitive results. > > After all, timer functions, and especially sleep functions that DAMON > uses to wait for specific timing, could contain some errors. Those > errors are legal, so no problem. However, depending on such legal > timing errors, the nr_accesses can be larger than aggregation interval > divided by sampling interval. For example, with the default setting (5 > ms sampling interval and 100 ms aggregation interval) we frequently show > regions having nr_accesses larger than 20. Also, if the execution of a > DAMOS scheme takes a long time, next aggregation could happen before > enough number of samples are collected. > > Since access check sampling is the smallest unit work of DAMON, using > the number of passed sampling intervals as the DAMON-internal timer can > easily avoid these problems. That is, convert aggregation and ops > update intervals to numbers of sampling intervals that need to be passed > before those operations be executed, count the number of passed sampling > intervals, and invoke the operations as soon as the specific amount of > sampling intervals passed. Make the change. > > Signed-off-by: SeongJae Park > --- > include/linux/damon.h | 14 ++++++-- > mm/damon/core.c | 84 +++++++++++++++++++------------------------ > 2 files changed, 48 insertions(+), 50 deletions(-) > [...] > diff --git a/mm/damon/core.c b/mm/damon/core.c > index 988dc39e44b1..83af336bb0e6 100644 > --- a/mm/damon/core.c > +++ b/mm/damon/core.c [...] > @@ -577,6 +580,9 @@ static void damon_update_monitoring_results(struct damon_ctx *ctx, > */ > int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs) > { > + unsigned long sample_interval; > + unsigned long remaining_interval_us; > + > if (attrs->min_nr_regions < 3) > return -EINVAL; > if (attrs->min_nr_regions > attrs->max_nr_regions) > @@ -584,6 +590,20 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs) > if (attrs->sample_interval > attrs->aggr_interval) > return -EINVAL; > > + sample_interval = attrs->sample_interval ? attrs->sample_interval : 1; > + > + /* adjust next_aggregation_sis */ > + remaining_interval_us = ctx->attrs.sample_interval * > + (ctx->next_aggregation_sis - ctx->passed_sample_intervals); > + ctx->next_aggregation_sis = ctx->passed_sample_intervals + > + remaining_interval_us / sample_interval; > + > + /* adjust next_ops_update_sis */ > + remaining_interval_us = ctx->attrs.sample_interval * > + (ctx->next_ops_update_sis - ctx->passed_sample_intervals); > + ctx->next_ops_update_sis = ctx->passed_sample_intervals + > + remaining_interval_us / sample_interval; The above remaining interval based adjustments mean we will respect the old intervals for one more time. However, user wants to change it right now, so respecting it yet makes no sense. Also, since this function is to be called while no aggregation is ongoing, the remaining_interval_us for next_aggregation_sis will be always zero. So, simply ignoring past and resetting the timings as below may make better sense. ctx->next_aggregation_sis = ctx->passed_sample_intervals + attrs->aggr_interval / sample_interval; ctx->next_ops_update_sis = ctx->passed_sample_intervals + attrs->ops_update_interval / sample_interval; I will replace the adjustments as above. Thanks, SJ [...]