From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 941BA80027 for ; Mon, 23 Nov 2026 04:30:15 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AN4SwYm018243; Mon, 23 Nov 2026 07:28:59 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AN4SwYm018243 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="CPYrargp" Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AN4Spgt018202 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 23 Nov 2026 07:28:51 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AN4Spgt018202 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c50b170ec5aso224642766b.2 for ; Sun, 22 Nov 2026 20:28:51 -0800 (PST) X-Gm-Message-State: APuU4Z8WNmRGInPhZlukNGRUBaAqgkJWAJO50vYpaC4SzUFMarF5bMKH JaKaVyVzXmpMkeTYfufgi00AhU6FWPaZv4/Pmq5At7XUPtzby1087wxAJE4F4aRRnUwM/Xcfr/1 m4akudj8MaiBSBwMKr+AQN5PVQ7fXd0z5Cl+zDbEprpqhYOQJjxL/gg== X-Gm-Gg: AZFdTZdo4YOaC46yI1W2YC1+qK9GDoT4LOYR86ryO7MFh1T8qS8J9vWpK5nhv1w+FIE I8bmnCvtRQumxr+xNe2U7Otnmu6L18+E9/6ovxg+LHbepVS/tKrDtZ7/3lu/gSO4Tkltva4Un/x e5VuX3+l/CZGf4hZFjjvUOtCD7rw9KXOkhGp03wEKHSTyr0a/U70fXOL5uj/NOVdkomoqMCqOjl R7cHhoEBANvshbgSVG3ugdgJ+GNBAaYZPqgeZ18JGj85H4a88WhI7fGJNTwlLb6BndkiUdHAFg1 3bs7lpFTwQmhLQ3T3RhmvHK7s6Jd/7kgdKmmCH2gNlfkt1DW12NVmxxDJHdhmFnuLV4Ii72ZoAv YUEEMpVKbrRAvHl/mg/zDb8sFQA== X-Received: by 2002:a17:906:6690:b0:c4d:167d:dcee with SMTP id a640c23a62f3a-c513aabb216mr626513266b.40.1795408131289; Sun, 22 Nov 2026 20:28:51 -0800 (PST) X-Received: by 2002:a17:906:6690:b0:c4d:167d:dcee with SMTP id a640c23a62f3a-c513aabb216mr626511966b.40.1795408130733; Sun, 22 Nov 2026 20:28:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795408130; cv=none; d=google.com; s=arc-20260327; b=X5BsRPX1NymRyLStNQcRXf0/cb8WNzSthm//29/J6Z+m5+BlexUqqbi4lQMiZLBuvd 0a9TloGdyOhxvAm12c031mbrHtXolxqWWMSKuWnVD1S+yoegP/fQxuaV3YYskHe4lpR8 zfkOrdPfV1IW0uGhrWqVuRDFFLo+UIScvHvZcSuhPEObTMWXcRM15a0aUzoMpjy9HILJ M0vanxD4Jx/5XmzZ3kjlR8Q/hGZBzhyMSpOUiL4SraHUuczlh3AjnhdsL0b7HOKdTzn/ 3FZy4pahtu0flT9nth4p1W9xuIEgEUyaKc4B8vcjbChhh3+6BXNfCNooJNBPqlRX8pLo G0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=tOEgPRlekBkRYEi7RBTlcGsljw3xuqhbaKBXmJjHjoY=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=oZK82HeZ1ZktWh0YcIIG1sCSfjIUtVI3gWOu1bXNa3r7li5jq/fuCY4GYPNG8r2Z9W +j7zc1O2aOuThMVcB0PQsb1OPIKet1Yxe1AoxQzT7InP0zZr3jK6XA+5tiztaivtpXPi uojL6J5EnfJCGPAzYowrt4CoMBX2tpIYR2HpLcVv9lYrOJoSz6rwGguRnrHzOnt6OMj/ DK8XPphKfp0d5MnoxH6C7mlaCqbda4md6YgGWEamZgi9H7yPiYsKPMwXaudpWHKry9jS jRKa1gVqmKJq4C7UWCqKJm1xH1jwglCLqyN7c6/timHXvi3zkmGnSCgQcNPWUewp9EUr JSUA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=CPYrargp; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id a640c23a62f3a-c513b0da546si661598366b.355.2026.11.22.20.28.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2026 20:28:50 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=CPYrargp; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=tOEgPRlekBkRYEi7RBTlcGsljw3xuqhbaKBXmJjHjoY=; b=CPYrargpMvOU g2ozvqWRnolFgunab0yoevpfaRQPo5oP4jua6MauiMS433jsyjA5MzUbxRbCPanwB9K4Cew32pkAJ hRHR3sQrGCz73EZXJiugkowNGoYjrT4vwHl8kGhKX165nzhhhZOpqyoGvrJ4fgLc2opbdfaFvLvCs t5JxQuseGKUaxvi0L6C9JwNYixcLD3UoRP+gnSgzfsmyrjCBaHT7KS4y3ccbMatCpF8sHZDswmuPN Xk+WNWEaYelCAYKEHuepTHdGZ4KJnpj+Gf1R979LbSYaHt3PQUfDaFtu43Fy9Wuub+v4I2TNV7IEZ PdCSO9xC6BtP+uZP4C9Bmg==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xVLfW-008EcT-1s; Mon, 23 Nov 2026 05:28:42 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Mon, 23 Nov 2026 06:26:38 +0200 Message-ID: <20261123042846.1684796-2-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123042846.1684796-1-eva.kurchatova@virtuozzo.com> References: <20261123042846.1684796-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 1/3] ms/mm/damon/core: split regions for min_nr_regions X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: SeongJae Park Patch series "mm/damon: strictly respect min_nr_regions". DAMON core respects min_nr_regions only at merge operation. DAMON API callers are therefore responsible to respect or ignore that. Only vaddr ops is respecting that, but only for initial start time. DAMON sysfs interface allows users to setup the initial regions that DAMON core also respects. But, again, it works for only the initial time. Users setting the regions for min_nr_regions can be difficult and inefficient, when the min_nr_regions value is high. There was actually a report [1] from a user. The use case was page granular access monitoring with a large aggregation interval. Make the following three changes for resolving the issue. First (patch 1), make DAMON core split regions at the beginning and every aggregation interval, to respect the min_nr_regions. Second (patch 2), drop the vaddr's split operations and related code that are no more needed. Third (patch 3), add a kunit test for the newly introduced function. This patch (of 3): DAMON core layer respects the min_nr_regions parameter by setting the maximum size of each region as total monitoring region size divided by the parameter value. And the limit is applied by preventing merge of regions that result in a region larger than the maximum size. The limit is updated per ops update interval, because vaddr updates the monitoring regions on the ops update callback. It does nothing for the beginning state. That's because the users can set the initial monitoring regions as they want. That is, if the users really care about the min_nr_regions, they are supposed to set the initial monitoring regions to have more than min_nr_regions regions. The virtual address space operation set, vaddr, has an exceptional case. Users can ask the ops set to configure the initial regions on its own. For the case, vaddr sets up the initial regions to meet the min_nr_regions. So, vaddr has exceptional support, but basically users are required to set the regions on their own if they want min_nr_regions to be respected. When 'min_nr_regions' is high, such initial setup is difficult. If DAMON sysfs interface is used for that, the memory for saving the initial setup is also a waste. Even if the user forgives the setup, DAMON will eventually make more than min_nr_regions regions by splitting operations. But it will take time. If the aggregation interval is long, the delay could be problematic. There was actually a report [1] of the case. The reporter wanted to do page granular monitoring with a large aggregation interval. Also, DAMON is doing nothing for online changes on monitoring regions and min_nr_regions. For example, the user can remove a monitoring region or increase min_nr_regions while DAMON is running. Split regions larger than the size at the beginning of the kdamond main loop, to fix the initial setup issue. Also do the split every aggregation interval, for online changes. This means the behavior is slightly changed. It is difficult to imagine a use case that actually depends on the old behavior, though. So this change is arguably fine. Note that the size limit is aligned by damon_ctx->min_region_sz and cannot be zero. That is, if min_nr_region is larger than the total size of monitoring regions divided by ->min_region_sz, that cannot be respected. Link: https://lkml.kernel.org/r/20260228222831.7232-1-sj@kernel.org Link: https://lkml.kernel.org/r/20260228222831.7232-2-sj@kernel.org Link: https://lore.kernel.org/CAC5umyjmJE9SBqjbetZZecpY54bHpn2AvCGNv3aF6J=1cfoPXQ@mail.gmail.com [1] Signed-off-by: SeongJae Park Cc: Brendan Higgins Cc: David Gow Signed-off-by: Andrew Morton (cherry picked from commit b1029f29eb1d5fbf07fa8db9b5e7ab6d9813ad67) Rebase note: this tree has no per-context min_region_sz, so the size limit is aligned to DAMON_MIN_REGION. kdamond_fn() here still calls the after_aggregation callback after the merge, and the regions are split between the two, as mainline splits them before kdamond_call(). https://virtuozzo.atlassian.net/browse/VSTOR-156361 Feature: fix ms/mm Signed-off-by: Eva Kurchatova --- mm/damon/core.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 0776452a1abb..aa1aa45264a7 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1047,6 +1047,40 @@ static unsigned long damon_region_sz_limit(struct damon_ctx *ctx) return sz; } +static void damon_split_region_at(struct damon_target *t, + struct damon_region *r, unsigned long sz_r); + +/* + * damon_apply_min_nr_regions() - Make effect of min_nr_regions parameter. + * @ctx: monitoring context. + * + * This function implement min_nr_regions (minimum number of damon_region + * objects in the given monitoring context) behavior. It first calculates + * maximum size of each region for enforcing the min_nr_regions as total size + * of the regions divided by the min_nr_regions. After that, this function + * splits regions to ensure all regions are equal to or smaller than the size + * limit. Finally, this function returns the maximum size limit. + * + * Returns: maximum size of each region for convincing min_nr_regions. + */ +static unsigned long damon_apply_min_nr_regions(struct damon_ctx *ctx) +{ + unsigned long max_region_sz = damon_region_sz_limit(ctx); + struct damon_target *t; + struct damon_region *r, *next; + + max_region_sz = ALIGN(max_region_sz, DAMON_MIN_REGION); + damon_for_each_target(t, ctx) { + damon_for_each_region_safe(r, next, t) { + while (damon_sz_region(r) > max_region_sz) { + damon_split_region_at(t, r, max_region_sz); + r = damon_next_region(r); + } + } + } + return max_region_sz; +} + static int kdamond_fn(void *data); /* @@ -1182,9 +1216,6 @@ static void kdamond_reset_aggregated(struct damon_ctx *c) } } -static void damon_split_region_at(struct damon_target *t, - struct damon_region *r, unsigned long sz_r); - static bool __damos_valid_target(struct damon_region *r, struct damos *s) { unsigned long sz; @@ -1992,7 +2023,7 @@ static int kdamond_fn(void *data) if (!ctx->regions_score_histogram) goto done; - sz_limit = damon_region_sz_limit(ctx); + sz_limit = damon_apply_min_nr_regions(ctx); while (!kdamond_need_stop(ctx)) { /* @@ -2025,6 +2056,8 @@ static int kdamond_fn(void *data) kdamond_merge_regions(ctx, max_nr_accesses / 10, sz_limit); + /* online updates might be made */ + sz_limit = damon_apply_min_nr_regions(ctx); if (ctx->callback.after_aggregation && ctx->callback.after_aggregation(ctx)) break; @@ -2055,7 +2088,6 @@ static int kdamond_fn(void *data) sample_interval; if (ctx->ops.update) ctx->ops.update(ctx); - sz_limit = damon_region_sz_limit(ctx); } } done: -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel