From patchwork Tue Jul 16 17:52:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13734725 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 F1185C3DA59 for ; Tue, 16 Jul 2024 17:52:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85BFD6B0093; Tue, 16 Jul 2024 13:52:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80DA36B0095; Tue, 16 Jul 2024 13:52:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FAAC6B0096; Tue, 16 Jul 2024 13:52:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 518AA6B0093 for ; Tue, 16 Jul 2024 13:52:28 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BCC29120654 for ; Tue, 16 Jul 2024 17:52:27 +0000 (UTC) X-FDA: 82346360334.27.982D210 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf13.hostedemail.com (Postfix) with ESMTP id 3E08B2000E for ; Tue, 16 Jul 2024 17:52:24 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QJ5HFnrA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.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=1721152314; a=rsa-sha256; cv=none; b=cLpbOVjfO9UBPfDndgNRNcEyTEVqDVdppzMFXoQLn6Uy7LAgvLULYiZWov8rEschBbDvwM w55SVRRHhJ5NdZVcOZ9Ywk7xQq2voPH/2ne1UipKM0Hjklh7OIl26EIOXtASBBmhYXm6pR s0CjOq1NmoxPlOGmrt4NifXLGVJ3KR4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QJ5HFnrA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.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=1721152314; 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=UTyYgMq5793WcumCd1s5zUCm18bJzo2EcSl3Rk5dagI=; b=kXsHW2257c//KsgLSsDPw0YW2Ee/SBdGO+S8bPWWuxSgQDl4VOgDBZKMcQ87Qe95GP1akN tzPA90YDLnoweBPIznfqZTTtGzp5aAgcmTz8DAe11vwQwBD+Om9/tCvF5nQ2dm3VUFpaVM WPRVXSwxvWAzscR4/Vwb2dBOqxiH6pM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6FFEDCE137E; Tue, 16 Jul 2024 17:52:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FFEAC4AF0D; Tue, 16 Jul 2024 17:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721152340; bh=T/pNo+yJuvE1fTBndW2I+PGWWQSfcSQHEgmL3hp/wPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QJ5HFnrA0gGqZLuEPeEMN1mg0jqaTM9UDLRevr0HupKNYdGfGxKDjFNarBVKFdQwQ e9gWRGiwBUzViaku+L9z1QoGNXBFu0xxwBvLWEqvxy659vuNIFJkesFvVhZb/gmDA1 DtVcN0V4mlwXWuTzJs9Ds0lpaSumxhEIZrL8TivBWgkzvrrZtRgGr60m/TEuROCmUj LCPNzOK+6pnJ/ORW6Z12e6u8Bjh6POkH4TYu1LwcWFdRlnMiOU+EJRWd+nz1qKKYJQ Sm/9+SnNFATTz0WNRcFk2GP6CUkYETY46eEDeijaaTAFXQztYjJvYpviBpFHBL/rwu jJxqBsRex9eHA== 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 6.1.y 7/7] mm/damon/core: merge regions aggressively when max_nr_regions is unmet Date: Tue, 16 Jul 2024 10:52:05 -0700 Message-Id: <20240716175205.51280-8-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716175205.51280-1-sj@kernel.org> References: <20240716175205.51280-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3E08B2000E X-Stat-Signature: 7caduberya6odizrcy9u6ux7u48ya6dc X-Rspam-User: X-HE-Tag: 1721152344-213375 X-HE-Meta: U2FsdGVkX1862ru98nLQFeUSaKQrcWgwoa2CWJQN5irhAV0WqYuk4CGVgaIMP+nWTinXarXWshCy/yT94IDNTgGeWJwmASCRYX7aH+O51YaUa8YMdfueS0daqeVsnY7XKLY1I1mn+rTsYgfuB6BR+owGILX9aWknArPtMNS4iz3+pz+IThERHb5qG6C0Ph7A2D8LlRL8CrB6h505nJD8WIOhp7Wst5giNebVHjEd+xmT7+Mc1HAz70sP3oyXRMIHzShflrF/t6w5SujIT0G5xVCSVLOUA9ULhEN6BnYR1QTSR8dnMpXAN1kXBzwsXiob4AOB/lD9DN1AStCfOhbCiDxMmf7FywJGyyIpDgKS6oGGLnEqTD4qQDSQDkvgyDepT9+ZgpOFlRIPGi4/Hn5rRhFPHO9YoUAdibYLGcn4lhuxawoba6vx6B4XEU/zkzpDOJXBt3Ow+slhH4D4YMUzdJ24WWVz9/fq4hqMDyAvB//QIQuRUKGkSpWTLXVKkdH9/DgzRmjEJLOQLuWAaKn+B+aQ4u69/icMgyHFcInbnPr4SW0ZMSb51Qb0cfZT/ReMN5EjXY+QP4toygfPYxLSpzESisJU9NSG4rtLDTBTtYeWgEBSgjOX1epsr7BiaRaYW1LNRi3dlSpf1oyRX/BefObpj3ghvX75DIsDwowIbXpwEc8G2vr6TLPBpURsXlWnfxFvK+bNiGJFTxa20QRkORQ9UmPGckQBCNSeQxi2eay988CdpbYgw0KgPWk+mL+6IbhQHqGTGacqRVwmWAyWbv2lY0omCVVVBQC/OQUZO6EbObywgoS3xCJfFqLDGbl0KUmjvKhQ2G0ng8Ed3FcK78Ka83oER5E/Z0wGjaBWSG+V5SCKCsSZYt5eb/HeEeD9AKiju8Yk4bhmdQD9f+Y6S/2GldjYRDjFIlGXt6OpSmKaOeyy93vRQjYenBDHTVWOF1mpdNVKk2l3QN6Zq1y NnFYmCI1 UskOVzEAErTFeyATvhPdgKFJFahecF3aWyEQlmxnKK8OhFRzSR3cCrri/Rgsolw6HTAzJmFWLTsj0eBN9Y1VtGH8pO2PuLMES/zdgIu0QAPVQD19neXkulf8SULe01z62KqiShRDDqKJu5kokRJOs4C87ZRHkh0xGw4fJbFuQyCwjIgImnDO3jPMa09c4ueIezpFBdmKvX0OKidqf4BwRwc4gh4OVf0U/CMfctLOdrGZEu99qDRPLJqGeyW2QYuOgFBu6hppZMNoymvxzrgjAg/NeoQdYj07a0hccLB9eujVHIB7+GMB1M4yg51tQKpk1wk4z9Ylkj00Rw1680flNReEu+Q== 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) --- mm/damon/core.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 5db9bec8ae67..ab5c351b276c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -921,14 +921,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; + unsigned int nr_regions; + unsigned int max_thres; - damon_for_each_target(t, c) - damon_merge_regions_of(t, threshold, sz_limit); + 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) { + damon_merge_regions_of(t, threshold, sz_limit); + nr_regions += damon_nr_regions(t); + } + threshold = max(1, threshold * 2); + } while (nr_regions > c->attrs.max_nr_regions && + threshold / 2 < max_thres); } /*