From patchwork Wed Jun 26 16:47:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13713196 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 1F8D1C27C4F for ; Wed, 26 Jun 2024 16:48:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A327C6B009F; Wed, 26 Jun 2024 12:48:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E24C6B00A0; Wed, 26 Jun 2024 12:48:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A9946B00A1; Wed, 26 Jun 2024 12:48:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6C69B6B009F for ; Wed, 26 Jun 2024 12:48:05 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E8A48A4249 for ; Wed, 26 Jun 2024 16:48:04 +0000 (UTC) X-FDA: 82273622088.27.5ABDA20 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf09.hostedemail.com (Postfix) with ESMTP id B8541140013 for ; Wed, 26 Jun 2024 16:48:02 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=arIe2N48; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719420475; a=rsa-sha256; cv=none; b=PHaGgcuWo7lQees6StrjxerZEA0V/U8G5+kxngdzYfPeOUc5VuVD4BcM7J6LHtsmQT/see KgwsS/GbfbyVqZGG4nwVuN2B/xPylJrU8x5VthRqP+eJuq3yPiSFpykf9KY0mLWmLKpzWI /fsGfjdRgp9atbNu1a/updGC+yN4ZFM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=arIe2N48; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719420475; 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:references:dkim-signature; bh=/qd9rLwsU8InJKfz0hlhnLEOy95Eg1Yeba0y8rzPyes=; b=tfknT8toQt0t5NOmx1eHgOWHBvCk4+AXQI2kzoZqV3teuiBuIHYH4p7fywXI3To0IOiWHz awY0G9J2i09x3Oy2uCuqqoK+wBrzzKZk7FYpKJ7kUCiHVMq8Kd0VfHaaMlKXi1/HgfQ+Fc MUnUzKKX0XDIaCqSNswYNbjsJh3Csfk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2B7F5CE0A3C; Wed, 26 Jun 2024 16:47:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E96B7C116B1; Wed, 26 Jun 2024 16:47:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719420477; bh=1m0DSP9A63mwJJipOeM4FCyyG6b/spl9g6jnH4ftP0k=; h=From:To:Cc:Subject:Date:From; b=arIe2N48kXbz7Tbvv0ooQg9EVpboyfd0WQ2+7V8KzLvZnGmXDucAs1H7mNVVLnqb1 oDUqwj5AZvMqjMAb1rv0I66aOPMdvuZJElF9A6ex+mHWJbCkP+YzgEmPtoGxMW/q4J ZFS2yS/IzDp5svXCctNcMMop4vWfl33dywnvQVjVi9GwEk0ORDDeiZ0g3HkZvdnj1C 5r0FkSN/8D5CHjHBGYvBa+LrYU2XSKmxoy2CzA8rjbMTbL9d9yx9p3RCES3SpqRKGe kDkJn9q72YVhRJKevPYmCL8rfoQtuZ09w3VXWQXK/JCt8aqLvxewESB9QWS/CKkVZl YaXkmvNtIHseg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH mm-unstable] mm/damon/core: increase regions merge aggressiveness while respecting min_nr_regions Date: Wed, 26 Jun 2024 09:47:53 -0700 Message-Id: <20240626164753.46270-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Stat-Signature: i41hzha18ojiqcymays3g758q64dxn16 X-Rspamd-Queue-Id: B8541140013 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719420482-589660 X-HE-Meta: U2FsdGVkX1/0XBjfgrNsb5KDmj+N/VYyhVaj/IB3jBhMXHkbkQ/9L1JVyWTtJNJFoOUHHBT0U+g0rFZUwdgKP0G/u+ZFdCmsX3fZJqzpeJnLkC9ZnG3O3SKeeURjGlWRMP1FWYWSFW+ME6/Vb37g9W914NMpctKvcP6D1D/7D63XYioddsmUwtKFAV7fF4alMy92St+stdJczIiOuZT62loo9BlzhvhQD640O9S+f0JWyGQm5een1W21remMhhTy0Wq5E/XWaBCusVCwiPQzoBRaF3ts2M78Dfg3xVNKCqksWwOxivQstXxTOt8b8OE9YqxMSO4F7u739RIlGGkR0nuJGDoybNDftpiJE+5qTDSq8NwYAT3zFOGIblyeNZ8SkIdX3dFF9yUtlbnmJO6IEyKqRQUuxN2mG2OzqEGJBW8xXyPCfw/PVvsST9ZtxEnh4rop3awltHFH7r4UNIk1UJKEgaJ9NrCsvZ2X+PjH/7CvmfVLLEFmGgc4sOhnXWzY5Z30A6DekzbiEQ8nM3u1bE8iAsl0oZGoJPe4kuxyDIzpTznPwcwb43P0Sq14CSXzixdW2ClwoFB2hxwSuEGWNvesKGfse7tMS4cin9UeoZwfHPve+/XpP87gZsSUeiXN2tCYg1+YXpAs9i3crpV+Ej7KS9TqGJXNGgZsrI2+fLopSePQ+wcsiwEcJnAbvvrtRceLdhNUFBaE5KJVH4iYvoCOpaWJrojZIe3HeYN9Tonp31F4ZdKDw5clWEebz1jhvGIZbdj0Yqzpko5L8dBtW3Bf9gFv+Y3C2/BFdfAyqoxUdrzGlQN1dSxNKWNSe3MlMjPqS/XMpME0ww8bGeU5DjEr5eMQU0YhTt9gYtW/fkb9e6HQ8hClhTGteSKZbU3PiQPG3WQI9Xg8OZlXbZpxLaAigX/B4d/He6Ue9TU5C7dZirmoVT5e+Jjl/sZqbyrejwLqQfkdZMSoIBfmUp7 soSZrDXq m+3J2EB/YWvmsydBt6GB9keYe6v6ldfFIgfal6pG1abZ4h5+Pd1mCHuch93sOTKg0EVt7t1jLSUAH1amfJIpzqi3/dTdRUwHgoP52/FdjEe4E018DKI4h8pHE427LAigGG5NK6M0UHciY9ozfxdIMuIYNmzsk4KsUeafGcBW4HctVICaW2f8pKSib0LeWSWrSZDXW7gY4O8NzjpIMJr7LO9ECL3CVawGP8cdvaQ/ERsPpj+KQdbCVXNUq7ZH24XBNjnU8EKyWZncLsROE4EPFRRxSIA== 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: List-Subscribe: List-Unsubscribe: DAMON's merge mechanism has two thresholds, namely those for access frequency and size. The access frequency threshold avoids merging two adjacent regions that having pretty different access frequency. The size threshold is calculated as total size of regions divided by min_nr_regions. Merging operation skip merging two adjacent regions if the resulting region's size can be larger than the threshold. This is for meeting min_nr_regions. Commit 44fdaf596984 ("mm/damon/core: merge regions aggressively when max_nr_regions is unmet") of mm-unstable, however, ignores the min_nr_regions by increasing not only access frequency threshold but also the size threshold. The commit also has one more problem. User could set DAMON target regions with more than max_nr_regions discrete regions. Because DAMON cannot merge non-adjacent regions, the number of regions will never be lower than max_nr_regions regardless of the increased thresholds. As a result, the function can infinitely repeat the loop. Increase only access frequency threshold, up to only possible maximum value. Fixes: 44fdaf596984 ("mm/damon/core: merge regions aggressively when max_nr_regions is unmet") # mm-unstable Signed-off-by: SeongJae Park --- mm/damon/core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index e6598c44b53c..dac27b949403 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1695,20 +1695,21 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, * overhead under the dynamically changeable access pattern. If a merge was * unnecessarily made, later 'kdamond_split_regions()' will revert it. * - * The total number of regions could be temporarily higher than the - * user-defined limit, max_nr_regions for some cases. For an example, the user - * updates max_nr_regions to a number that lower than the current number of - * regions while DAMON is running. Depending on the access pattern, it could - * take indefinitve time to reduce the number below the limit. For such a - * case, repeat merging until the limit is met while increasing @threshold and - * @sz_limit. + * The total number of regions could be higher than the user-defined limit, + * max_nr_regions for some cases. For example, the user can update + * max_nr_regions to a number that lower than the current number of regions + * while DAMON is running. For such a case, repeat merging until the limit is + * met while increasing @threshold up to possible maximum level. */ static void kdamond_merge_regions(struct damon_ctx *c, unsigned int threshold, unsigned long sz_limit) { struct damon_target *t; unsigned int nr_regions; + unsigned int max_thres; + max_thres = c->attrs.aggr_interval / + (c->attrs.sample_interval ? c->attrs.sample_interval : 1); do { nr_regions = 0; damon_for_each_target(t, c) { @@ -1716,8 +1717,8 @@ static void kdamond_merge_regions(struct damon_ctx *c, unsigned int threshold, nr_regions += damon_nr_regions(t); } threshold = max(1, threshold * 2); - sz_limit = max(1, sz_limit * 2); - } while (nr_regions > c->attrs.max_nr_regions); + } while (nr_regions > c->attrs.max_nr_regions && + threshold <= max_thres); } /*