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 69B46C27C4F for ; Wed, 26 Jun 2024 21:50:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 967286B0083; Wed, 26 Jun 2024 17:50:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 917816B0085; Wed, 26 Jun 2024 17:50:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DF456B0088; Wed, 26 Jun 2024 17:50:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5E5E56B0083 for ; Wed, 26 Jun 2024 17:50:01 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EAE88C1717 for ; Wed, 26 Jun 2024 21:50:00 +0000 (UTC) X-FDA: 82274382960.22.EA3B7EE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 434BCC0015 for ; Wed, 26 Jun 2024 21:49:59 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=M51PKDuK; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 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=1719438583; 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=tkPenc50hk/E9Wy8dWvEVe1GarTwPYI4Ld8o47s3XiQ=; b=vXYE5oT1FsYRPigAIz/BwRTh5bK26FeGga4QVUdbeYISx6UVSTkrF6fT0vVuuv3agZ6G74 ufSERmc4GHaeaqmnoUKDQsBYr7/JfD51f3RMX754J9BOV+zsu2sCvK7mZ+W7qaMGEa/FLZ j8CPeHI22eeh+4ZyaCy3Kxa2ueDY9XE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719438583; a=rsa-sha256; cv=none; b=sFPu+keqvvt9GoZVSYXq1Wc0vJ/1RlR4lEMfKxxjGlbpYThMN/GfQOKkL4pNsiG+J6bbek 53uz5sZnSiPNq1Y7dAeZNvZHo2LU2F3LCo0Q7gyTZsehewaOVM0iWC5I2eJaZLUIrgC57O 66VcInqQI0jyT0qaptQ5GD/sQ6SJrws= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=M51PKDuK; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4DA9C61D06; Wed, 26 Jun 2024 21:49:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78D5FC116B1; Wed, 26 Jun 2024 21:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719438597; bh=vbEkrfUjgmgKqdl2dZG8HUfOBAyAIBXP7eZIOo4QAUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M51PKDuKttI5HYYW8JwcELqr83G0iDFtXFaA3vZk47MOIbPNwORjBid45M/+61AlT oUHLfS3wQVrxLLaPnoJwlHscJJXHQj32r6t+h2Boj6ZCbVl2vHDFJqjq1jKGvorXSf HmkNJanzFpzsuf3ucoCqcI0wdhMLlhuU3JI5wHMRq7kGtZH+X8TQwNrqgEfdjh84GO Ax5eH6vydpS9H5PM9o4MipJ84h+nPd2wuB64h3O5D6IjbPdLG2sX7ZgRmF3LpqEJx+ Me/9kB1kmpHYvoxYgk93LMLrnmFF1EvyzU/up5jZpaj90XOlPkw4QMio5hBpcLEC3I QKx/zcf/OiJ+g== From: SeongJae Park To: SeongJae Park Cc: Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH mm-unstable] mm/damon/core: increase regions merge aggressiveness while respecting min_nr_regions Date: Wed, 26 Jun 2024 14:49:54 -0700 Message-Id: <20240626214954.46143-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240626164753.46270-1-sj@kernel.org> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 434BCC0015 X-Stat-Signature: dsxcuedg98ujtysnrnt56zr5pbygzs5z X-HE-Tag: 1719438599-118732 X-HE-Meta: U2FsdGVkX1/ZhWQDI5LWylwK/pWXirJjtEf5m71xU4g7k6Cqt+82i14yOrQC3Rktyi6xcdBkyjo1dptsme8YlpaEiEUP/WeL2w2TsGLmHp6YOpbO1kX/vU8WZrbBGxP0fyMBx797fzT9hE+0E3I5S+v6B7lwsSJgn3K/ajCV2WkIM3uPVIaCCwVELNsCkIzFNo6Fp0L6KW7a5lDDvOTt2jRv55WDOyJjQ06ppy5pIFMPAGPwSOysiAuo2i5Bbg3waN2AdBzMYGI15Gik3tcXDm5AqKdB1YLbscDUSX7xe63wptE2JCUxt0bA0fmPGQFX2rWaDOtIF561exzNnvwHBSacMX7atWksaaHMvzgQfJ+oovvNgi9K2q2HvzNba+bRfjpD9Or0E3E+kw6bZHk6bd7KNKQIPjHyP2bT0U8MvUVu3uuHkfwWmlg5sp4fMku8Ihb+pSA0JBvXh6dEoELcHGr0kuePLnI6Nh0HAOJciqy0DpSS/mbnIrrRTHxldy1AmzfFKgXG4SN55sL5N7UmC3KKsTwZPYgWoa39KdkiMvV5Dm5+1xdxcBNsqolSTwXU43AT/WI2abCWDeDENHKStYanrJAF3uCM+rNMujRsq65VuYFSyVaZFhbVM/5uU83XYX9FWK9k63Kmv8dZLOXkRfIjO0U5QN28qHn99rOfuQOKcZO2qNWwFZcA2yBFhb1XDdPWdFJj6xa5l4LwshgQcedurYKp7elS85oLcs4+8UYTx29s2PTSmZsIvYsrFhlIOwZgd1P5yeZc4Jcd95oU+ChPF/C5sPGCnRkwf6u+wwa+T/52RuxarGE9SUp035F19B7DGOo/C15VXGXrEZa6t5iNsfH4laG9C3vrUDvwSJXYIWIoXr7X0S0cmOhi1mFjrG2i+/mVjz80tYNbFL7dju+wZpoHLU3UM5WI2yOXl3DpSoAuq+yml7eq5sRDfl513VIuskndA5rlTqaDQjE xl6F7Etj vMRhs9Eougy7NnY/et9Qd5tAWrQlzoBr9yqwL//elDYz62BDjB9FtjPeQQI0GJ1uCD+wf/WqIVRdFuT+iKyxUoWlM8DKtvjMLk0EkT/JBAilsS3ONGFPeJydoEKqL/BQd8TxNeSnjJfLovt5n3PN6g8jAjw/gCIp9G3Pz9u7O+o1gpG9NzYeqCtoUU2qn/deljgiuu0EL0T26yLpzSghtUUfro15R9PVVsPX/acnhqcoLpa6Mosuico3EXV79nrvHiR1wC2JGgtT5t3y1ou1RXBQb9M8tZrwU8Wkd 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: On Wed, 26 Jun 2024 09:47:53 -0700 SeongJae Park wrote: > 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 [...] > + 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); This code means that kdamond_merge_regions() stops this repeated merge attempt if the merge threshold that increased for next attempt is higher than the possible maximum threshold. And because the increase of the threshold is made by picking a maximum value between one and the last-used threshold multiplying two, the merge attempt with maximum threshold will not be made unless both the maximum threshold and the threshold to increase are powers of two. In maximum situation (e.g., region 1 has 100% access frequency, region 2 has 0% access frequency, so on), this means the max_nr_regions violation cannot be recovered by the attempts. This can be fixed by changing it to stop repeated attempt if the last-used threshold is same to or higher than the maximum possible threshold, like below. I'll send the fix of the fix as a formal patch soon. FYI, the original fix is definitely better to be merged in stable kernels, but not urgent in my opinion, since the problematic case is not common and the behavior was same since the beginning of DAMON. Andrew, if you feel the original fix is not stable yet, please feel free to delay moving it to hotfix-stable for one week or two. Thanks, SJ ================================= >8 ========================================== --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1773,7 +1773,7 @@ static void kdamond_merge_regions(struct damon_ctx *c, unsigned int threshold, } threshold = max(1, threshold * 2); } while (nr_regions > c->attrs.max_nr_regions && - threshold <= max_thres); + threshold / 2 < max_thres); } /*