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 B19D0C3DA63 for ; Tue, 23 Jul 2024 12:15:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 299166B0088; Tue, 23 Jul 2024 08:15:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 247F76B008A; Tue, 23 Jul 2024 08:15:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10F646B0093; Tue, 23 Jul 2024 08:15:56 -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 E56DF6B0088 for ; Tue, 23 Jul 2024 08:15:55 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 089F5161E7C for ; Tue, 23 Jul 2024 12:15:53 +0000 (UTC) X-FDA: 82370913786.12.655B6FE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 1CC1C20033 for ; Tue, 23 Jul 2024 12:15:50 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=IKrK+C3y; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721736913; a=rsa-sha256; cv=none; b=2YSgSgrY4Osg+G+AmWtcOqaYfkdzqz1C8bC/LdoIZOgNl3wDsUCoX0nd1EGVtkplhGHfZZ mgnA+Plo8wUpva2awUV65S7uL2ee6urEleFpoTXiEr5UQytsITUlNHTpvSQA86glzIrWkN 0ed79Mhe8iHO6Y73ChTLJCJ5Ks78ajY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=IKrK+C3y; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721736913; 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=+/dURv2DVAeY7KMi+hZKqaGA2RunEvApL5fTz5Ixck4=; b=MURDSM7qO7nGsKj3jl2F9goOiuv+7PfYkSGnadEAqm2vbPYAMZWeIKbYb7Frwh/6BmMKD9 Wy1x2Yh3ATDal+ZnWs6B3JCpej3z98Wg9EmnCz3AmJb+LEc9g/5vojm5J3vUtmvx52+K1A 8S1Oxh4RxgBBrrUTThNBvcUDIjA8ZWE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1C1E36066C; Tue, 23 Jul 2024 12:15:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BB1AC4AF09; Tue, 23 Jul 2024 12:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721736949; bh=NaQ6QttPe2y7waCCFyD4qjBXn7dkyfpQfQBvyxyr8bo=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=IKrK+C3yrszfzgL8Jm6AZ3M1iRMlw3W5zDr/uzm4u5KQuf2B18YEoXtLBpKi0mfvG DAVJxyiQUlTtYJYtCxE5N6A5ytVDW5le9ESUwwhe4ygjRTgD5Wd5Gp8hasOVLMp8xq eCaFBixVIOFI92e8/3vMGDGgISyuscsEMm3cTmFs= Subject: Patch "mm/damon/core: merge regions aggressively when max_nr_regions is unmet" has been added to the 5.15-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:15:28 +0200 In-Reply-To: <20240716183333.138498-9-sj@kernel.org> Message-ID: <2024072328-luminance-disown-1c8c@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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1CC1C20033 X-Stat-Signature: ypt3co3iiwxmdeintzwy8q8ofj14rqma X-Rspam-User: X-HE-Tag: 1721736950-632091 X-HE-Meta: U2FsdGVkX19ovU6uaTkiW/MXLamMCMYZf8psRvwUKDuiQhKO0wwxkzTVvDMQ4wX4ThZJs335Jxl/jkEIuUcfTDFOta8S/dLRT7xYs3JuiUJgmcHCJZ3qViJw9Mu+at3bf/K1sLlhC+gQo8btAPYxLfmvQv5Aj3f0I1D0/TwFoNnC19LJX0atsHGWuhpbWwFZqDTHXP6wqZ7PadRy94MkpGqDgCllvPhKTvXMbbL9Ag7SAxsWT3qlU0ID4Ou9TRmPqzNxnJzjaBEmj7k/PFQKgOBqNxRvvf07X2fEsxSjdi0ekuSbItEgABQxWMtawh0/4bWkrH5s9pziCEWMqeaFDbS2Hg6plTQ1CJqc2kyN6U+PCaPxu0zPmI9vi4EccC+0rGpTQN/9cXOFhZF8B143YqxJrBuOjTlDKpRNE8Vn1xhehdMw/Vn9D1mubFGssGMj+oRK+D+4X+S0X4oBNyTx7oEZBTfWdSi4OySGGxf8qH0s6VsEt12SJ8itds2k6WbZUbWCooQ99KINwew6KMHv2XtCH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: owner-linux-mm@kvack.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 5.15-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-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From sj@kernel.org Tue Jul 16 20:33:48 2024 From: SeongJae Park Date: Tue, 16 Jul 2024 11:33:33 -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: <20240716183333.138498-9-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: SeongJae Park [Remove use of unexisting damon_ctx->attrs field] 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 @@ -507,14 +507,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->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); } /* Patches currently in stable-queue which might be from sj@kernel.org are queue-5.15/minmax-allow-min-max-clamp-if-the-arguments-have-the-same-signedness.patch queue-5.15/minmax-sanity-check-constant-bounds-when-clamping.patch queue-5.15/minmax-clamp-more-efficiently-by-avoiding-extra-comparison.patch queue-5.15/minmax-relax-check-to-allow-comparison-between-unsigned-arguments-and-signed-constants.patch queue-5.15/minmax-fix-header-inclusions.patch queue-5.15/mm-damon-core-merge-regions-aggressively-when-max_nr_regions-is-unmet.patch queue-5.15/tracing-define-the-is_signed_type-macro-once.patch queue-5.15/minmax-allow-comparisons-of-int-against-unsigned-char-short.patch