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 60D87C3DA49 for ; Tue, 23 Jul 2024 12:09:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8FE16B0083; Tue, 23 Jul 2024 08:09:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3F796B0088; Tue, 23 Jul 2024 08:09:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2E0F6B0089; Tue, 23 Jul 2024 08:09:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A63056B0083 for ; Tue, 23 Jul 2024 08:09:55 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5907A141E98 for ; Tue, 23 Jul 2024 12:09:55 +0000 (UTC) X-FDA: 82370898750.25.8E052FF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 4DC9EA002F for ; Tue, 23 Jul 2024 12:09:52 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=yf+Wo1Nb; spf=pass (imf15.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721736546; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:dkim-signature; bh=lZvW2FoVoIrfEBeNzIwhgtATOSHkcoizTSlMDpVyGVI=; b=U1jiBKx6ERoarJbCGeWnJPQS7tngqN+vQdodOW57Jc4KPy966v1/+h285Vun3gsaN0++gI PDHL3IubCf/NPvy6msmGVa7D1uQJZNnBAJnEfTcRXA1PORjEYFlWSovSiRaBtL8a5kRJtr Rb3cCRKgKqRQdEygZ8jhEN8i4hStyU8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721736546; a=rsa-sha256; cv=none; b=kD/bqk7cop0wvG1QS9wk5eTcNq1rtpenpOvCO87yZ07BUjXSVj9j4sgb0OEs76tbVtcSKG 7GumqT6ivCxTA3XPn3svPgpTxAwPyMTl20xDc4qvdZt+2Jiv1W9kNFnBnnMxgCIKNVZEbv NO5ZomQsPn1B0Iu35XaAalb3IPeF3JQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=yf+Wo1Nb; spf=pass (imf15.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 496DB6066C; Tue, 23 Jul 2024 12:09:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98916C4AF09; Tue, 23 Jul 2024 12:09:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721736591; bh=GzdI/su6Ucw1JuPfQUySJpX0Ti6NwAl2vI4cx3OUtIA=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=yf+Wo1Nbn5+5Kbqyim0HHHAdT3uV4wAu2gtYm1tbzChr56OvGnae1OAWnVYr/ZDtw 8XGduqLWo5X9DuFPrlWm5oT2ZV9iDMcgX3QvMeQ8V9PG1qVuys+RjC06KbqmubOqBn M2Tuw2K003IsR5sIEglCW7bd0y1PfWg3qwGLCUeI= Subject: Patch "mm/damon/core: merge regions aggressively when max_nr_regions is unmet" has been added to the 6.1-stable tree To: akpm@linux-foundation.org,damon@lists.linux.dev,gregkh@linuxfoundation.org,linux-mm@kvack.org,sj@kernel.org Cc: From: Date: Tue, 23 Jul 2024 14:09:26 +0200 In-Reply-To: <20240716175205.51280-8-sj@kernel.org> Message-ID: <2024072325-eggnog-profusely-f907@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit X-stable: commit X-Patchwork-Hint: ignore X-Stat-Signature: ay4rr9zjmetexewkftimfc3dfdz1ym4d X-Rspamd-Queue-Id: 4DC9EA002F X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721736592-222314 X-HE-Meta: U2FsdGVkX1/1N3xIkgd+0+m2j795+h1paR0ewuRBwQT00mqbTwxEY08Nb7aVRDX6/V3o01qeBvkXeJaprai/AiPuMLYxQjlxOzgWcYKngwEFFwi6I6sKHzt++M83atj3dDmcRPWz9YCB4s6Jm89AfQh2GFf9UDmzSJndGrOkliqYh9VwvaWK4xMz33MRJmjjg00FnujdTDPqqCURMKqndXrRfgLblR06G1IHCeCW7cpglgePXAKECSbeQ4Cl/lxvD1srLyMwUmKcszs+vp1pOSOeRRtqGPnEKgVreq1tjDNIgkIF++Lx0gV7oVO3ygCOm44n5D1rNWqpY/o919ZTCKbr3RZAUVF4GMfk7cSwoZGaY8TIusLFtKN4WfBwaLfAE5DeFtzt51BMkt+JytarzHNlW82DcgyqpzFJTwPnl24RfUIytnOZUjJoCXj/qxeD5GEat8MbbyGCuQoZSbhj2QBRErsusdRGPfPxpb2oaNmQlxsD3OeO9SFbzabon9oe4oLdPvzLswLpN4mBZ+hbVzBSgc2I1EIjguO72QkGqqDf70FscZS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org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This is a note to let you know that I've just added the patch titled mm/damon/core: merge regions aggressively when max_nr_regions is unmet to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mm-damon-core-merge-regions-aggressively-when-max_nr_regions-is-unmet.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From stable+bounces-60285-greg=kroah.com@vger.kernel.org Tue Jul 16 19:53:31 2024 From: SeongJae Park Date: Tue, 16 Jul 2024 10:52:05 -0700 Subject: mm/damon/core: merge regions aggressively when max_nr_regions is unmet 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 Message-ID: <20240716175205.51280-8-sj@kernel.org> From: SeongJae Park 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: Greg Kroah-Hartman --- mm/damon/core.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -921,14 +921,31 @@ static void damon_merge_regions_of(struc * 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); } /* Patches currently in stable-queue which might be from kroah.com@vger.kernel.org are queue-6.1/minmax-allow-min-max-clamp-if-the-arguments-have-the-same-signedness.patch queue-6.1/minmax-sanity-check-constant-bounds-when-clamping.patch queue-6.1/minmax-clamp-more-efficiently-by-avoiding-extra-comparison.patch queue-6.1/minmax-relax-check-to-allow-comparison-between-unsigned-arguments-and-signed-constants.patch queue-6.1/minmax-fix-header-inclusions.patch queue-6.1/mm-damon-core-merge-regions-aggressively-when-max_nr_regions-is-unmet.patch queue-6.1/minmax-allow-comparisons-of-int-against-unsigned-char-short.patch