From patchwork Tue Jul 16 18:33:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13734747 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 62B04C3DA49 for ; Tue, 16 Jul 2024 18:33:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB1886B009A; Tue, 16 Jul 2024 14:33:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D62176B009C; Tue, 16 Jul 2024 14:33:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C50D96B009D; Tue, 16 Jul 2024 14:33:52 -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 A778E6B009A for ; Tue, 16 Jul 2024 14:33:52 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5AB8AC0755 for ; Tue, 16 Jul 2024 18:33:52 +0000 (UTC) X-FDA: 82346464704.12.C358338 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf05.hostedemail.com (Postfix) with ESMTP id E727C10002E for ; Tue, 16 Jul 2024 18:33:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gjw3rELS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721154801; a=rsa-sha256; cv=none; b=iLfN0XbmBblxpnOCyf/EhNA/buYrJIaX0HIz+aLmlRH5NEwfc/E6rfTf3CXeeMiHGtcAZ1 gqWXLwzApSbYT0wNXTXE3kn3WPbj8NUXLOYCowoTj5eqQinRDujNpf7v5vuEzYQwnahOR6 LNJhx4xbGH2/g/CWDP1YNza6dSFopwk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gjw3rELS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 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=1721154801; 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=vYY0pA3j5CrHL2OSebzbAY3A4uj/dfY1mvcmsXLUqM0=; b=j+mswkIwdpA+mz3xJ4PO4U5IyTe19ngBbmQKfvwHLaKpmIBNQeLdMZvxtfWi4hYR8XEX/+ bTpNYMmpMOJX5FYpcUlOYbXNZek7hM4E/y0+aF6XDkXXWNatmXKYn5gCqWpKD+FDz1nmXe 4eXiVivsoRjx7wgb0q6zUbCpzdqG0xA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C3A1CCE13C0; Tue, 16 Jul 2024 18:33:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E32FFC4AF0F; Tue, 16 Jul 2024 18:33:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721154826; bh=B154PBKiYl5EWcFNNPsQO6OKsGY+pG6XCthbORAZL/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gjw3rELSz2/fCMGSuNWZ10azZwg3mYDgyAqtfvlP832tU+6N3FLJn+IuvProFtFYT IweLKEc4JMCkzpyvgFIM4lRGbSxCr/8M9xpnnTKG6bqihzxFrWThfu1sWZ8rA7RMie p+0bphGvjbJaKeKZ1K4C8H50AAmXXG1yhe6jn7E3M3HTbhvPJedzf+LUxDykAf+wB8 M6zJhR7S58Eu7CLgS3HlmcQXYRjw8FVOP5HttxscCQTAOfJiekydgXZlquULnWgylv 1hnSyuhuXjz1TKXE6gdW4tu/Jzm9mzWPmhYoTja8YCC0rXb+MZfOG8aLlr3av03LuF R5tdHbMUyfYvg== From: SeongJae Park To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5.15.y 8/8] mm/damon/core: merge regions aggressively when max_nr_regions is unmet Date: Tue, 16 Jul 2024 11:33:33 -0700 Message-Id: <20240716183333.138498-9-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716183333.138498-1-sj@kernel.org> References: <20240716183333.138498-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E727C10002E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: drhaw7nf59n7broqq73w5918oqqbr4jh X-HE-Tag: 1721154829-342036 X-HE-Meta: U2FsdGVkX18lJX1WheY2KM3iKJHDj+jsB53ba2KbFFFB5is8pbNPKOc9MtwagcUYaWMLRSAPuWOVQ88ow014qmcWEwB79nJIJoHder57PT3gaBaSYyWkHHexBiduzyxeCbXSwbUZzMOxHSaIsTFR0Ksh4VwQFbmcBxytBlV3vbkCuKLaYBNLJ6zkLJUPxiM5BIJ5VmzHHx+/xGM5mcj8o2dis6WfdjIrU3xJyTVl6OiKRTlpdh2001oiiFXjXzunPm3WlRc0RR+F0hjL7E0XPem1AmQi7LZtYrjw6QhHdBKe87LWpY8yy+awozojejIAgYzZpujg4Y+8Fhgoz+6eWUn7rGsRIAYMdEPJecA1i6AWxexNtQ3K9kKXdnrlTKI/wy4Mw++BkfGWjoC61G+jJAfRR88Akb72vHgo6rVp3qJ+qpBxpEp6vo3MArsaIAnfoG/zNqaHXvBmAPc0MXZBm8VtPnhWPIm2fCvNVP2ft1eCws771JR5pp45uUuWwGgneRomThdtKahQUWcs41uaXqDciXiV/w3oCLdUMMVFqYZ2Pw2S+h52H7dIzUqUIEapLhhjUl83TVt4t2Z1Zs5bs0VJxU8RXpbp8HkTVG+ftOCBdMim+4udbg6VUZmIYMh1nz2jaDnWFLEl5LwFZjuZMr9LmbWYdYf68djOhVWzC6zgUQkL0u/+LdjZSMOpu8WZzC2nzSpwkvz7BiHR2B4bfzzEhQ8WV09kbJRSJLqKJGl8zHYYs1pCEAbZCzGhJ4mzDnu3b8RIXB4PZM1LjMVD9a+DRn7kOE7ngsZq7O3ceh7XmBMOyOZaDO2WZhd4rm/f9ZTZXdD6W2Ij7H3jrFGDI7wUIZHo/TY5Fa+D8Roq+FsT3aaNUWhPkBoIEPk0jUIS1S7QNsDB/ZHRWPul33kJpd9xZdpcJuBLMjVezdaaK+3T5q8R5IR4h938U+6QnOX0nRJXGGrb6QonRllYWIv tqR0iilg nLl/njlnL8sKOWcEkQgwCy+FKg3GQsqJaBbZk9W3/HglWv6EL+dU3NsoGjS+VL2VsiGiGKKRkzgXA5avpHHzc3C3BNyoKPk9XDLm9/dMzKBt+871sc+s7bfr1XuklKNTXS471G3jQWQ+qU33bI2kRfFfml7ozhJ9o6FooZKinucnoMn+b8IJ3bSaRHMeHSgfEoHnhtF+FmNizseMOAiuebjfOmpPiZVmAg5z5LwOvlwyNeZ6I4IO9MjmyoCHMtyUg9z2UapQK/oa8/ZriIm3sLv6oO44shn+5sdLbf2i2E349iuxNcx7jR/cNizFBcZDbQKyea2C1Ov2ag/er9anm2yODQw== 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: commit 310d6c15e9104c99d5d9d0ff8e5383a79da7d5e6 upstream. DAMON keeps the number of regions under max_nr_regions by skipping regions split operations when doing so can make the number higher than the limit. It works well for preventing violation of the limit. But, if somehow the violation happens, it cannot recovery well depending on the situation. In detail, if the real number of regions having different access pattern is higher than the limit, the mechanism cannot reduce the number below the limit. In such a case, the system could suffer from high monitoring overhead of DAMON. The violation can actually happen. For an example, the user could reduce max_nr_regions while DAMON is running, to be lower than the current number of regions. Fix the problem by repeating the merge operations with increasing aggressiveness in kdamond_merge_regions() for the case, until the limit is met. [sj@kernel.org: increase regions merge aggressiveness while respecting min_nr_regions] Link: https://lkml.kernel.org/r/20240626164753.46270-1-sj@kernel.org [sj@kernel.org: ensure max threshold attempt for max_nr_regions violation] Link: https://lkml.kernel.org/r/20240627163153.75969-1-sj@kernel.org Link: https://lkml.kernel.org/r/20240624175814.89611-1-sj@kernel.org Fixes: b9a6ac4e4ede ("mm/damon: adaptively adjust regions") Signed-off-by: SeongJae Park Cc: [5.15+] Signed-off-by: Andrew Morton (cherry picked from commit 310d6c15e9104c99d5d9d0ff8e5383a79da7d5e6) Signed-off-by: SeongJae Park [Remove use of unexisting damon_ctx->attrs field] --- mm/damon/core.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 7a4912d6e65f..4f031412f65c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -507,14 +507,31 @@ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, * access frequencies are similar. This is for minimizing the monitoring * 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 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; - - damon_for_each_target(t, c) - damon_merge_regions_of(t, threshold, sz_limit); + unsigned int nr_regions; + unsigned int max_thres; + + max_thres = c->aggr_interval / + (c->sample_interval ? c->sample_interval : 1); + do { + nr_regions = 0; + damon_for_each_target(t, c) { + damon_merge_regions_of(t, threshold, sz_limit); + nr_regions += damon_nr_regions(t); + } + threshold = max(1, threshold * 2); + } while (nr_regions > c->max_nr_regions && + threshold / 2 < max_thres); } /*