From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 461C4145B3F; Wed, 9 Jul 2025 01:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022821; cv=none; b=SxrE8lqfsGQUupR8BQnlvsJXxf/UKp68A+UbsOxT1vdu2jj+uQVTP7TKqXpAjlBndouU2sBgyKH1S+BK2166Q/qzxCj5hnzSppxQxLIokiH5lqPXxrr4s8AbXl735qtjCiY84uOVUzmxqFyHRk/u11I9gHkIj82681iSFyReh4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022821; c=relaxed/simple; bh=EcpgCEiHcibyxaOwHRX8bt5yDryjoNGcO1lh9/3JWjo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ar0RP+LNg4JLYZOdaOrw8QZNGl/sAXmIJhol/BrUbJytH9vAHMFme8id8FEu+TXeRDfkaP45nui5NsZRDrLOaUTuWZD92EhEUc4flvkXG1CCN+j3i8mdWXuVjvdNBekpJc+lmv8JKexrv6yN84BZScScjENBhACcs+bajucBHeo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gW+P4cVh; arc=none smtp.client-ip=209.85.219.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gW+P4cVh" Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-e740a09eae0so5039953276.1; Tue, 08 Jul 2025 18:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022818; x=1752627618; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+S+EPhy8VyFlv7h36Y9eh7ovmZghlSmk5oVJFc5gzbo=; b=gW+P4cVhuQcP/H0l47VDjek3OPNTCeErLQAdhWfSw7OVir8jWKQ4JiK00sDACWr0bA vqBVWL6YRyWQhgL8Wl0PAE7qbh18ykIDoh07pI1OvbdJZ5sv/UAXF4t6DjHpHURgE6Q8 SVEOqawf1aIBguOT2MG3QoT+OixHU38mgGjnJy03MedT0fxpgO4XEChrHifr1KNsJFCE 5/zs+MOi/Rx6ZKmw7o/4B/UbsJzXKbz9tHzbnYwLVnA4ox+z3L8it0CBVf6AnRF/0//+ YqsR+wrLOsLmSBVDoNNUK9iMA3seHd5UL1YUMnRYx0Re3WlSyCH0iNFVMVE5SomozoiN pMbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022818; x=1752627618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+S+EPhy8VyFlv7h36Y9eh7ovmZghlSmk5oVJFc5gzbo=; b=j1SoHq/CcjUX8fEsOdGk315pIBG/rp7a7tjRgtZVM88PaKPlKjd9IyF7vQcZN2f5WD dxT4wzHnqJenw92aRnLUY60NE/eU4Fsr3sHBy4huNfivjnX1TAOhO53R3ibAhU9ivB/i DZEQqcebmLvb+jtXW3Vu6J18/WJPUCy102aY28xNMCAZxytJXzPbB4QzxHbCq+z2elaO op80PXJUY0nuwpPOg+4M25boyjozePOvyczonrMy1X5Pcu0oCnNKaA75jg3jFZKWw17v nwbuPCbzcQ5KRZxZ9px+xcb1hcXM1XWLL9gZxqsxSb37rbySN5nm1PiC+JrPk/M4tLLf Y3Uw== X-Forwarded-Encrypted: i=1; AJvYcCVxQNOfheT/Wd67A/DVt8UoMk5FIJslGf60oBJnn/D2xklPKCZGk8cuQu280qbfDYS/OUDrgl8qMo8=@vger.kernel.org, AJvYcCWPqZew6OS9m4IHhyHFjj8JAqh5ChToeyFnc370JHKjvU1ltho2j/btU0orF7SHnT75FVtBN23VIjP06iws@vger.kernel.org X-Gm-Message-State: AOJu0Yy65snHg9sY/xy3g2a49I1vqIXdFNd9xQwAyKot0wNB3T370z/Z PfgX8mvCZFuLbQJCit3tlmdajkuljF9/ZPj2Vx73k3Badiqy7g8WTdMW X-Gm-Gg: ASbGncv+XJdZrie/nRDFd8RGpCgZ+GMgujJRXVmLMBepdTcFqIK7BR/c+6lDR7k5bRY kXuLBvqquaisd1U1z3pQ7wYkEhebJAteIlHme5GhpcZkMc5cUdDXHu0Bgtfvqny3hAkiuOs5MjT 0M4XWcjzAf+uhbzQ5jk46a7e0ay7zQdyyRQoQb5cDIx7ofCcc9prdQrF8G19d1YrZ0zz53EZfAi vZhjcUpGMLnhi25sohpq1YplBan3gr3pbEQ+Ha21ycBg4rS9prn3MNJYovtny5rWbNfQiscyFTK ULUiO7NlASiAR3xIW+GQKymIV7TMmorIjPprXLIHz7PNFY2dexo5iKq9yXnGbb+6Lf71tnR8cIA VnuzHePQ= X-Google-Smtp-Source: AGHT+IHgAhVoBn0DlM8BUKh4bCqB1qI3HV71RTmOzTs/ExvjbhBZ4AjtFQcsZLzN7auWvUgFy8e37Q== X-Received: by 2002:a05:6902:18d4:b0:e81:7f36:5a37 with SMTP id 3f1490d57ef6-e8b6e0bc5cbmr1044311276.8.1752022818118; Tue, 08 Jul 2025 18:00:18 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:17 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com Subject: [PATCH v4 01/13] mm/damon: add struct damos_migrate_dests Date: Tue, 8 Jul 2025 19:59:31 -0500 Message-ID: <20250709005952.17776-2-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: SeongJae Park Introduce a new struct, namely damos_migrate_dests, for specifying multiple DAMOS' migration destination nodes and their weights. Signed-off-by: SeongJae Park Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- include/linux/damon.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index e1fea3119538..07cee590ff09 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -447,6 +447,22 @@ struct damos_access_pattern { unsigned int max_age_region; }; =20 +/** + * struct damos_migrate_dests - Migration destination nodes and their weig= hts. + * @node_id_arr: Array of migration destination node ids. + * @weight_arr: Array of migration weights for @node_id_arr. + * @nr_dests: Length of the @node_id_arr and @weight_arr arrays. + * + * @node_id_arr is an array of the ids of migration destination nodes. + * @weight_arr is an array of the weights for those. The weights in + * @weight_arr are for nodes in @node_id_arr of same array index. + */ +struct damos_migrate_dests { + unsigned int *node_id_arr; + unsigned int *weight_arr; + size_t nr_dests; +}; + /** * struct damos - Represents a Data Access Monitoring-based Operation Sche= me. * @pattern: Access pattern of target regions. --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 991CE137932; Wed, 9 Jul 2025 01:00:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022826; cv=none; b=rctf6ApeZlP3RQIonlohCdScvV6kvWfnjvLHezzlz5Tzr9vj+6nS/A+Bme3P329Z5hRodLv0fibtFlS+aLPldRNWSuRzlN0PTakCT8aTEBPnyLgsdLhC6f7Yd5VGUZblyzi29Jp2GdimxbrzHDmpZsFvgtN2z7VLbTsK0WWNbto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022826; c=relaxed/simple; bh=TF36DmJ4gRDLXGKB0dablkBerf4+G3+9gH3N4qFv2Eo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QVBHvIRIVpOWyM4xuI50JQdHKAwtTv0Wg1h9B4WC4YsMlvVA9qQqtPxZS6/VxAnOzPYW52Cfl6tbt5C1fgEjU/a48dZ/NufcJJJKdAV69XEPGDyREpUI+ekAdqO4LGz8bjZ0QYCWzNeZ2JvEyjNxPET69QUN7OcvywDXrDVidb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fgwSz9uf; arc=none smtp.client-ip=209.85.219.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fgwSz9uf" Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e85e06a7f63so4528334276.1; Tue, 08 Jul 2025 18:00:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022823; x=1752627623; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+TgSHi8o+LhWVBXZHtMiPoCLNZyL4Zo3x7ltlQyypVA=; b=fgwSz9ufaJo0s9rJbsYR9KA+7qJ4e5sOc5OjAcU9xyRmAoC4cV/g3v+yArNfW4+yws pWlNEOLzkA1VksTR3qac3UHP0Qqv4JRC6IqXe+k3uY7VrBrWBEG7JzQsDfIT+MOBj1lM 1Mq/Q0u9hJIEBmpGHU65vbhbnJMClv3oh8yVhldAvbgucO7gsU1m6whYamajebUVsaAq 4THfnCQNVMdcKCQI4ogwI6ZSDbHPaHahNnZaRfkfkkzznYoH6Rtw8c3ThFXEMHOnpBuE XGqxlGclgOPuuIaCwEdEVz+OZ3YtwoZc4vwRv+LGZtLHk812G4LhBONyy0eh7dSpB2iZ bgoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022823; x=1752627623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+TgSHi8o+LhWVBXZHtMiPoCLNZyL4Zo3x7ltlQyypVA=; b=ohvl6ZumDABVRj83loQ2BwckqzVyIbRXd8UBEg2nDN2tcGPMzauHUTTlQDWDJR2TY9 lvWkBIrqUQbE3RR5heavhOYAncg1gQlhKnCvEx8TLDGvgYchiKjUHwJQZm5X/5Rg975I QNu8xVO2yG1wk2vVFozRyOez7x43ZL335QcwzqWEgu7+MNfCFuJmjSw04j2BWQt4wWLC JG2oDXkMCLflucNMlJrPi+3UG+f801f7recYtweH8OB+shWAd6soqIiSPZy0eQvHXkxK O9o96LGNgqFjMbOPebYbHaCcDm+dhwbbDl9hU3b7ZFFuJ7PL1VyRzzZOBtPIV3kWqhSF 8hAQ== X-Forwarded-Encrypted: i=1; AJvYcCW+mkZpk28m3Y75Acr4ogBqqSrAL43ekv3unzZdNZQWjgTYTcqAKT4pAXL8w8LMphEGAf7lb7H3TLs=@vger.kernel.org, AJvYcCXK1vmm3eaGyd0g+TdzAsKMk7dw0tqcZJU1RD0LGtZPWcZzjtamLXRYgr8jWbdecGFA/BxOtcbUR/pMi5bg@vger.kernel.org X-Gm-Message-State: AOJu0Yz5Ilk1bAAh6gK1rgtVunwnbhcBkDyyk/EiVOwAY8K9RIqf6s+f OeJLVK1B13VJrrmE5qp+cx9n1AZTSzrD4LSutD6FHM4yTErWoQr5kv5Q X-Gm-Gg: ASbGncuejYqHvUGllnzdFQC6f3Uk64RbrXGI76jnxI52JQ7Ao5PdovBV+qKv4bC9VKp PSBj+FVrJKtUknmCEi9p3RqZMN+1s2mZ84UV+F7Msep0Zl4YcTdTyqpE/xZCaMopzeFbtBvmacJ uJP4pmOWxlB5zobhUEatUrtCztPwYInLUdibuwN7I28Q5yfN3RZS4KcUtbB6mYA13lYB3kvrINc tYVmajY+qXJeDMnGTMIW49MqP3ek8YUPscSOV7oi5gycvJgWPFM/SLcjYjX2p6Td4iBKRKGQyOR tEK0+07TRth3aVXAMg1kPT5tET7ztLYipGGmajuSWSW3tN200Rl0uebf3VlZiLCd0wVAu1PJK8A +odvrflg= X-Google-Smtp-Source: AGHT+IHKEK977MUyeP+iX8FWA6em280Bb2xxq8On52e+HzVmSP39OMEedbCQWl+WgqWCiO+aaXyLvQ== X-Received: by 2002:a05:6902:18d1:b0:e89:97db:e13a with SMTP id 3f1490d57ef6-e8b6e0bb33emr1141015276.2.1752022823136; Tue, 08 Jul 2025 18:00:23 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:22 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com Subject: [PATCH v4 02/13] mm/damon/core: add damos->migrate_dests field Date: Tue, 8 Jul 2025 19:59:32 -0500 Message-ID: <20250709005952.17776-3-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: SeongJae Park Add a new field to 'struct damos', namely migrate_dests, to allow DAMON API callers specify multiple migration destination nodes and their weights. Also update 'struct damos' creation and destruction functions accordingly to initialize the new field and free up the API caller-allocated buffers on those, respectively. Signed-off-by: SeongJae Park Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- include/linux/damon.h | 13 ++++++++++--- mm/damon/core.c | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 07cee590ff09..1f425d830bb9 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -470,6 +470,7 @@ struct damos_migrate_dests { * @apply_interval_us: The time between applying the @action. * @quota: Control the aggressiveness of this scheme. * @wmarks: Watermarks for automated (in)activation of this scheme. + * @migrate_dests: Destination nodes if @action is "migrate_{hot,cold}". * @target_nid: Destination node if @action is "migrate_{hot,cold}". * @filters: Additional set of &struct damos_filter for &action. * @ops_filters: ops layer handling &struct damos_filter objects list. @@ -488,9 +489,12 @@ struct damos_migrate_dests { * monitoring context are inactive, DAMON stops monitoring either, and just * repeatedly checks the watermarks. * + * @migrate_dests specifies multiple migration target nodes with different + * weights for migrate_hot or migrate_cold actions. @target_nid is ignore= d if + * this is set. + * * @target_nid is used to set the migration target node for migrate_hot or - * migrate_cold actions, which means it's only meaningful when @action is = either - * "migrate_hot" or "migrate_cold". + * migrate_cold actions, and @migrate_dests is unset. * * Before applying the &action to a memory region, &struct damon_operations * implementation could check pages of the region and skip &action to resp= ect @@ -533,7 +537,10 @@ struct damos { struct damos_quota quota; struct damos_watermarks wmarks; union { - int target_nid; + struct { + int target_nid; + struct damos_migrate_dests migrate_dests; + }; }; struct list_head filters; struct list_head ops_filters; diff --git a/mm/damon/core.c b/mm/damon/core.c index ab28ab5d08f6..62acfd5cf4ea 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -407,6 +407,7 @@ struct damos *damon_new_scheme(struct damos_access_patt= ern *pattern, scheme->wmarks =3D *wmarks; scheme->wmarks.activated =3D true; =20 + scheme->migrate_dests =3D (struct damos_migrate_dests){}; scheme->target_nid =3D target_nid; =20 return scheme; @@ -449,6 +450,9 @@ void damon_destroy_scheme(struct damos *s) =20 damos_for_each_filter_safe(f, next, s) damos_destroy_filter(f); + + kfree(s->migrate_dests.node_id_arr); + kfree(s->migrate_dests.weight_arr); damon_del_scheme(s); damon_free_scheme(s); } --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D64F2AD2F; Wed, 9 Jul 2025 01:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022830; cv=none; b=hjoMeA7llB7rRPqHYm7k1rgF7Psdb4TYsYU7Pf0zEH47UYeyxVZbbck+TwTZ+vb7yh/gMq0p9VW4bWJx0FLfFKhoJMWnsz6BZ6uaN1I3gsnLpU8xhXcavhedtQppUOBW23G7htZV7mdbJPIbzul+YKDE4qpkorPKDPquIs9U8DU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022830; c=relaxed/simple; bh=eF/H/z2pYqktDTEJ23uY4F7DAK6ZaD5jret1tgIuUMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RFTwuo1iXB/nN/oIVjtMlNoro7Kic5gY0pAqXuKJU8YRe5E562XcQqgyjeTeFPbCYVvGXJgeukIxmmWNz9uvWJwCwftwAL3il4gB4+znyXnTchKk5yaThwZss92+SDi4AFsWDDyQ06lP8aJvyLn4RKxGz353Zdbv1r0LAZDqKLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FavCzOJn; arc=none smtp.client-ip=209.85.219.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FavCzOJn" Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-e812fc35985so4280703276.0; Tue, 08 Jul 2025 18:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022827; x=1752627627; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fwKG6sHtooB+0pjFJ6ZV0sLHha49Q9YzgcCRLM4NWHU=; b=FavCzOJn++Ipld2br1shZz79Y+Oip6VIjYNHZjTEpAI+PQvukZ/GdHsG5gA7VDjnjV B2NpPKuZVVkhrTOsrkgWO9UL2IfKk15EF18ZBeGOD7DyJoGzq6r8+u+UTPZstrJ7kPsp I3+qlESRDHeQiUo3G50eUO7MZZDQrwNKCZRgTqxZQcZ3J/IKpO0CuMx1R2DvO0kRKMzF /5BlT5UdMlqvDzJxXtxRsbcriCqqMvJCaj3loYSvbOdSW1U/Tly3A6eE/5fvvzR+TSyz /DXU52cTzP1LtOWNZY+IgOfSIyp2LO18u4p9zfV9yUw2633lIfwuMRBFdZi2RamvpnBm Onkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022827; x=1752627627; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fwKG6sHtooB+0pjFJ6ZV0sLHha49Q9YzgcCRLM4NWHU=; b=bEqkxk2C9YoDPlJqq2lgac/LSI9NEpFFDUNVZnRDiExIwkM+BvzPi4xMCJQ6GS4CJd M/CcvA+aZBs4LVHNju1vP5iWWu2GQAiGhXkIJbbVTbSU8LCZ0uoKYUvwRUKI65UegEuy qsVNfh2K3eplpOJWMn9IXs6olusouije45kbWLNxwMMmR2nXTgSXMBc1iuqoR2xPcrQJ JPt1GDrBYt2+WRzEKa7vsyRlJfsCGuRGBO7eCcANS5i+GkB68GUi53CnqRJVlen3O+yw ZMnjuU3iL5CyIIzIWzSe/Cnb217IE6BEl7qOWQEEeee4/brW4VR1cvxOXyZS+9fl2yyY dAuQ== X-Forwarded-Encrypted: i=1; AJvYcCVLTq5JckBC2TNFpSxbWJZQMguCR1C9Zxv1jZWuzNS74K9jcA5HQwaM1qv2Leajeowb+sZcMgWHc6E=@vger.kernel.org, AJvYcCWFhW1SnBluhqe/IU5vSzrL7wsPA3XAELG1bxOVk21Yj46POCeGhMAVfQlMHkYq62UJwtnIEV4MWdF51AwD@vger.kernel.org X-Gm-Message-State: AOJu0Yzpot7+GTCiwu84nW9S5sNko7RdT0J5VC0aEB16Pu03dLzTzvcp /pU1rMgoy6o2150jR8XDVhJ5boYCD1qszRZW66EF9bPQvP4xHQcOaA/U X-Gm-Gg: ASbGnct3x+Yw4lHsVHnUyROfkGJtPWyeSfdDZaIqYshltuwprJFdlHyTgCIAFgO44U5 D1xaigiUEyqeWJC6Ug2ahno+62l/UnlcrlTHUxVphiq3fKCersJUJynUDtERFJIFUS9+pFrgKuK R3XRF7OndojfxGKvTNMAJENccSFWadZkdv6DbJu9A7jLn6XLsqeiVikRUwM+DoKUFnsg26wD+Zr y//sXjCp22U4HD6XKNVPJtlk40c/F7UxlhosRyYCRPd31Cs7G/dVubjqh1SHH2ybEbJvZW7LTu7 Zg1GILY+zJIkYRqsqckbFSSDww+sLoRFzYi63EUqRqi0EAb7HZc2ByFrH8cnIp+qJi25o223BNs DcTsvZsolCCIFhpLmWw== X-Google-Smtp-Source: AGHT+IGeQ1u4AoGhlYo8kgmCKQenafouUCLlNX4fxfebzGsC3hfoSv6y546S9TcBswJHKfgNZJfd/Q== X-Received: by 2002:a05:6902:6b0a:b0:e8b:411a:64a8 with SMTP id 3f1490d57ef6-e8b6e14faaamr725647276.24.1752022827080; Tue, 08 Jul 2025 18:00:27 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:26 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com Subject: [PATCH v4 03/13] mm/damon/sysfs-schemes: implement DAMOS action destinations directory Date: Tue, 8 Jul 2025 19:59:33 -0500 Message-ID: <20250709005952.17776-4-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: SeongJae Park DAMOS_MIGRATE_{HOT,COLD} can have multiple action destinations and their weights. Implement sysfs directory named 'dests' under each scheme directory to let DAMON sysfs ABI users utilize the feature. The interface is similar to other multiple parameters directory like kdamonds or filters. The directory contains only nr_dests file initially. Writing a number of desired destinations to nr_dests creates directories of the number. Each of the created directories has two files named id and weight. Users can then write the destination's identifier (node id in case of DAMOS_MIGRATE_*) and weight to the files. Signed-off-by: SeongJae Park Reviewed-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 225 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 224 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 601360e9b521..b9434cdaacdc 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1655,6 +1655,204 @@ static const struct kobj_type damon_sysfs_access_pa= ttern_ktype =3D { .default_groups =3D damon_sysfs_access_pattern_groups, }; =20 +/* + * dest (action destination) directory + */ + +struct damos_sysfs_dest { + struct kobject kobj; + unsigned int id; + unsigned int weight; +}; + +static struct damos_sysfs_dest *damos_sysfs_dest_alloc(void) +{ + return kzalloc(sizeof(struct damos_sysfs_dest), GFP_KERNEL); +} + +static ssize_t id_show( + struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + + return sysfs_emit(buf, "%u\n", dest->id); +} + +static ssize_t id_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + int err =3D kstrtouint(buf, 0, &dest->id); + + return err ? err : count; +} + +static ssize_t weight_show( + struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + + return sysfs_emit(buf, "%u\n", dest->weight); +} + +static ssize_t weight_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + int err =3D kstrtouint(buf, 0, &dest->weight); + + return err ? err : count; +} + +static void damos_sysfs_dest_release(struct kobject *kobj) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + kfree(dest); +} + +static struct kobj_attribute damos_sysfs_dest_id_attr =3D + __ATTR_RW_MODE(id, 0600); + +static struct kobj_attribute damos_sysfs_dest_weight_attr =3D + __ATTR_RW_MODE(weight, 0600); + +static struct attribute *damos_sysfs_dest_attrs[] =3D { + &damos_sysfs_dest_id_attr.attr, + &damos_sysfs_dest_weight_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damos_sysfs_dest); + +static const struct kobj_type damos_sysfs_dest_ktype =3D { + .release =3D damos_sysfs_dest_release, + .sysfs_ops =3D &kobj_sysfs_ops, + .default_groups =3D damos_sysfs_dest_groups, +}; + +/* + * dests (action destinations) directory + */ + +struct damos_sysfs_dests { + struct kobject kobj; + struct damos_sysfs_dest **dests_arr; + int nr; +}; + +static struct damos_sysfs_dests * +damos_sysfs_dests_alloc(void) +{ + return kzalloc(sizeof(struct damos_sysfs_dests), GFP_KERNEL); +} + +static void damos_sysfs_dests_rm_dirs( + struct damos_sysfs_dests *dests) +{ + struct damos_sysfs_dest **dests_arr =3D dests->dests_arr; + int i; + + for (i =3D 0; i < dests->nr; i++) + kobject_put(&dests_arr[i]->kobj); + dests->nr =3D 0; + kfree(dests_arr); + dests->dests_arr =3D NULL; +} + +static int damos_sysfs_dests_add_dirs( + struct damos_sysfs_dests *dests, int nr_dests) +{ + struct damos_sysfs_dest **dests_arr, *dest; + int err, i; + + damos_sysfs_dests_rm_dirs(dests); + if (!nr_dests) + return 0; + + dests_arr =3D kmalloc_array(nr_dests, sizeof(*dests_arr), + GFP_KERNEL | __GFP_NOWARN); + if (!dests_arr) + return -ENOMEM; + dests->dests_arr =3D dests_arr; + + for (i =3D 0; i < nr_dests; i++) { + dest =3D damos_sysfs_dest_alloc(); + if (!dest) { + damos_sysfs_dests_rm_dirs(dests); + return -ENOMEM; + } + + err =3D kobject_init_and_add(&dest->kobj, + &damos_sysfs_dest_ktype, + &dests->kobj, "%d", i); + if (err) { + kobject_put(&dest->kobj); + damos_sysfs_dests_rm_dirs(dests); + return err; + } + + dests_arr[i] =3D dest; + dests->nr++; + } + return 0; +} + +static ssize_t nr_dests_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_dests *dests =3D container_of(kobj, + struct damos_sysfs_dests, kobj); + + return sysfs_emit(buf, "%d\n", dests->nr); +} + +static ssize_t nr_dests_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_dests *dests; + int nr, err =3D kstrtoint(buf, 0, &nr); + + if (err) + return err; + if (nr < 0) + return -EINVAL; + + dests =3D container_of(kobj, struct damos_sysfs_dests, kobj); + + if (!mutex_trylock(&damon_sysfs_lock)) + return -EBUSY; + err =3D damos_sysfs_dests_add_dirs(dests, nr); + mutex_unlock(&damon_sysfs_lock); + if (err) + return err; + + return count; +} + +static void damos_sysfs_dests_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damos_sysfs_dests, kobj)); +} + +static struct kobj_attribute damos_sysfs_dests_nr_attr =3D + __ATTR_RW_MODE(nr_dests, 0600); + +static struct attribute *damos_sysfs_dests_attrs[] =3D { + &damos_sysfs_dests_nr_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damos_sysfs_dests); + +static const struct kobj_type damos_sysfs_dests_ktype =3D { + .release =3D damos_sysfs_dests_release, + .sysfs_ops =3D &kobj_sysfs_ops, + .default_groups =3D damos_sysfs_dests_groups, +}; + /* * scheme directory */ @@ -1672,6 +1870,7 @@ struct damon_sysfs_scheme { struct damon_sysfs_stats *stats; struct damon_sysfs_scheme_regions *tried_regions; int target_nid; + struct damos_sysfs_dests *dests; }; =20 struct damos_sysfs_action_name { @@ -1762,6 +1961,22 @@ static int damon_sysfs_scheme_set_access_pattern( return err; } =20 +static int damos_sysfs_set_dests(struct damon_sysfs_scheme *scheme) +{ + struct damos_sysfs_dests *dests =3D damos_sysfs_dests_alloc(); + int err; + + if (!dests) + return -ENOMEM; + err =3D kobject_init_and_add(&dests->kobj, &damos_sysfs_dests_ktype, + &scheme->kobj, "dests"); + if (err) + kobject_put(&dests->kobj); + else + scheme->dests =3D dests; + return err; +} + static int damon_sysfs_scheme_set_quotas(struct damon_sysfs_scheme *scheme) { struct damon_sysfs_quotas *quotas =3D damon_sysfs_quotas_alloc(); @@ -1894,9 +2109,12 @@ static int damon_sysfs_scheme_add_dirs(struct damon_= sysfs_scheme *scheme) err =3D damon_sysfs_scheme_set_access_pattern(scheme); if (err) return err; - err =3D damon_sysfs_scheme_set_quotas(scheme); + err =3D damos_sysfs_set_dests(scheme); if (err) goto put_access_pattern_out; + err =3D damon_sysfs_scheme_set_quotas(scheme); + if (err) + goto put_dests_out; err =3D damon_sysfs_scheme_set_watermarks(scheme); if (err) goto put_quotas_access_pattern_out; @@ -1927,6 +2145,9 @@ static int damon_sysfs_scheme_add_dirs(struct damon_s= ysfs_scheme *scheme) put_quotas_access_pattern_out: kobject_put(&scheme->quotas->kobj); scheme->quotas =3D NULL; +put_dests_out: + kobject_put(&scheme->dests->kobj); + scheme->dests =3D NULL; put_access_pattern_out: kobject_put(&scheme->access_pattern->kobj); scheme->access_pattern =3D NULL; @@ -1937,6 +2158,8 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_s= ysfs_scheme *scheme) { damon_sysfs_access_pattern_rm_dirs(scheme->access_pattern); kobject_put(&scheme->access_pattern->kobj); + kobject_put(&scheme->dests->kobj); + damos_sysfs_dests_rm_dirs(scheme->dests); damon_sysfs_quotas_rm_dirs(scheme->quotas); kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63DBF18F2FC; Wed, 9 Jul 2025 01:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022833; cv=none; b=JpPyTsXE4UcDOvmN2MLtEG+h4hQqxzTnRrhVNqB0LpBHuiG4aJbhLPXo6p7LbqvD07quqKSz1DrivMWCZJ/tmNBbGpAFG46K7kGaWLe891sEhJSmPaxfYjSpwc+DH/UHSdN+jrrrCKYTbpJv9jABuNMaEjixQ36bsGtBDt0GmA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022833; c=relaxed/simple; bh=kBGVCYlBO0JURIWpfIht3mgfCTHSB2GXv7bsD1cphHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BdtVcJLYvT5jEgqTs4R76d9OE1CxriI8ex9AFFV3TapyVcZikiH9HRSPL0/guIjsFQs7JG/ApjZkmqFwhdw1Cn9/b4dCIOURRHNJSFpu+NpFRMBQ4GJfaptYbGczjwaudTWurBZFIxtEZXc1jmxuyPYLxLqoDdQZqw5iK/gdDAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RzWc4BSr; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RzWc4BSr" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e898de36cfbso4273306276.1; Tue, 08 Jul 2025 18:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022831; x=1752627631; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VRqZ7kP81Zaq1arwauUEMN4RtZnPWf0LKmXEbv9bw+8=; b=RzWc4BSry9ffeFjy8MbvRLPy+2nNcqR8GIQCZv4Zmo7y6myXdbaCq3I3EhFR2M68/3 jIRO1FBz25s6b8TBy6XVPy85cIevPlNvGhUFnqjztGor/m4tSCyaOlI5I+7GUFtmHS0W UTr92mrLL6WWFzDqy73RG3vfkOVTPyrVp5qu4skJmk6iyoF2nhXNSua6qdBqwLnO494G wPq8CjB+PS1IOYVxGVq6MYaYPcJ2sz7KlDEf4lChSshAq0rC6HqqJW1P98KV9ISW/q0/ /RpZJXu/Zt0wXq5lbBrUSc06cA0gGv2CmWXUoZY3z4rOshzFvXrRK+wlnL/wPxYa2Tx7 nYmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022831; x=1752627631; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VRqZ7kP81Zaq1arwauUEMN4RtZnPWf0LKmXEbv9bw+8=; b=DocxukEeSWCG44H9ps0K1f4UCuCxolvraukRthJMRwpDggC6HCZxfy3ACpr79gYSdm V0+3wk8J8YSt51mrYgZyC2Lb9h7XfwDLK24HfkhpQmuBsbVjaPXopKM61/4IhyCw0H5T WLrPw1cz7wsXMTwWoSpYXClNynVi1kWFO6bNm8EayDqEzkVVNsTx+QHQgGLS3VeB2SpS ESCBMZ62gXwLjuCyKByszDO6DZ6fbE2bJp9nC4leCaH6ytknK0NglBfznPJ0WFkTCdZj gmAF4/9PUvIpOKGIl8CcYGHR9+ahFi0+kCTDHulViXqtMzlai0jATyTZ3lvQNGGh2eNs YXQQ== X-Forwarded-Encrypted: i=1; AJvYcCVnnSPMT0S+VZDFf+JpOI2NznyoYJvQKJzhC7U/H1AI17MxSQ0fkTpVDGCAvEUT0vu/FnZV+L1hB1qr8kR+@vger.kernel.org, AJvYcCXKxsJ8C4xQohJY4N07GPW/NlrxUiH2TiP6bKF+DdcaWmfR9/lNFTzpa8Y6uNjOPmNFbddGV9UfIlc=@vger.kernel.org X-Gm-Message-State: AOJu0YxxivxAltzrHxMaJdeRr/iu2Y2Vucd1EY/mZp2xXqa0IJuZRwXz NrKXbOCxdU476RU/SzuoGsDgurSCPANhPbTT5nxSVu9NLkjtLMF37k2n X-Gm-Gg: ASbGncuc7/kL7zb4BHBuA9BRf6aSbQdmzzOuIgb5gYTxbvw9kE6vlyZIfI7+GWWeIBw FAccQGvS4TB8sAAvXdAaseJtvbzaAeYIKEOF3s26qpRMrbt5AHNzb8DamalbSeK4KqDCuFqUwRq vt74VBw9YBgsnzB2zxyvluF/0C/dbR3YsOK1QqDuNXZgMYb9u9AV+ehwiGeM6t7I60Aei7MZ7ML TVJVIAHNcTc7ThLdy0NUaApuSff50/e/L4NOwXllbtHLLfHwQ8P40O2DIff1ukPNWPEJswz5n3F djC0Am/gWBO4anXXjLkiLHHzi8K1MDaahmwYiUdr2KEMtXzjYqfZu5xPYg2rLuj0ldsYTnWL4EF duiWh67OmoPcJfAzASA== X-Google-Smtp-Source: AGHT+IFFk12vBHKfYShm0xwUy70JkBS9iNu9v3bAoNdevYxQvMw6G4nHxm7r8pPOOSVJOc1J+GaBlQ== X-Received: by 2002:a05:6902:2846:b0:e84:3769:d7e1 with SMTP id 3f1490d57ef6-e8b6e0dfd76mr1151677276.8.1752022831313; Tue, 08 Jul 2025 18:00:31 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:31 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com Subject: [PATCH v4 04/13] mm/damon/sysfs-schemes: set damos->migrate_dests Date: Tue, 8 Jul 2025 19:59:34 -0500 Message-ID: <20250709005952.17776-5-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: SeongJae Park Pass user-specified multiple DAMOS action destinations and their weights to DAMON core API, so that user requests can really work. Signed-off-by: SeongJae Park Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index b9434cdaacdc..74056bcd6a2c 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2576,6 +2576,29 @@ void damos_sysfs_update_effective_quotas( } } =20 +static int damos_sysfs_add_migrate_dest(struct damos *scheme, + struct damos_sysfs_dests *sysfs_dests) +{ + struct damos_migrate_dests *dests =3D &scheme->migrate_dests; + int i; + + dests->node_id_arr =3D kmalloc_array(sysfs_dests->nr, + sizeof(*dests->node_id_arr), GFP_KERNEL); + if (!dests->node_id_arr) + return -ENOMEM; + dests->weight_arr =3D kmalloc_array(sysfs_dests->nr, + sizeof(*dests->weight_arr), GFP_KERNEL); + if (!dests->weight_arr) + /* ->node_id_arr will be freed by scheme destruction */ + return -ENOMEM; + for (i =3D 0; i < sysfs_dests->nr; i++) { + dests->node_id_arr[i] =3D sysfs_dests->dests_arr[i]->id; + dests->weight_arr[i] =3D sysfs_dests->dests_arr[i]->weight; + } + dests->nr_dests =3D sysfs_dests->nr; + return 0; +} + static struct damos *damon_sysfs_mk_scheme( struct damon_sysfs_scheme *sysfs_scheme) { @@ -2638,6 +2661,11 @@ static struct damos *damon_sysfs_mk_scheme( damon_destroy_scheme(scheme); return NULL; } + err =3D damos_sysfs_add_migrate_dest(scheme, sysfs_scheme->dests); + if (err) { + damon_destroy_scheme(scheme); + return NULL; + } return scheme; } =20 --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D50EB944F; Wed, 9 Jul 2025 01:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022841; cv=none; b=WOTS9WKRfGz/xkp1B68Y61OcZ/Fc7PTJ8zCpIsbSfq70Dec0MwtQfYfzY1b5PKNTzmN7DgvCZx7S8uD60GnpXEqrbfJ60siJlnw3x7mzFrdb4QeJ3/vgZzR43THZCoqjxdF7rzMDidm2YcvemhIz4GwLZxnkOi14OyVOdIN7WVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022841; c=relaxed/simple; bh=2noVsCQNVQLRiGq6reRkE5gM+8BX0pVDlcLEQw236uo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O7vrRdzi12QXNcprN0Uaj8z1vhBBceCBw5cWHOgLiIHmIXrt71Udb8Z/ikQncq5YPUk7QTNrkPBwzuLXZ7nfwSm4fUr/QixTxGN1MBkMt4Yhw5ghkwiSj/+evvse1a1QBtTLwUrMjkR/U/Lf44N/HKuZ/g48bPt4z1yf/hGBt9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bFggfCmZ; arc=none smtp.client-ip=209.85.219.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bFggfCmZ" Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e7311e66a8eso4535676276.2; Tue, 08 Jul 2025 18:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022836; x=1752627636; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T0AEBACIj7iufFFEjwK+DXtNtO5oq6pBK1Svk06pLxI=; b=bFggfCmZ1Z7GUsxha4gTXpZmi/YNN/hmWHxtnqjw8TLfIn+PPW+zmUZXhxo8GaejcL WNKumoC4ZEeMSZTBJEFdpGr2SAdQUvTOkMb9K2dLEKJrX9fojUMz2mFfiN8pxlAVPpYN Fxg0j37pbHYGlsz+3WA8KwTpcijZjrEyN/umVxNBPTtYc+9SsuQ06bY1fdi3fj9H7wRA Retr4gvLHCL+oNE95L22ay+JUH5m/NStY/g5GR9k3n5D/vqPGKfsfjBgyIw5hzMJEzpu rp50WxLsxJOxErQ6eXSz2xU2uKVlKN/CRPn4XC1vEPcgxBLe23Mgjaf6e9orokT3AFjf UTjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022836; x=1752627636; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T0AEBACIj7iufFFEjwK+DXtNtO5oq6pBK1Svk06pLxI=; b=c9AbaExLhV7ufjufUy9h4PGvT+RIAGcIb/ASyfkqH9vRIl7sNSsfPt7rWhAFBruCcF QYnk5KCfwjTRBBW72tDV6M1eH1ZhQS3V9bENjNqguWyikYw410S1LfdoC/9EFxYOYcVE +UGpkeEdKvlS73m8WuEMva4RUs66X9jdr6tUvYSFEIszzATixNIUhKnqb0ThWACy6UPX WRVuytACiWXN7i6JzL0Kt1k7iABYxe2+CwvDOv6lJG9C5K+N9zb5/FVuFLaMN3sodaAe zL19zJPT3DLgE8L6KqemIsCquPYxy2frCGx5MBakBk07mFEzVK2xT1PL7JmyR9qASOUN u1Tg== X-Forwarded-Encrypted: i=1; AJvYcCVJ4HERkVCek5VZuzCg+csCOnFotCDNUG+l+yc7i1fFqx9QTBPhDLW1AI6pFa70av7ddY/H9gWQ1dt3fmxT@vger.kernel.org, AJvYcCWi1HEcTl33AV3t+LoZLel760HnZ6cjVEZmBa1rY+4FrKEqmvVEa/ic/tUUaNgeyKB1SFDAj0HZtho=@vger.kernel.org X-Gm-Message-State: AOJu0Yy798UMs7bz0FtJVyGwq5ghLJFgKldg/CcmvSg9mb+IBF9fvW+y KUVG0i1kp69ech0W8ZQE127zSPWDnfPYQhrEWxZmFFDDnZIZt0efrZHdVTFNq/4XC5E= X-Gm-Gg: ASbGnctxKYMJDkTRCJDxdlVA8SFeLnl5L3n5d0VGFsBviIDGxCUKTCE9xn082TT6yFA bEKYPhqUDJA/YVBM6V4w+FXwPodR0XNeAK9LwawRKK0DhhR20Ay89RjTBxK1N0kMQHvV57k4FvG qPAjpT/NoyC5E5ZfvVxs1wOX6Sia85v2CY+ZIwpKTvR458lPmdqMa/a0MOIkXYCMCCA8usD1sB+ 67S5V1Ktmmsf9XGVVT88YCBmpCk2cDUuWLagGPaaq0BCjfsw9WpAetlhUYS3LThBp5i0gBDmoXf i6XP+MaOzUzmg/FflrTQnEv25RJjaOl+sXvTodG4x02oQUMJTLvxzi8LPRc/IzLrBwMLB9ofetF FW8hyZOY= X-Google-Smtp-Source: AGHT+IGDozJUCJpVBxPfjv9ILiQSL1R6miXqzbkK4caVqVpgbl+9ZhuvLHM+DyHUEdodqwUQX37wGw== X-Received: by 2002:a05:6902:986:b0:e81:9b39:e46 with SMTP id 3f1490d57ef6-e8b6e102b32mr1051961276.18.1752022835632; Tue, 08 Jul 2025 18:00:35 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:35 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com Subject: [PATCH v4 05/13] Docs/ABI/damon: document schemes dests directory Date: Tue, 8 Jul 2025 19:59:35 -0500 Message-ID: <20250709005952.17776-6-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: SeongJae Park Document the new DAMOS action destinations sysfs directories on ABI doc. Signed-off-by: SeongJae Park Reviewed-by: SeongJae Park --- .../ABI/testing/sysfs-kernel-mm-damon | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentatio= n/ABI/testing/sysfs-kernel-mm-damon index 5697ab154c1f..e98974dfac7a 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -431,6 +431,28 @@ Description: Directory for DAMON operations set layer-= handled DAMOS filters. /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//filters directory. =20 +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//de= sts/nr_dests +Date: Jul 2025 +Contact: SeongJae Park +Description: Writing a number 'N' to this file creates the number of + directories for setting action destinations of the scheme named + '0' to 'N-1' under the dests/ directory. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//de= sts//id +Date: Jul 2025 +Contact: SeongJae Park +Description: Writing to and reading from this file sets and gets the id of + the DAMOS action destination. For DAMOS_MIGRATE_{HOT,COLD} + actions, the destination node's node id can be written and + read. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//de= sts//weight +Date: Jul 2025 +Contact: SeongJae Park +Description: Writing to and reading from this file sets and gets the weight + of the DAMOS action destination to select as the destination of + each action among the destinations. + What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//st= ats/nr_tried Date: Mar 2022 Contact: SeongJae Park --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB45B156678; Wed, 9 Jul 2025 01:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022847; cv=none; b=BsaJzEfVeFR8YlNX3/WGrvp5u/UJ4s8Zo1HWsyApGq2GmUrm/3bU0pvNFiNxzEHD/R1yxLmrgTqaann1zaXWmqq1eEwK7FA922uVB8CYdgMbFeaAVy5OjSA6TSQ90XA/BINMeif3jR2FDYOlreUO/Tz1058ALDaakgynNLZjt18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022847; c=relaxed/simple; bh=IsxDvUOlPC/SNQd1/+tcnpC3Es95w6IQg+qyLyewcNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CBHt/EdbBcJMgm/UPavihwUV3p9StYJmr21rOYvXfL9ia395tFcJUoo6fbT08doccc+tAJYOKjvHBspc9tBo7W2W5JfzpmGrhvuJ+FJoPnsByaty3p+ohjaIJwrKOnW6hC8URZRQ9Is+GbD5QC6HjiURt0CbtMg8IueuDVkyd8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=URWBSzy1; arc=none smtp.client-ip=209.85.219.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="URWBSzy1" Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e8b3cc05665so2793998276.2; Tue, 08 Jul 2025 18:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022843; x=1752627643; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H2jsjg4EouOhcgExOsiiXXDMU3g5WamEv1plw5aSp2k=; b=URWBSzy1cz91XBJ5ACVDdXX/IGi2f3wYCoPCcAb0zSnz+DPn3a98ShzlhmEPUrx1WX 7TnmFln+UCXiv8zMrk6JJ4DEEjJ/YrnWTUIklB0ADbXZH2K719C9+ZYvER7OYpeBgncp KDuFv01R+NKxiKOXHzYuJaBWIgTVy0qWEhgFpe1d3HBqtfzcJZxSmOJ4mygqQJdX6J26 kfKH0PbEGxm1sgIJq8ADI+2+YISFZmzDrVx5UFaqKVIlwtV7+mqLYXVogUHipPKQ5VYy 4brU680V61pTPIekZRznmSAJWdqsnFvuif3LmpRUGeM0Giao0j0iZhR+QZjQmmPwdVwg EqdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022843; x=1752627643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H2jsjg4EouOhcgExOsiiXXDMU3g5WamEv1plw5aSp2k=; b=XcxzyAd8tMS4528P8M1xVk8vHtLeofwAqT4r/aHIHSmpTk6uQinGxgxp2676WKRAyk BCZy2QmRk0doLGJOreMDoJ+c6q0yAxdv1NavkbDdVEx54U2hhcsC3ztrl9UQJkFNR5ze YYk/UtOLX4+ak8Cqzd0Hu9h6rg/fTvpNK8dkPdOnc39k3KhORKAzgQ7HU0Gc/Z0QOd79 aUsB65P9oXivqFZ9Aa9j0a6E1G8BDJmx8ZkNMl7/pHvru0wQPNLgKy7mRkvpivftq3sF 2FmDHTwb5zAtdR4uufRpIEM2LXkc0zZbeP4Ci1HbGqPs4E2DlJVGRwTKine/GOXNjBl2 QNng== X-Forwarded-Encrypted: i=1; AJvYcCUbR4AG1h1mcX5kQ8NfV5Ak5JIQ/SzySH8vkseFNNP2jV3FpsDaS7SUjHJeaNGNtUnH/KtPfgz56bw=@vger.kernel.org, AJvYcCX4paOu7jmv3zWhG1eEzvPOesMe+qZuEuO9g2mymyfuqdYwG8ybTvlHgyKGk7AHosOWYxBNsz+HErNVYl7q@vger.kernel.org X-Gm-Message-State: AOJu0YyFduVSPgo0Y93VIKMH78epR9730ie/yv5Z6NBBEXs8KTFFa9EA ZYMHDQJ5p6jcuF09quJw6Rr7q9p4+5btACXxgv4eanxKkbOTdviaOexJGaKcod3gtvw= X-Gm-Gg: ASbGncu6oOgn1cQHxZUcotUMjC3KwmDlGMuHbPbLiuwqtgm537QhUcjUUl8yid5gNpF bAsC9HEaOzzEZ792rbHEUAM+KS+tOofu0oOLMa7dwJA79eKCdIotKoWK+r3Sm7fjJlWAfZKTLuK Rqj3gysj0Rq8YITrhoPA4Mx+D0B9XK8AGzF/sU5d7k5eWQd3pFQTRPtsyDrA8rGzra2m/uBZY6m WgilNHp0Typ7HqNIVI8tmXOrOcND8iRBHephiKahx8lKA0TV5u72tI9GTWdD0C7MvVh/2R8J9vb 59QvWWMstb3GyJ2trnuCNfrTHDp9y+6478Ly6oSnk9ODUue2ELoE/lf5OZCEStJLpO0zgTQu2Tb yKNX27ro= X-Google-Smtp-Source: AGHT+IG9eIe5dClap9KCxt/8jsEpzJHg4xsuwYOTV9E8tYS1KG14U14qxbM4oZ2qYkqz80lDz0BJew== X-Received: by 2002:a05:6902:2c05:b0:e87:982c:5528 with SMTP id 3f1490d57ef6-e8b6e151739mr662630276.40.1752022842295; Tue, 08 Jul 2025 18:00:42 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:41 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com Subject: [PATCH v4 06/13] Docs/admin-guide/mm/damon/usage: document dests directory Date: Tue, 8 Jul 2025 19:59:36 -0500 Message-ID: <20250709005952.17776-7-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: SeongJae Park Document the newly added DAMOS action destination directory of the DAMON sysfs interface on the usage document. Signed-off-by: SeongJae Park Reviewed-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index d960aba72b82..fc5c962353ed 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -85,6 +85,8 @@ comma (","). =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`watermarks `/metric,interval_us,high,mid,low =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`{core_,ops_,}filters `/nr_filters =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,m= in,max + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`dests `/nr_dests + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/id,weight =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`stats `/nr_tried,sz_tried,nr_applied,sz_applied,= sz_ops_filter_passed,qt_exceeds =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`tried_regions `/total_bytes =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/start,end,nr_accesses,age,sz_filter_passed @@ -307,10 +309,10 @@ to ``N-1``. Each directory represents each DAMON-bas= ed operation scheme. schemes// ------------ =20 -In each scheme directory, seven directories (``access_pattern``, ``quotas`= `, -``watermarks``, ``core_filters``, ``ops_filters``, ``filters``, ``stats``,= and -``tried_regions``) and three files (``action``, ``target_nid`` and -``apply_interval``) exist. +In each scheme directory, eight directories (``access_pattern``, ``quotas`= `, +``watermarks``, ``core_filters``, ``ops_filters``, ``filters``, ``dests``, +``stats``, and ``tried_regions``) and three files (``action``, ``target_ni= d`` +and ``apply_interval``) exist. =20 The ``action`` file is for setting and getting the scheme's :ref:`action `. The keywords that can be written to and read @@ -484,6 +486,29 @@ Refer to the :ref:`DAMOS filters design documentation of different ``allow`` works, when each of the filters are supported, and differences on stats. =20 +.. _damon_sysfs_dests: + +schemes//dests/ +------------------ + +Directory for specifying the destinations of given DAMON-based operation +scheme's action. This directory is ignored if the action of the given sch= eme +is not supporting multiple destinations. Only ``DAMOS_MIGRATE_{HOT,COLD}`` +actions are supporting multiple destinations. + +In the beginning, the directory has only one file, ``nr_dests``. Writing a +number (``N``) to the file creates the number of child directories named `= `0`` +to ``N-1``. Each directory represents each action destination. + +Each destination directory contains two files, namely ``id`` and ``weight`= `. +Users can write and read the identifier of the destination to ``id`` file. +For ``DAMOS_MIGRATE_{HOT,COLD}`` actions, the migrate destination node's n= ode +id should be written to ``id`` file. Users can write and read the weight = of +the destination among the given destinations to the ``weight`` file. The +weight can be an arbitrary integer. When DAMOS apply the action to each e= ntity +of the memory region, it will select the destination of the action based o= n the +relative weights of the destinations. + .. _sysfs_schemes_stats: =20 schemes//stats/ --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1525B145B3F; Wed, 9 Jul 2025 01:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022850; cv=none; b=B/ewxM68O9e84jYAWS3bFcJoLCRmGuJUz8PrsjUcpgOsOfmtMD9I3SD7lclluPOYF08VGETwSOzT5Jus7cnw5fXn61Bowxq3eopaaqW7WwEI6Dtcy0q1XRMNVde5YN5K8+szelF8BDZjTbhTmIkJFseB6CMY+fT4J6TDzImpqLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022850; c=relaxed/simple; bh=0MULHU7ToE1y24HCVFh8DYPWr9UIZ8/yXBxYBDmNcrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q9w2jAecX6FOVhu4a0Lpnq1vVvKEcJ0K5Al0LxgKZE612VXk+36FTBeHgY0++n6xjSiywl6WM09Guw3BiHgOQG+1JJ3HMpOT/+LZhs1BBA0iYuVzOAt53j7rn6nZ0E4zG8P/1kWFTqHoR/h/64b6Jn1pHufqFG9YWNNO0BLsdM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Oyp8YL6Z; arc=none smtp.client-ip=209.85.219.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oyp8YL6Z" Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e81cf6103a6so4647568276.3; Tue, 08 Jul 2025 18:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022848; x=1752627648; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J1rQEZ3P3BWEkub0MmK+N1X97w+uXKLbRycfS2a+MLc=; b=Oyp8YL6ZxV5UXy+AGWNr+0crcECSvtABWdbOJ/PFkDx/oP31hR/ZT8+GWssvGsQKW3 fU2nafqiHTh8xcFMzz0z/xBSVVFUlX87KbQYK1BnbnCzci0Kgx/fFIk5sBE71J6680ra OIE201g2Nnj7D/N06JeKP/TbptjuGpLOS01nAaReV3vD2E3qX6ETVOkNHcbk7d5UkMrU ls7JZc7NVWofKe3YsSUeMoBau2CYZ6Dxlu7U0IAP7W5/u4mK4Yuy/eknDI2BF6YFZKHK 2IRIhpsq/NYBUuUZMGM0xarC/QHzc7WprCNlVVmFVsLb1c3ogBEGgNMSpEj2Q9vNR95O 8qew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022848; x=1752627648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J1rQEZ3P3BWEkub0MmK+N1X97w+uXKLbRycfS2a+MLc=; b=LUndbWjq8HSKa4hgGOUbSBljT+Fw4M+WmI6UZlq/bLHG6pETPN4HK/Z5FSXhc8Hexb HSpI+V6FSEys1YKC/XkJz9hqvxPlP/P7igvGLn/CNFoe9Epk97bgrD+DolQX/mq3iTsq FmR46eYrjwhU+YuUVFZPDXDg4KuLURODs56+BConQyu4A0/Nj/MyMCd3JRTZDCw2JljG +oy2zTv8bz2BBtyoJSuinvRcYVY4NMxHKpy3/sI/DSXmGGqk+T0bOKqNfH2jREPg719W V/Vm5PcAbuyLeSTKx/1qr43E7qaLgkPKVx143Uy36YMax6HQxt8S4ayQxnP3JhpDpE5M uD2g== X-Forwarded-Encrypted: i=1; AJvYcCUIwIaggTRVpwy2/taqIX2+XwgQ7WxEmz56TrRliBt8yzMq6J8/MtzQJIkjqifRteWuUy1oGyhfsXcIYh1X@vger.kernel.org, AJvYcCWPjbGJceik3TUBzhIIL4zFwL+2uZs2eRR5kjnCjtAWEFKiE0gIrNYXMty+sucWwSG83kDo8StqamE=@vger.kernel.org X-Gm-Message-State: AOJu0YwjMgs0vcqLAXSQzwF2iwGmhvgr7A957PoHOqlG+nVTBmlxBGv2 eyoDlH/479x3ABGZ1/2fOIaIfkiY+NtD1m2Xd0NlAoZ7eXWf15fVDoBp X-Gm-Gg: ASbGncvdRwipMdMhQITTAaTUTroC9+iR4t0b3XOyJXMpQXDfbW9kubKTRgxfrQ3uruG IN/h/88lrQ36xsn/VDmVtBuDyjEFZezMgG9meXDte2Ctd7DJGVx/KrGZfxh1b6ASrhS0geVOzaS YmI8sqCiPPU7wIfTMpCYYz2epbrRNa+0qTry2DIYitnEeDjTBpZrOOu5kHN4YF8z7yqGexZIizs QVGP/UwnkqCyEYfCW826sAdtEvy7lKiksN5js5x86xjX/nGdsA6eikIp8oG8slyRjp7FxqZEP1t d0wCc3bZimogBf9Cxcs5u29oISDK6ibQFSyPGYJO/wAX4ObcHD7vXWbkMa9fNWhnbiRwf8mzW0M 2HT0Y2Y0= X-Google-Smtp-Source: AGHT+IH2cQxk/EywgLp+UgmsKikCG6qPU3Rfx8V0pFOQ6x3T288Qg0dLaeI6mBOGtVGc7IHSd5hNEA== X-Received: by 2002:a05:690c:680f:b0:70e:15e7:59e2 with SMTP id 00721157ae682-717b1c36f17mr11095217b3.24.1752022847915; Tue, 08 Jul 2025 18:00:47 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:47 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com Subject: [PATCH v4 07/13] mm/damon/core: Commit damos->migrate_dests Date: Tue, 8 Jul 2025 19:59:37 -0500 Message-ID: <20250709005952.17776-8-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bijan Tabatabai When committing new scheme parameters from the sysfs, copy the migrate_dests struct of the source schemes into the destination schemes. Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- mm/damon/core.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 62acfd5cf4ea..8d54bfc3ce0e 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -943,6 +943,41 @@ static void damos_set_filters_default_reject(struct da= mos *s) damos_filters_default_reject(&s->ops_filters); } =20 +static int damos_commit_dests(struct damos *dst, struct damos *src) +{ + struct damos_migrate_dests *dst_dests, *src_dests; + + dst_dests =3D &dst->migrate_dests; + src_dests =3D &src->migrate_dests; + + if (dst_dests->nr_dests !=3D src_dests->nr_dests) { + kfree(dst_dests->node_id_arr); + kfree(dst_dests->weight_arr); + + dst_dests->node_id_arr =3D kmalloc_array(src_dests->nr_dests, + sizeof(*dst_dests->node_id_arr), GFP_KERNEL); + if (!dst_dests->node_id_arr) { + dst_dests->weight_arr =3D NULL; + return -ENOMEM; + } + + dst_dests->weight_arr =3D kmalloc_array(src_dests->nr_dests, + sizeof(*dst_dests->weight_arr), GFP_KERNEL); + if (!dst_dests->weight_arr) { + /* ->node_id_arr will be freed by scheme destruction */ + return -ENOMEM; + } + } + + dst_dests->nr_dests =3D src_dests->nr_dests; + for (int i =3D 0; i < src_dests->nr_dests; i++) { + dst_dests->node_id_arr[i] =3D src_dests->node_id_arr[i]; + dst_dests->weight_arr[i] =3D src_dests->weight_arr[i]; + } + + return 0; +} + static int damos_commit_filters(struct damos *dst, struct damos *src) { int err; @@ -984,6 +1019,10 @@ static int damos_commit(struct damos *dst, struct dam= os *src) dst->wmarks =3D src->wmarks; dst->target_nid =3D src->target_nid; =20 + err =3D damos_commit_dests(dst, src); + if (err) + return err; + err =3D damos_commit_filters(dst, src); return err; } --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86ABD156678; Wed, 9 Jul 2025 01:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022856; cv=none; b=mbo6DDPQVEjd29QqMjg7oVZzXgr73rZh3W1UiNlovCg+OuYK8LYTHsWU+XP2LITazOSsPqyQW/XUjLgaZkBJ2QuIMqqxgTFXwO0uWVDZp591FhJDbegnWsms1ufCpJcpBATHg3Ig1EepkmF7IyPdCGQmOSsHiqLLYdQNufHZPgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022856; c=relaxed/simple; bh=L9z9MlZY9GADbKkS2o+6k0p7RSnZuJugrqzlxUfWhGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSzVwFQlRk+uTHMVjyujo9PA64d1PNl/11QO1YUNa9jZvJiILQ4+4xiJMxsslnxhkg+vCd/IO2UmmO5GoEnHbkCQY9/62SQ88yJqQFhB+tFPwRa19bTlbzngmKcpACWSa7pEo4iHXbJ7E8ctgQAlCWiRtZnqKGWOla1F2D9ndP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hkiXj0k/; arc=none smtp.client-ip=209.85.219.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hkiXj0k/" Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e819ebc3144so4672055276.0; Tue, 08 Jul 2025 18:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022853; x=1752627653; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hXQH/ve6qx1KBEN74fLQjfqY8wtfZagojlNvUz86dAc=; b=hkiXj0k/K27Q8thL9luTD88fKv830pRY9/WgqHEf7KS8YtgTf7hfvXvijDMWcPkv42 im2QjNbe99W73r2qlOQmNxWHkK2wbQAySQfXfS19Zoo46aFApJhwd16SSSrJtxmdLUcP dvrxOaPnn2Rrwo0bEwqpRbdoGf0k7Fv4+sYcM3claXCF4u114Hkuyg6dngJGRroal2Y/ R6O+YoD0h1VwjOBvKyMS0SiaQcmPGb0UoUrB7avu23spbYr8jxzHYuR16j9VMhHvy3CE UrZ7f9YciztFXIVgKWQMxE1sQ29pQX4bbuiUxXSsFYL5S9qTon7okbT+5rwyCVxh0VdL 2vWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022853; x=1752627653; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hXQH/ve6qx1KBEN74fLQjfqY8wtfZagojlNvUz86dAc=; b=L6aRAuXv6zpAAHcQX+eMa4WIXATG4zHW3r3wGW6zlMAZwJimdJNbg70XPvdC4zLR4B OdOQwtMw4VXVItMLipWXU+mWNu0vSDnXcNcPh6xMEIxRKc3WUDprurscxjtzBT259fbS hf7thQY4yB8UoLfm+YZwYnGdtpzmr+8MeSpHYDj62YUlPfkdT+K4FIU2cf3bN8fNWg2e bhYT/6lK4TV9994VyC+wsjpWxlSrZ5JfbDE+x5aDEsqmwj8MM339nNiH2Jd3hJcxbQWt bZ063OMTqcKQzUuWZK5pI1AuwFVKALAb03cXe5UjdDgNIywGG5Y7vMbPaKVCapVE3DZW k0Tw== X-Forwarded-Encrypted: i=1; AJvYcCX4gaQKtuVtLQrPR5NteUrbzb5mhoKBpPTx3ZU2DS0/CcwHd5XEE6n1s2Y68xe9sCclRGln2ZEZMlRwdib9@vger.kernel.org, AJvYcCXuOc0YPfNRgy9fyYRkEXwWaADoaflZQAL/rTDpH7rvX5tmd5G7vZ2E6eBck1fPC2b7sT7lWTPEWa0=@vger.kernel.org X-Gm-Message-State: AOJu0YwR3LVFkniPuqkxn3Lh99l61hzAdUHXm1f69k3IDX5eZv75+heR pLWUxZZ38iIy3m7IlSSVBo+IIaB/y+5wQgV2+ax9hm1B/QlHBVVZeXUV X-Gm-Gg: ASbGncv27jquOEpA0hRVnsCYHEWV6xFZTOAxLvRbznvOexy0jdpEpRCjj5m6IAXe6iD jctrnZmplqokPDvDCSC0Wl80tfIr/j5W3nVzQH5oKDybcxfQai+pPAkEjH5CHeORCy28GNw2elI Lcnj74XsWDOeO7oghQ/whGqbSMxAfwgba+L9VOJlUZvbmvFZMsIk22hYICDNLmvhcABkg8kTYwO /VJ1Hbg67f/GV/WZlQeHOJBc5X/r4hLmStUOK41qXWHKzsSJwLFIzpZ6hA8JQnZiQ0QLg+E2ygu SIY52ttb0MV7P5OYtMSvGf0FzQRRAYJEIvLtLO7BuqSwE+NUNTSunLNUi4NYdV0CaKgB89BUlGN 30CtJbpI= X-Google-Smtp-Source: AGHT+IH4QyN9DH4rspZx7He5z7+iL9YLC4MetFnDASWRiFISwzMF2jwtmKA6AtCtBMwy//dlFDHNCA== X-Received: by 2002:a05:6902:128f:b0:e85:e06a:7845 with SMTP id 3f1490d57ef6-e8b6e107726mr1137039276.5.1752022853205; Tue, 08 Jul 2025 18:00:53 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:52 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com, Ravi Shankar Jonnalagadda Subject: [PATCH v4 08/13] mm/damon: Move migration helpers from paddr to ops-common Date: Tue, 8 Jul 2025 19:59:38 -0500 Message-ID: <20250709005952.17776-9-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bijan Tabatabai This patch moves the damon_pa_migrate_pages function along with its corresponding helper functions from paddr to ops-common. The function prefix of "damon_pa_" was also changed to just "damon_" accordingly. This patch will allow page migration to be available to vaddr schemes as well as paddr schemes. Co-developed-by: Ravi Shankar Jonnalagadda Signed-off-by: Ravi Shankar Jonnalagadda Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- mm/damon/ops-common.c | 120 +++++++++++++++++++++++++++++++++++++++++ mm/damon/ops-common.h | 2 + mm/damon/paddr.c | 122 +----------------------------------------- 3 files changed, 123 insertions(+), 121 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index b43620fee6bb..918158ef3d99 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -5,6 +5,7 @@ * Author: SeongJae Park */ =20 +#include #include #include #include @@ -12,6 +13,7 @@ #include #include =20 +#include "../internal.h" #include "ops-common.h" =20 /* @@ -138,3 +140,121 @@ int damon_cold_score(struct damon_ctx *c, struct damo= n_region *r, /* Return coldness of the region */ return DAMOS_MAX_SCORE - hotness; } + +static unsigned int __damon_migrate_folio_list( + struct list_head *migrate_folios, struct pglist_data *pgdat, + int target_nid) +{ + unsigned int nr_succeeded =3D 0; + struct migration_target_control mtc =3D { + /* + * Allocate from 'node', or fail quickly and quietly. + * When this happens, 'page' will likely just be discarded + * instead of migrated. + */ + .gfp_mask =3D (GFP_HIGHUSER_MOVABLE & ~__GFP_RECLAIM) | + __GFP_NOWARN | __GFP_NOMEMALLOC | GFP_NOWAIT, + .nid =3D target_nid, + }; + + if (pgdat->node_id =3D=3D target_nid || target_nid =3D=3D NUMA_NO_NODE) + return 0; + + if (list_empty(migrate_folios)) + return 0; + + /* Migration ignores all cpuset and mempolicy settings */ + migrate_pages(migrate_folios, alloc_migration_target, NULL, + (unsigned long)&mtc, MIGRATE_ASYNC, MR_DAMON, + &nr_succeeded); + + return nr_succeeded; +} + +static unsigned int damon_migrate_folio_list(struct list_head *folio_list, + struct pglist_data *pgdat, + int target_nid) +{ + unsigned int nr_migrated =3D 0; + struct folio *folio; + LIST_HEAD(ret_folios); + LIST_HEAD(migrate_folios); + + while (!list_empty(folio_list)) { + struct folio *folio; + + cond_resched(); + + folio =3D lru_to_folio(folio_list); + list_del(&folio->lru); + + if (!folio_trylock(folio)) + goto keep; + + /* Relocate its contents to another node. */ + list_add(&folio->lru, &migrate_folios); + folio_unlock(folio); + continue; +keep: + list_add(&folio->lru, &ret_folios); + } + /* 'folio_list' is always empty here */ + + /* Migrate folios selected for migration */ + nr_migrated +=3D __damon_migrate_folio_list( + &migrate_folios, pgdat, target_nid); + /* + * Folios that could not be migrated are still in @migrate_folios. Add + * those back on @folio_list + */ + if (!list_empty(&migrate_folios)) + list_splice_init(&migrate_folios, folio_list); + + try_to_unmap_flush(); + + list_splice(&ret_folios, folio_list); + + while (!list_empty(folio_list)) { + folio =3D lru_to_folio(folio_list); + list_del(&folio->lru); + folio_putback_lru(folio); + } + + return nr_migrated; +} + +unsigned long damon_migrate_pages(struct list_head *folio_list, int target= _nid) +{ + int nid; + unsigned long nr_migrated =3D 0; + LIST_HEAD(node_folio_list); + unsigned int noreclaim_flag; + + if (list_empty(folio_list)) + return nr_migrated; + + noreclaim_flag =3D memalloc_noreclaim_save(); + + nid =3D folio_nid(lru_to_folio(folio_list)); + do { + struct folio *folio =3D lru_to_folio(folio_list); + + if (nid =3D=3D folio_nid(folio)) { + list_move(&folio->lru, &node_folio_list); + continue; + } + + nr_migrated +=3D damon_migrate_folio_list(&node_folio_list, + NODE_DATA(nid), + target_nid); + nid =3D folio_nid(lru_to_folio(folio_list)); + } while (!list_empty(folio_list)); + + nr_migrated +=3D damon_migrate_folio_list(&node_folio_list, + NODE_DATA(nid), + target_nid); + + memalloc_noreclaim_restore(noreclaim_flag); + + return nr_migrated; +} diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h index cc9f5da9c012..54209a7e70e6 100644 --- a/mm/damon/ops-common.h +++ b/mm/damon/ops-common.h @@ -16,3 +16,5 @@ int damon_cold_score(struct damon_ctx *c, struct damon_re= gion *r, struct damos *s); int damon_hot_score(struct damon_ctx *c, struct damon_region *r, struct damos *s); + +unsigned long damon_migrate_pages(struct list_head *folio_list, int target= _nid); diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index fcab148e6865..48e3e6fed636 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -13,7 +13,6 @@ #include #include #include -#include #include =20 #include "../internal.h" @@ -381,125 +380,6 @@ static unsigned long damon_pa_deactivate_pages(struct= damon_region *r, sz_filter_passed); } =20 -static unsigned int __damon_pa_migrate_folio_list( - struct list_head *migrate_folios, struct pglist_data *pgdat, - int target_nid) -{ - unsigned int nr_succeeded =3D 0; - struct migration_target_control mtc =3D { - /* - * Allocate from 'node', or fail quickly and quietly. - * When this happens, 'page' will likely just be discarded - * instead of migrated. - */ - .gfp_mask =3D (GFP_HIGHUSER_MOVABLE & ~__GFP_RECLAIM) | - __GFP_NOWARN | __GFP_NOMEMALLOC | GFP_NOWAIT, - .nid =3D target_nid, - }; - - if (pgdat->node_id =3D=3D target_nid || target_nid =3D=3D NUMA_NO_NODE) - return 0; - - if (list_empty(migrate_folios)) - return 0; - - /* Migration ignores all cpuset and mempolicy settings */ - migrate_pages(migrate_folios, alloc_migration_target, NULL, - (unsigned long)&mtc, MIGRATE_ASYNC, MR_DAMON, - &nr_succeeded); - - return nr_succeeded; -} - -static unsigned int damon_pa_migrate_folio_list(struct list_head *folio_li= st, - struct pglist_data *pgdat, - int target_nid) -{ - unsigned int nr_migrated =3D 0; - struct folio *folio; - LIST_HEAD(ret_folios); - LIST_HEAD(migrate_folios); - - while (!list_empty(folio_list)) { - struct folio *folio; - - cond_resched(); - - folio =3D lru_to_folio(folio_list); - list_del(&folio->lru); - - if (!folio_trylock(folio)) - goto keep; - - /* Relocate its contents to another node. */ - list_add(&folio->lru, &migrate_folios); - folio_unlock(folio); - continue; -keep: - list_add(&folio->lru, &ret_folios); - } - /* 'folio_list' is always empty here */ - - /* Migrate folios selected for migration */ - nr_migrated +=3D __damon_pa_migrate_folio_list( - &migrate_folios, pgdat, target_nid); - /* - * Folios that could not be migrated are still in @migrate_folios. Add - * those back on @folio_list - */ - if (!list_empty(&migrate_folios)) - list_splice_init(&migrate_folios, folio_list); - - try_to_unmap_flush(); - - list_splice(&ret_folios, folio_list); - - while (!list_empty(folio_list)) { - folio =3D lru_to_folio(folio_list); - list_del(&folio->lru); - folio_putback_lru(folio); - } - - return nr_migrated; -} - -static unsigned long damon_pa_migrate_pages(struct list_head *folio_list, - int target_nid) -{ - int nid; - unsigned long nr_migrated =3D 0; - LIST_HEAD(node_folio_list); - unsigned int noreclaim_flag; - - if (list_empty(folio_list)) - return nr_migrated; - - noreclaim_flag =3D memalloc_noreclaim_save(); - - nid =3D folio_nid(lru_to_folio(folio_list)); - do { - struct folio *folio =3D lru_to_folio(folio_list); - - if (nid =3D=3D folio_nid(folio)) { - list_move(&folio->lru, &node_folio_list); - continue; - } - - nr_migrated +=3D damon_pa_migrate_folio_list(&node_folio_list, - NODE_DATA(nid), - target_nid); - nid =3D folio_nid(lru_to_folio(folio_list)); - } while (!list_empty(folio_list)); - - nr_migrated +=3D damon_pa_migrate_folio_list(&node_folio_list, - NODE_DATA(nid), - target_nid); - - memalloc_noreclaim_restore(noreclaim_flag); - - return nr_migrated; -} - static unsigned long damon_pa_migrate(struct damon_region *r, struct damos= *s, unsigned long *sz_filter_passed) { @@ -527,7 +407,7 @@ static unsigned long damon_pa_migrate(struct damon_regi= on *r, struct damos *s, addr +=3D folio_size(folio); folio_put(folio); } - applied =3D damon_pa_migrate_pages(&folio_list, s->target_nid); + applied =3D damon_migrate_pages(&folio_list, s->target_nid); cond_resched(); s->last_applied =3D folio; return applied * PAGE_SIZE; --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7411C145A05; Wed, 9 Jul 2025 01:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022862; cv=none; b=kPOuMm0RZhDOl8bXZj99iwiht5/mMYF586Jos6I3/SkNnZLBgXQemndCBYrpxnes9MjfvKbqnr7n0RPaCQoxTHBR37TASIajvd/Fe23hpucXaGJdxBj8ALutZ2QX5PrsHdxleF0ta1JkAa3141GP7T/EayC3ueNKQ36AijYstFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022862; c=relaxed/simple; bh=2tx63+KdOTObd6zqvCEY/MQ4uDr7hrKI7nGRHNi+LY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZZz5GWmhN/Adewk+OEVmXVPSyMUQQoj3Gfqe7LFTaHdd8+HABHhviQVX3Mr0m4saQwq23kbKXbwPjIKevcSn/idXkHOULExwtCH1lPCD8bkNfkitT1LIF2aXsZWm1p4rhBiXuS5qfJm77zb2yxaFqBKLoEIPIVZqNeS/P3JvzYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MGBbYn/y; arc=none smtp.client-ip=209.85.219.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MGBbYn/y" Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-e740a09eb00so4418884276.0; Tue, 08 Jul 2025 18:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022859; x=1752627659; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kcIKbfhzMN50M5LtwAnXxnGE89hsJ21qEPoFUKJgyP0=; b=MGBbYn/yRNSy+r5jGsiUf+m/8oCcgYZ337ekYqpeNNDJex/v3JtlwZ8AocFGTzrMrh +DET3Gc/D0RyYX5ZayG2dFw8sk3gv8bDtSB6o91q4hkfG/3jG/cvc0vM0GbF5uuGlYAb QRdko2GPCanvsowoHmyfCPCHrC1HN+6rrvYKt5eBmz+PvLUOxFrpNgEmHGsiAdCNIe9o fvmPwvk8jf0/SCkLM7+MU33VVKqFgAynrTolAMirsllcdVahFLKDUipoTQAFcrKdnkF+ 3MufzfVkDPQKTlxbZpKYudrGIsEmfUms539fM7n+AOGrLI0W6t2zZ0VExc1KbKWIURqR xQvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022859; x=1752627659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kcIKbfhzMN50M5LtwAnXxnGE89hsJ21qEPoFUKJgyP0=; b=qZ1Ncs7XsRlxrV8HtNBb8n7KJrVShmV6/j13qiJnLrSvvh39bqGt2crPyVqZtwHRRx H6ext/W9iZb3XNL0q/h5IMqEq2UjCp5cwz7UbSn9yZTjZJzcGEy3rWbakPYUkDXqhDGe V9vT0CenOUDsDgfqK2JQN6coRxYnkJSbrOYSbGBlRZxflt2M4Y2ZecmZV0MOkAelGe29 K2XRQZFS/7c09RWld53gUc328wmU94gyoXcFW6G5zl4pkuwFXud1uz0DwImHUh3vMgfI aQ8fiw1xL+YUWVg8Jw8WeGqxPsvPx9rvLqIJ6L83KlHBlCrOWihnruGUCucZCcmkIm/3 /gPQ== X-Forwarded-Encrypted: i=1; AJvYcCVLLK84Dzt/EwKN+wIIkvDbtSQr5eJsjI5Xlbi5YgqVeCnbAByceW04/F3eH5vF2l05ad6xrQB6kt+b3bWN@vger.kernel.org, AJvYcCXsEnbnf2nIAeoboWiWKiFo0p1wXUoUDmVAhzhtGEo6PVhCPJHRUltAsNfy2tykUl+pQj+Rtjt+URc=@vger.kernel.org X-Gm-Message-State: AOJu0YwVETNz9Kf8lohql/MgTknevkPQutLG8quw7Xy+v+4LNSp6l5sO vtDI1JiQvWg2IfOeiU9k4a9fJHzf0hAc/fFR8TsnE/kFsUg7ikozYMC7 X-Gm-Gg: ASbGncvvcKHgTSK3LA68yaGClgf5tTEK7vZfdouPWIwgt3tzzMG8560/XopD3vVSeDp 57u7BjmHd1aWYkU/v4eGeHYlA2ltaPpxOjnBgzeEMPodWQiOJOCh6idXzVSuO9r9G89SFhRJRsU Xta05swnV6RCjwoDqYAgwLR6ZyqBVMgnwKEfguKBTOGaczJ6cgBvCS/hLSjnjMmNcfcQHhJQLuT tUmth7ZK/C6yhBCzm7KvCIPupAXjOL8QtHQWawZVGqY4W9w5L7ItkOEcmepd7zvGYF6NBCUIb7l kSbQw4M1bM4M9/cxU7y8E7pEgZ8cyaa56qxeu1+FHYLAXzxrQvpWLvQ67fi2+ym4nHX6/dpn4ES iqzO4TNk= X-Google-Smtp-Source: AGHT+IFYbwWbBORRAOQcUqRSE5nM3ImmXuihNVwFJJ1IgG2vxJBWwJ/OTio7E7L6AtKwcW8L80dpZg== X-Received: by 2002:a05:6902:2e0b:b0:e84:3657:e50 with SMTP id 3f1490d57ef6-e8b6e0cdb96mr1078235276.3.1752022859283; Tue, 08 Jul 2025 18:00:59 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:00:58 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com, Ravi Shankar Jonnalagadda Subject: [PATCH v4 09/13] mm/damon/vaddr: Add vaddr versions of migrate_{hot,cold} Date: Tue, 8 Jul 2025 19:59:39 -0500 Message-ID: <20250709005952.17776-10-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bijan Tabatabai migrate_{hot,cold} are paddr schemes that are used to migrate hot/cold data to a specified node. However, these schemes are only available when doing physical address monitoring. This patch adds an implementation for them virtual address monitoring as well. Co-developed-by: Ravi Shankar Jonnalagadda Signed-off-by: Ravi Shankar Jonnalagadda Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- mm/damon/vaddr.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 46554e49a478..b244ac056416 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -15,6 +15,7 @@ #include #include =20 +#include "../internal.h" #include "ops-common.h" =20 #ifdef CONFIG_DAMON_VADDR_KUNIT_TEST @@ -610,6 +611,68 @@ static unsigned int damon_va_check_accesses(struct dam= on_ctx *ctx) return max_nr_accesses; } =20 +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr, + unsigned long next, struct mm_walk *walk) +{ + struct list_head *migration_list =3D walk->private; + struct folio *folio; + spinlock_t *ptl; + pmd_t pmde; + + ptl =3D pmd_lock(walk->mm, pmd); + pmde =3D pmdp_get(pmd); + + if (!pmd_present(pmde) || !pmd_trans_huge(pmde)) + goto unlock; + + /* Tell page walk code to not split the PMD */ + walk->action =3D ACTION_CONTINUE; + + folio =3D damon_get_folio(pmd_pfn(pmde)); + if (!folio) + goto unlock; + + if (!folio_isolate_lru(folio)) + goto put_folio; + + list_add(&folio->lru, migration_list); + +put_folio: + folio_put(folio); +unlock: + spin_unlock(ptl); + return 0; +} +#else +#define damos_va_migrate_pmd_entry NULL +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + +static int damos_va_migrate_pte_entry(pte_t *pte, unsigned long addr, + unsigned long next, struct mm_walk *walk) +{ + struct list_head *migration_list =3D walk->private; + struct folio *folio; + pte_t ptent; + + ptent =3D ptep_get(pte); + if (pte_none(ptent) || !pte_present(ptent)) + return 0; + + folio =3D damon_get_folio(pte_pfn(ptent)); + if (!folio) + return 0; + + if (!folio_isolate_lru(folio)) + goto out; + + list_add(&folio->lru, migration_list); + +out: + folio_put(folio); + return 0; +} + /* * Functions for the target validity check and cleanup */ @@ -653,6 +716,34 @@ static unsigned long damos_madvise(struct damon_target= *target, } #endif /* CONFIG_ADVISE_SYSCALLS */ =20 +static unsigned long damos_va_migrate(struct damon_target *target, + struct damon_region *r, struct damos *s, + unsigned long *sz_filter_passed) +{ + LIST_HEAD(folio_list); + struct mm_struct *mm; + unsigned long applied =3D 0; + struct mm_walk_ops walk_ops =3D { + .pmd_entry =3D damos_va_migrate_pmd_entry, + .pte_entry =3D damos_va_migrate_pte_entry, + .walk_lock =3D PGWALK_RDLOCK, + }; + + mm =3D damon_get_mm(target); + if (!mm) + return 0; + + mmap_read_lock(mm); + walk_page_range(mm, r->ar.start, r->ar.end, &walk_ops, &folio_list); + mmap_read_unlock(mm); + mmput(mm); + + applied =3D damon_migrate_pages(&folio_list, s->target_nid); + cond_resched(); + + return applied * PAGE_SIZE; +} + static unsigned long damon_va_apply_scheme(struct damon_ctx *ctx, struct damon_target *t, struct damon_region *r, struct damos *scheme, unsigned long *sz_filter_passed) @@ -675,6 +766,9 @@ static unsigned long damon_va_apply_scheme(struct damon= _ctx *ctx, case DAMOS_NOHUGEPAGE: madv_action =3D MADV_NOHUGEPAGE; break; + case DAMOS_MIGRATE_HOT: + case DAMOS_MIGRATE_COLD: + return damos_va_migrate(t, r, scheme, sz_filter_passed); case DAMOS_STAT: return 0; default: @@ -695,6 +789,10 @@ static int damon_va_scheme_score(struct damon_ctx *con= text, switch (scheme->action) { case DAMOS_PAGEOUT: return damon_cold_score(context, r, scheme); + case DAMOS_MIGRATE_HOT: + return damon_hot_score(context, r, scheme); + case DAMOS_MIGRATE_COLD: + return damon_cold_score(context, r, scheme); default: break; } --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D0B21DDA18; Wed, 9 Jul 2025 01:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022866; cv=none; b=QXpRwltHtgZ8QPsI8vnzaPLIbqP5jdH+4e19NMUyWorI8mayN6DR4EaR7ZjpYuF5D3vxDa1CAxD8mQwwff95ySQgnC0MLSij92usFtnvfOerwW1Z1er2eGXIMR/4EoAcDPFFyw8DGWyefRVyK18CkeyNrsgw4KHudhZL5fopjqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022866; c=relaxed/simple; bh=K439CV0Hr790Er9RUMtoSY+/LksLRGeekuflMOjQ/tE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HBkdXDVIlyUlj2kuYO91JecWS5SKwpkPXZ1RpQrrQstcgWh6EuIDPWENjS7DbR4lP+GwPW8pDmLBg/TQi7zevS55X+8i0tL9qRSxdCPF3BXavrXdQyteYFNw5vh7y2fbQ9dYMCnmZRSQj1Y7gNyWSRbWmf59P1HLV7zK9RKoqWE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CVcINdYS; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CVcINdYS" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e740a09eae0so5040446276.1; Tue, 08 Jul 2025 18:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022864; x=1752627664; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C4j5uWVr2okio0nPQPsshhbU5KAvZtN3lS96eXXErJM=; b=CVcINdYSTaKsxOqaFlFSrbvcfJ03JMQm/kD4KfrBlzZBsSS/17xMHfVvQ4/wzrcSJi ikyBS/2404wrDX9eUSPRRqfKQT41qX13YiL4GAhnXnUu/d3RC8+O4OTFo4lHNzRA8kek 7k+dFyjHFZ+HAFKpFrh1qIlrMJLezfQxfH9AeoBMEC1wlUJLk/Shmllc7CGmgdwo/cin JQBjHKuzFxxZ1leQbXYoivgAjbDpjiNstnanxwjr+HkkEnfdXfiuPjrO7R6WMZjdE0b2 oAam2DTpFhayJYlfKDtQG7QccKCJujLoicSIPAZcJ4Z6xJ+Sl2rbCA4Mw5+rkpVb5hjP FBJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022864; x=1752627664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C4j5uWVr2okio0nPQPsshhbU5KAvZtN3lS96eXXErJM=; b=A4Ud6E3xTSWbw9bHLy6AT9RYnZ0De2srWSVJVda9Mw+k6vlEhBxwoR5nxfN2v237yC vO4t3A6NHhYmjYPq9Pqflrl9+wM3M1+txbvUBQeC2AL/cBIoNwkBXqtSQDFqH1TXmqRj 91zoc8prrmWtnkIuWSeAIQ0e/ysFoOYCE3XN4MxshFcwuQmMXrGuQoM10n9sOd+Se07n yFBQKBEEtz4lgCuGDaRTvmElB/sWfhVaE5HadyfrHxhSv0qo+XSf4g+5SDDHI1YNKQ0P o5Qa6XyhhyhA+/Bz8MN2zexHfPfzN3ig6G+pEzBhyFlNbObbSMRAOiij5BMSc3yX4KkO +v3A== X-Forwarded-Encrypted: i=1; AJvYcCVE/hG1S2zj4rJ36/2iQ8rAxx3NK8X7ifaMR5379J3bxEhrTRMtuAhi0ybIwmWCubnRD7iAtR6tf/20ja3a@vger.kernel.org, AJvYcCXblB1Y7cmU4FAaE5IUmkXsPoGzWWxoxcsWsklP80XcL3FMR4sbmeaEntO67M6HUesFCDRj6NT3mzw=@vger.kernel.org X-Gm-Message-State: AOJu0YxttW63JRqQMaD2K03jYzlWxCfZTzvDfptWQhx7B8jrgB3iuMlI L0nIBEffBUnEGIW5QcFm8FATGxl2XjFhKvJ7R6lAk4qNz4uMloNSD4yr X-Gm-Gg: ASbGncu4knCMHDYHJ9ka9BU+lWwQAnp1SuwxFGoyqhQ/4i86U5uyZ8AWAIrAaA+B4ab 7iabqbnSYXgJVDtTWYG8EwT5G44f1DHl9nZQrtV5vwHhs2v1uO33PHHAD8Y/m1RlK9pUf56Ally dHDaxwcdGZrUx8IiodVAe70iRcAk5LmWaI6bOrb4BCglZqOqQsjs8qU/fpxyH0Wu63OUtpFGg2H q2rf75FXzR5YPwDR7cVmCygII/E8rsIDJg0se+Pg8eRC++iGnjndTRmQtdVAsMBfsQ0AzyZXjeT pzLEOxcaJIhkhx1JRwX/FDSNns4WFaEdynNuggJkGRLG6WpBZ2rJur/5aBkd5P0IK+L/laLCYHq AQEr47FM= X-Google-Smtp-Source: AGHT+IHLPdZoeujPLqUztp6UuADx4QDXfITwDq09vzFE768onA06GI5SAONpI024p+kEEi9lspLVXA== X-Received: by 2002:a05:6902:6886:b0:e84:1f9f:1344 with SMTP id 3f1490d57ef6-e8b6e0e4588mr825062276.19.1752022864185; Tue, 08 Jul 2025 18:01:04 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:01:03 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com, Ravi Shankar Jonnalagadda Subject: [PATCH v4 10/13] Docs/mm/damon/design: Document vaddr support for migrate_{hot,cold} Date: Tue, 8 Jul 2025 19:59:40 -0500 Message-ID: <20250709005952.17776-11-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bijan Tabatabai Document that the migrate_{hot,cold} schemes can be used by the vaddr operations set. Co-developed-by: Ravi Shankar Jonnalagadda Signed-off-by: Ravi Shankar Jonnalagadda Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- Documentation/mm/damon/design.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index ddc50db3afa4..03f8137256f5 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -452,9 +452,9 @@ that supports each action are as below. - ``lru_deprio``: Deprioritize the region on its LRU lists. Supported by ``paddr`` operations set. - ``migrate_hot``: Migrate the regions prioritizing warmer regions. - Supported by ``paddr`` operations set. + Supported by ``vaddr``, ``fvaddr`` and ``paddr`` operations set. - ``migrate_cold``: Migrate the regions prioritizing colder regions. - Supported by ``paddr`` operations set. + Supported by ``vaddr``, ``fvaddr`` and ``paddr`` operations set. - ``stat``: Do nothing but count the statistics. Supported by all operations sets. =20 --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C43631E1A3D; Wed, 9 Jul 2025 01:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022872; cv=none; b=Vv8HDZdKNZGTpB60U/NJv1ZaAAuPNrT/rlBOnS0uHPL0e5okn0txs/Qaxl8QAV5MuG2gnr962sUQ10Z6XSnVLeS3vaFKAXQrB2IrZigmFjbUFr/RE63KgqjMz0YKqIPsZbf7kQGpSrBjrW4B4wlcoP7SZy0fNlGfiqqW/p6sd1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022872; c=relaxed/simple; bh=JzE3Nk/VzSdLN7NSVCdb6rvenOkMzV6KjMxB/f2iteE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SmxLUp9Jel/eaH1/XvI75qZ5+D4fO4Ln3Uwmc+VnZedgcSxzLsfabGwqdVTS6n73kPncT1mBOSaIgdkfYFvp9L+ckzF6k9yWKvqg8sboUxm+/I0AYc/EsZ1OjrZ067znQJ0AOlzkwh8XkokJQ7ThJvnEnfKC5bvlFHCRJY4bxo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fX6NWZ95; arc=none smtp.client-ip=209.85.219.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fX6NWZ95" Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e85e06a7f63so4528940276.1; Tue, 08 Jul 2025 18:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022869; x=1752627669; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BwtNm4BtmVP3B29Sr0z6Dg9gSZdTDCfEDKjBCM7yKB4=; b=fX6NWZ95b2ITQM2wV84fRfLqc0FAN+BZjYynJAyPmw50B/Rg0UZtWvz24Frx/0l3K/ B2hSJIJGEaYKTrWXNxviviXUQNAcyAe3RoqpugaVBuhPplaQUma+G5hceemhlLhPKBvk BzyKyEKdzRVbgYDhFhmRBc51XGChIrs9aY9Nk6dQRUSVGj/qT59ndbArRcpEVhmo0dKu 4NFeLrMnWO0mjK/ORf2KY/lq7cHw6uar2k4Qn1ADRWIUlfQyOeRYVxXQTprp/fH+f3Hq E4t8soMXeWJJ7CudPgYS607s//FUf5WNFoYqwBQpocc1RCq2j7rcnLFL0NeCIRCvzigL K7uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022869; x=1752627669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BwtNm4BtmVP3B29Sr0z6Dg9gSZdTDCfEDKjBCM7yKB4=; b=L4LbGeK9HbuP0USxD/7s/UPWLIZ4sk6l35seF8vxzrCCYuVDrp75AeUFb+VFYhTcZv tqm1KPBvsRfHkT9p4KQ4s9Eg9IPoNuxJCTgyQ0rdg/gCfFqfyx02AAi16G17c91W/LLo hlK+UC+A4r490S3R+jYFTohw+0NIdRZiMUdRmA/adJF2tnGudMa4zCPhBGm2mjowna6m cYLtWIpVXvlYQr1IiU36Vyu8LhoWd35Qio11Nt/UEPL7ed5DKt4KxsZw6NLmbu/IpBX6 ZFAqOrghohw+dLq8BdYgELIxjiopiKO46Nbhd2AydzPqB/yXDXDApCbKVidzpiDYnbQe dlwg== X-Forwarded-Encrypted: i=1; AJvYcCUAFuGNvLJYnlfRVjRhhcxdQOvP0HSWIRXzdq5rIzTCUi+KjYN1gx0aNbPY9m1fRJiaPxHWtH3P8zWI7xGj@vger.kernel.org, AJvYcCUKmmxZF9r4alzrwDSrlVhdgXzfDAb9PdQY5yT1tzdvZleAabkP2VnHBgHp/OFS8m2xACOBxK6J7CA=@vger.kernel.org X-Gm-Message-State: AOJu0YzMvW8DlXPBTeQNp8fAR2YEUz+8EzlZC6EC2gtE7DVrjHHApLh0 2NRXQdL67BfuRKzeirjvv7KhJMo24sVhP3flUC4LQA6w/URfZcuWKgo5 X-Gm-Gg: ASbGncvmjkCcZaBdEGLnCI6J1Vue7qSrn11p5rL1MedzfoiYRcFkqTQtbG55gbN4gks mPEKB/tS+pu4b0LcP74zu0s+3VtBTfaWw8uKuGfFf8m368rigPNX+OKCcB1hU+m3zAp40cVAaBw PEL/UBin+lLeXxo9LzPdQ33TFN8aJa08idQQeKt8fMeIP7j89uzh/n9HXKnLHx5veaSl6LCKgmf 9B2uJ4OUXsutVTwXL0wciSG2ImHAr41U1oA2nKcijiEQyaii8UGWSXlIo5F8z56OiglyHxS4DJi 1WqM/THt5lW+/MNp7DU/sQ3k+yyrb21EDNBtCbUcbiqxng0DxrSZHRsY6FZCgFnmVflMtv0SRN7 zYn2ECKs= X-Google-Smtp-Source: AGHT+IEyRvCqbPeHTafmEDhZZQo8dDhtfIjvEfEuUPSnxmp83I7UH79ZdtpmrabA8PjyfakEBMidxg== X-Received: by 2002:a05:6902:2309:b0:e8b:53ba:535 with SMTP id 3f1490d57ef6-e8b6e0e2aeamr1046878276.15.1752022869325; Tue, 08 Jul 2025 18:01:09 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:01:08 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com, Ravi Shankar Jonnalagadda Subject: [PATCH v4 11/13] mm/damon/vaddr: Use damos->migrate_dests in migrate_{hot,cold} Date: Tue, 8 Jul 2025 19:59:41 -0500 Message-ID: <20250709005952.17776-12-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bijan Tabatabai damos->migrate_dests provides a list of nodes the migrate_{hot,cold} actions should migrate to, as well as the weights which specify the ratio pages should be migrated to each destination node. This patch interleaves pages in the migrate_{hot,cold} actions according to the information provided in damos->migrate_dests if it is used. The interleaving algorithm used is similar to the one used in weighted_interleave_nid(). If damos->migration_dests is not provided, the actions migrate pages to the node specified in damos->target_nid as before. Co-developed-by: Ravi Shankar Jonnalagadda Signed-off-by: Ravi Shankar Jonnalagadda Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- mm/damon/vaddr.c | 108 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 92 insertions(+), 16 deletions(-) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index b244ac056416..47d5f33f89c8 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -611,11 +611,69 @@ static unsigned int damon_va_check_accesses(struct da= mon_ctx *ctx) return max_nr_accesses; } =20 +struct damos_va_migrate_private { + struct list_head *migration_lists; + struct damos_migrate_dests *dests; +}; + +/* + * Place the given folio in the migration_list corresponding to where the = folio + * should be migrated. + * + * The algorithm used here is similar to weighted_interleave_nid() + */ +static void damos_va_migrate_dests_add(struct folio *folio, + struct vm_area_struct *vma, unsigned long addr, + struct damos_migrate_dests *dests, + struct list_head *migration_lists) +{ + pgoff_t ilx; + int order; + unsigned int target; + unsigned int weight_total =3D 0; + int i; + + /* + * If dests is empty, there is only one migration list corresponding + * to s->target_nid. + */ + if (!dests->nr_dests) { + i =3D 0; + goto isolate; + } + + order =3D folio_order(folio); + ilx =3D vma->vm_pgoff >> order; + ilx +=3D (addr - vma->vm_start) >> (PAGE_SHIFT + order); + + for (i =3D 0; i < dests->nr_dests; i++) + weight_total +=3D dests->weight_arr[i]; + + /* If the total weights are somehow 0, don't migrate at all */ + if (!weight_total) + return; + + target =3D ilx % weight_total; + for (i =3D 0; i < dests->nr_dests; i++) { + if (target < dests->weight_arr[i]) + break; + target -=3D dests->weight_arr[i]; + } + +isolate: + if (!folio_isolate_lru(folio)) + return; + + list_add(&folio->lru, &migration_lists[i]); +} + #ifdef CONFIG_TRANSPARENT_HUGEPAGE static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr, unsigned long next, struct mm_walk *walk) { - struct list_head *migration_list =3D walk->private; + struct damos_va_migrate_private *priv =3D walk->private; + struct list_head *migration_lists =3D priv->migration_lists; + struct damos_migrate_dests *dests =3D priv->dests; struct folio *folio; spinlock_t *ptl; pmd_t pmde; @@ -633,12 +691,9 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsi= gned long addr, if (!folio) goto unlock; =20 - if (!folio_isolate_lru(folio)) - goto put_folio; - - list_add(&folio->lru, migration_list); + damos_va_migrate_dests_add(folio, walk->vma, addr, dests, + migration_lists); =20 -put_folio: folio_put(folio); unlock: spin_unlock(ptl); @@ -651,7 +706,9 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsig= ned long addr, static int damos_va_migrate_pte_entry(pte_t *pte, unsigned long addr, unsigned long next, struct mm_walk *walk) { - struct list_head *migration_list =3D walk->private; + struct damos_va_migrate_private *priv =3D walk->private; + struct list_head *migration_lists =3D priv->migration_lists; + struct damos_migrate_dests *dests =3D priv->dests; struct folio *folio; pte_t ptent; =20 @@ -663,12 +720,9 @@ static int damos_va_migrate_pte_entry(pte_t *pte, unsi= gned long addr, if (!folio) return 0; =20 - if (!folio_isolate_lru(folio)) - goto out; + damos_va_migrate_dests_add(folio, walk->vma, addr, dests, + migration_lists); =20 - list_add(&folio->lru, migration_list); - -out: folio_put(folio); return 0; } @@ -721,26 +775,48 @@ static unsigned long damos_va_migrate(struct damon_ta= rget *target, unsigned long *sz_filter_passed) { LIST_HEAD(folio_list); + struct damos_va_migrate_private priv; struct mm_struct *mm; + int nr_dests; + int nid; + bool use_target_nid; unsigned long applied =3D 0; + struct damos_migrate_dests *dests =3D &s->migrate_dests; struct mm_walk_ops walk_ops =3D { .pmd_entry =3D damos_va_migrate_pmd_entry, .pte_entry =3D damos_va_migrate_pte_entry, .walk_lock =3D PGWALK_RDLOCK, }; =20 + use_target_nid =3D dests->nr_dests =3D=3D 0; + nr_dests =3D use_target_nid ? 1 : dests->nr_dests; + priv.dests =3D dests; + priv.migration_lists =3D kmalloc_array(nr_dests, + sizeof(*priv.migration_lists), GFP_KERNEL); + if (!priv.migration_lists) + return 0; + + for (int i =3D 0; i < nr_dests; i++) + INIT_LIST_HEAD(&priv.migration_lists[i]); + + mm =3D damon_get_mm(target); if (!mm) - return 0; + goto free_lists; =20 mmap_read_lock(mm); - walk_page_range(mm, r->ar.start, r->ar.end, &walk_ops, &folio_list); + walk_page_range(mm, r->ar.start, r->ar.end, &walk_ops, &priv); mmap_read_unlock(mm); mmput(mm); =20 - applied =3D damon_migrate_pages(&folio_list, s->target_nid); - cond_resched(); + for (int i =3D 0; i < nr_dests; i++) { + nid =3D use_target_nid ? s->target_nid : dests->node_id_arr[i]; + applied +=3D damon_migrate_pages(&priv.migration_lists[i], nid); + cond_resched(); + } =20 +free_lists: + kfree(priv.migration_lists); return applied * PAGE_SIZE; } =20 --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DA511F8747; Wed, 9 Jul 2025 01:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022878; cv=none; b=eOAOCdQLDcXUGuNTy5PXbBc5iQguDTjSLhmQhWky+iD1+6xCKtx7+XidWXjJdW33LuRu16lJ0I589SUIesUpOIvNX6NlFhi2EQFiC5ezwebXvA6Mb9OT3rhKNH7hyAUVkxVhjHugvtvI0Nmv4s6epkS7/ahfPwNvMLIcJouRbtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022878; c=relaxed/simple; bh=6J+5cIy/RS0xSFqv44VRY5CPmSgMHZJZkpXzMeqwAwI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O9Y4dmOiC+5MdioYIV6UgZrM8c5k1pRA/1b7XqeRGWE5pyqS5+tIpYlJrynhwwJiqvj3/alkjAtbOEoWVW7esN1R8P6jxNYXsB3r8bEa3OhpBe24FgkP4tG58aJxt4Yd2HbxFng74uojRk7ejkcDMrHjvZLuLv+M+2cJGCX/s+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QFRk7t1+; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QFRk7t1+" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e733e25bfc7so4346565276.3; Tue, 08 Jul 2025 18:01:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022875; x=1752627675; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RwxdkvIH4+jDYN/7Cinl22ra/M1sXM4/dKfSa4ANwTM=; b=QFRk7t1+cts5GPrbmFC9mC/Fr9sVI1/4XkUaKpr8vrB1IhqhD7aMC4TowtHkz6ETMU tGwazfbVITaxQtVoUZb8KB24sWRoJWxUWOXSGojOcSG5es9K5YuzHbRM/LVpl4laZy27 CAEaOTfXPsaOLzL8/00OWCa4DMJ8vr2tBNpvqn8gchC5r5kM4r7Rj8hmtJuGSpj2BoKa Nl+4EMoUFxgxJkJtUrB/4SIlKPzT31iWYDd68Efw4V4AMCCXoGsGCy7Poeus8dYugog/ M2qpYePeCmCkMtMQDhknOQ9uJ8FZd1He91DRADZPOPYuQJRzv1SQnWb/kh9EBQQRkIgt g9xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022875; x=1752627675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RwxdkvIH4+jDYN/7Cinl22ra/M1sXM4/dKfSa4ANwTM=; b=b/M1IV0QSpcQ0h5RyNzWpyoxbiNhucuPSUObeJmJJ6fw8iC+tUMFjmcrj0JdJ16FkY hgaBOkMlo5vaVDaj+hXZCgr408Y54z9ZPw30p21eQOx8TnOaZRrOSeRBTRN455ioOeo4 v6Olwnjk2aGCO3n18sKBEv2tDrJ7DNW7KvwDhmuAzKsfXZR4TL5Fqtv1c5KzoOwQYFzv fNxJQ+pbvli/Gk2nGPCG2qGkC0guaxTysEsWPn51c0uqwIPZajZOSeZzlpIqmP8HCZCf HQ/WSx2mKy7ws+o7kZUc9yYF8QTyxRQMJ937Fdq0mOudwaltaUzKUHSglkb1VWAmEJaZ zaAw== X-Forwarded-Encrypted: i=1; AJvYcCUOjYCwRpMPymu/qEzUumhU1dd/iblorWbKbe+OAUMVQNCTqLUyABXPc488qt9+z80c9mUAwC6H8E8=@vger.kernel.org, AJvYcCWJJq28xfpvsTbh8aJ4kzzsf+vX6XG+CqD2bdev8vMl5lTAAilF8jMuiJxU1dDqgbz0lUQJTId82aKzoblM@vger.kernel.org X-Gm-Message-State: AOJu0YyagqbMuerPHXLDWiDqOvH6uuRaJFalGWIIcTJjC8XIIIsTR7qc 4y4R3ZzV7yFoCQFG71zVdTu7XHMtK25hfJiUsCkE4X79n0AjE3Eyi637 X-Gm-Gg: ASbGncvaMDoO9I2xGXkSfxQvABy+3i0uNgzRAapD7ZWNvH60mi2oIOxlUGO/VQW7tJp 0En9W0miAEyufH2WuWG6jS6FcBvgl68ulM6wKEk+2SKQTbPwslCbxqPIv6F3zj6FQK2yEXsDkF2 oxs7tEqozA4t18SdnB+YAxqZ2rlwW/4muu8vJIJkPqec/Rhcm1+KEXRID8vc2Uwfvy3HCJA3tFE mgdT523y2czn+kjncTELiV7ENL4e/U0K+taJBbepLZp/e+4Qr/658oFq+kaZZi4ETMvMK/Yplsm t1y0VRZmNxgtDSkYrkLfmFx5KobiTthQLchYB7FZnQofehOgiaJTWpKISRGOn7QSeb0afAI/gZ7 VWhXJA5Y= X-Google-Smtp-Source: AGHT+IGxOKv9TT+GJA5HkW+nmvLYwYPGlnDvxe6/6+ea2PSeO270tAsemkQN6HvUwL31Go6xbuev9A== X-Received: by 2002:a05:6902:4913:b0:e7d:c8eb:92f4 with SMTP id 3f1490d57ef6-e8b6e0eebe3mr1078373276.22.1752022874731; Tue, 08 Jul 2025 18:01:14 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:01:14 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com, Ravi Shankar Jonnalagadda Subject: [PATCH v4 12/13] mm/damon: Move folio filtering from paddr to ops-common Date: Tue, 8 Jul 2025 19:59:42 -0500 Message-ID: <20250709005952.17776-13-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bijan Tabatabai This patch moves damos_pa_filter_match and the functions it calls to ops-common, renaming it to damos_folio_filter_match. Doing so allows us to share the filtering logic for the vaddr version of the migrate_{hot,cold} schemes. Co-developed-by: Ravi Shankar Jonnalagadda Signed-off-by: Ravi Shankar Jonnalagadda Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- mm/damon/ops-common.c | 150 +++++++++++++++++++++++++++++++++++++++++ mm/damon/ops-common.h | 3 + mm/damon/paddr.c | 153 +----------------------------------------- 3 files changed, 154 insertions(+), 152 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index 918158ef3d99..6a9797d1d7ff 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -141,6 +141,156 @@ int damon_cold_score(struct damon_ctx *c, struct damo= n_region *r, return DAMOS_MAX_SCORE - hotness; } =20 +static bool damon_folio_mkold_one(struct folio *folio, + struct vm_area_struct *vma, unsigned long addr, void *arg) +{ + DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, addr, 0); + + while (page_vma_mapped_walk(&pvmw)) { + addr =3D pvmw.address; + if (pvmw.pte) + damon_ptep_mkold(pvmw.pte, vma, addr); + else + damon_pmdp_mkold(pvmw.pmd, vma, addr); + } + return true; +} + +void damon_folio_mkold(struct folio *folio) +{ + struct rmap_walk_control rwc =3D { + .rmap_one =3D damon_folio_mkold_one, + .anon_lock =3D folio_lock_anon_vma_read, + }; + bool need_lock; + + if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { + folio_set_idle(folio); + return; + } + + need_lock =3D !folio_test_anon(folio) || folio_test_ksm(folio); + if (need_lock && !folio_trylock(folio)) + return; + + rmap_walk(folio, &rwc); + + if (need_lock) + folio_unlock(folio); + +} + +static bool damon_folio_young_one(struct folio *folio, + struct vm_area_struct *vma, unsigned long addr, void *arg) +{ + bool *accessed =3D arg; + DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, addr, 0); + pte_t pte; + + *accessed =3D false; + while (page_vma_mapped_walk(&pvmw)) { + addr =3D pvmw.address; + if (pvmw.pte) { + pte =3D ptep_get(pvmw.pte); + + /* + * PFN swap PTEs, such as device-exclusive ones, that + * actually map pages are "old" from a CPU perspective. + * The MMU notifier takes care of any device aspects. + */ + *accessed =3D (pte_present(pte) && pte_young(pte)) || + !folio_test_idle(folio) || + mmu_notifier_test_young(vma->vm_mm, addr); + } else { +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + *accessed =3D pmd_young(pmdp_get(pvmw.pmd)) || + !folio_test_idle(folio) || + mmu_notifier_test_young(vma->vm_mm, addr); +#else + WARN_ON_ONCE(1); +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + } + if (*accessed) { + page_vma_mapped_walk_done(&pvmw); + break; + } + } + + /* If accessed, stop walking */ + return *accessed =3D=3D false; +} + +bool damon_folio_young(struct folio *folio) +{ + bool accessed =3D false; + struct rmap_walk_control rwc =3D { + .arg =3D &accessed, + .rmap_one =3D damon_folio_young_one, + .anon_lock =3D folio_lock_anon_vma_read, + }; + bool need_lock; + + if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { + if (folio_test_idle(folio)) + return false; + else + return true; + } + + need_lock =3D !folio_test_anon(folio) || folio_test_ksm(folio); + if (need_lock && !folio_trylock(folio)) + return false; + + rmap_walk(folio, &rwc); + + if (need_lock) + folio_unlock(folio); + + return accessed; +} + +bool damos_folio_filter_match(struct damos_filter *filter, struct folio *f= olio) +{ + bool matched =3D false; + struct mem_cgroup *memcg; + size_t folio_sz; + + switch (filter->type) { + case DAMOS_FILTER_TYPE_ANON: + matched =3D folio_test_anon(folio); + break; + case DAMOS_FILTER_TYPE_ACTIVE: + matched =3D folio_test_active(folio); + break; + case DAMOS_FILTER_TYPE_MEMCG: + rcu_read_lock(); + memcg =3D folio_memcg_check(folio); + if (!memcg) + matched =3D false; + else + matched =3D filter->memcg_id =3D=3D mem_cgroup_id(memcg); + rcu_read_unlock(); + break; + case DAMOS_FILTER_TYPE_YOUNG: + matched =3D damon_folio_young(folio); + if (matched) + damon_folio_mkold(folio); + break; + case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE: + folio_sz =3D folio_size(folio); + matched =3D filter->sz_range.min <=3D folio_sz && + folio_sz <=3D filter->sz_range.max; + break; + case DAMOS_FILTER_TYPE_UNMAPPED: + matched =3D !folio_mapped(folio) || !folio_raw_mapping(folio); + break; + default: + break; + } + + return matched =3D=3D filter->matching; +} + static unsigned int __damon_migrate_folio_list( struct list_head *migrate_folios, struct pglist_data *pgdat, int target_nid) diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h index 54209a7e70e6..61ad54aaf256 100644 --- a/mm/damon/ops-common.h +++ b/mm/damon/ops-common.h @@ -11,10 +11,13 @@ struct folio *damon_get_folio(unsigned long pfn); =20 void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned lon= g addr); void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned lon= g addr); +void damon_folio_mkold(struct folio *folio); +bool damon_folio_young(struct folio *folio); =20 int damon_cold_score(struct damon_ctx *c, struct damon_region *r, struct damos *s); int damon_hot_score(struct damon_ctx *c, struct damon_region *r, struct damos *s); =20 +bool damos_folio_filter_match(struct damos_filter *filter, struct folio *f= olio); unsigned long damon_migrate_pages(struct list_head *folio_list, int target= _nid); diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 48e3e6fed636..53a55c5114fb 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -18,45 +18,6 @@ #include "../internal.h" #include "ops-common.h" =20 -static bool damon_folio_mkold_one(struct folio *folio, - struct vm_area_struct *vma, unsigned long addr, void *arg) -{ - DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, addr, 0); - - while (page_vma_mapped_walk(&pvmw)) { - addr =3D pvmw.address; - if (pvmw.pte) - damon_ptep_mkold(pvmw.pte, vma, addr); - else - damon_pmdp_mkold(pvmw.pmd, vma, addr); - } - return true; -} - -static void damon_folio_mkold(struct folio *folio) -{ - struct rmap_walk_control rwc =3D { - .rmap_one =3D damon_folio_mkold_one, - .anon_lock =3D folio_lock_anon_vma_read, - }; - bool need_lock; - - if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { - folio_set_idle(folio); - return; - } - - need_lock =3D !folio_test_anon(folio) || folio_test_ksm(folio); - if (need_lock && !folio_trylock(folio)) - return; - - rmap_walk(folio, &rwc); - - if (need_lock) - folio_unlock(folio); - -} - static void damon_pa_mkold(unsigned long paddr) { struct folio *folio =3D damon_get_folio(PHYS_PFN(paddr)); @@ -86,75 +47,6 @@ static void damon_pa_prepare_access_checks(struct damon_= ctx *ctx) } } =20 -static bool damon_folio_young_one(struct folio *folio, - struct vm_area_struct *vma, unsigned long addr, void *arg) -{ - bool *accessed =3D arg; - DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, addr, 0); - pte_t pte; - - *accessed =3D false; - while (page_vma_mapped_walk(&pvmw)) { - addr =3D pvmw.address; - if (pvmw.pte) { - pte =3D ptep_get(pvmw.pte); - - /* - * PFN swap PTEs, such as device-exclusive ones, that - * actually map pages are "old" from a CPU perspective. - * The MMU notifier takes care of any device aspects. - */ - *accessed =3D (pte_present(pte) && pte_young(pte)) || - !folio_test_idle(folio) || - mmu_notifier_test_young(vma->vm_mm, addr); - } else { -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - *accessed =3D pmd_young(pmdp_get(pvmw.pmd)) || - !folio_test_idle(folio) || - mmu_notifier_test_young(vma->vm_mm, addr); -#else - WARN_ON_ONCE(1); -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ - } - if (*accessed) { - page_vma_mapped_walk_done(&pvmw); - break; - } - } - - /* If accessed, stop walking */ - return *accessed =3D=3D false; -} - -static bool damon_folio_young(struct folio *folio) -{ - bool accessed =3D false; - struct rmap_walk_control rwc =3D { - .arg =3D &accessed, - .rmap_one =3D damon_folio_young_one, - .anon_lock =3D folio_lock_anon_vma_read, - }; - bool need_lock; - - if (!folio_mapped(folio) || !folio_raw_mapping(folio)) { - if (folio_test_idle(folio)) - return false; - else - return true; - } - - need_lock =3D !folio_test_anon(folio) || folio_test_ksm(folio); - if (need_lock && !folio_trylock(folio)) - return false; - - rmap_walk(folio, &rwc); - - if (need_lock) - folio_unlock(folio); - - return accessed; -} - static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz) { struct folio *folio =3D damon_get_folio(PHYS_PFN(paddr)); @@ -205,49 +97,6 @@ static unsigned int damon_pa_check_accesses(struct damo= n_ctx *ctx) return max_nr_accesses; } =20 -static bool damos_pa_filter_match(struct damos_filter *filter, - struct folio *folio) -{ - bool matched =3D false; - struct mem_cgroup *memcg; - size_t folio_sz; - - switch (filter->type) { - case DAMOS_FILTER_TYPE_ANON: - matched =3D folio_test_anon(folio); - break; - case DAMOS_FILTER_TYPE_ACTIVE: - matched =3D folio_test_active(folio); - break; - case DAMOS_FILTER_TYPE_MEMCG: - rcu_read_lock(); - memcg =3D folio_memcg_check(folio); - if (!memcg) - matched =3D false; - else - matched =3D filter->memcg_id =3D=3D mem_cgroup_id(memcg); - rcu_read_unlock(); - break; - case DAMOS_FILTER_TYPE_YOUNG: - matched =3D damon_folio_young(folio); - if (matched) - damon_folio_mkold(folio); - break; - case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE: - folio_sz =3D folio_size(folio); - matched =3D filter->sz_range.min <=3D folio_sz && - folio_sz <=3D filter->sz_range.max; - break; - case DAMOS_FILTER_TYPE_UNMAPPED: - matched =3D !folio_mapped(folio) || !folio_raw_mapping(folio); - break; - default: - break; - } - - return matched =3D=3D filter->matching; -} - /* * damos_pa_filter_out - Return true if the page should be filtered out. */ @@ -259,7 +108,7 @@ static bool damos_pa_filter_out(struct damos *scheme, s= truct folio *folio) return false; =20 damos_for_each_ops_filter(filter, scheme) { - if (damos_pa_filter_match(filter, folio)) + if (damos_folio_filter_match(filter, folio)) return !filter->allow; } return scheme->ops_filters_default_reject; --=20 2.43.0 From nobody Tue Oct 7 14:46:49 2025 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7F2F19D07A; Wed, 9 Jul 2025 01:01:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022886; cv=none; b=fiWHwQkEdx8h1Q0j1fzbgR38uUVvdrJr663wHwUWqC6c5XTkAQ8CLBv1IcGSTp5M23KODQLidSxhFIn49sf7R4PmrNdztI/mPj7bZWQuygxzBCG64sdGpmkrUpi6zAyCuWJe0W0JFO8fqOX47t+ZC9hMlHcxQoq/y/RbPvxRLKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752022886; c=relaxed/simple; bh=e+T1fhlgewUCMGkVoR3tTxRjhF3Cc5drfaDrOO75184=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CQ1n+o37j6qxxPLZST6wlbe/d3Eqvx+4OmeYbmGEun2UOxB1HrBRr2BKkeV4yeAyiJBf/DPraT4SyZV/xR2cRXXoQtf3DZUV/dtDyCjvR3mn4+DD80YjvaiKK6EC9R/v1u6953rG8YrRrdfoDEvZ8HhpJeXxsFIsytCKsav3Xas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PRXAZ7Yt; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PRXAZ7Yt" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e81a7d90835so4149844276.1; Tue, 08 Jul 2025 18:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752022883; x=1752627683; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IZC5q8LZ5pc6UFxmCdVHkQ+xcSY0x1BRxLFRLW7GuXk=; b=PRXAZ7Yt1WxN7Nw3k6zuzoLgCuCqPWEtw0WdOIov03JSL6YQxCbUa+LlX+22rGdsTK 4P+TjdpQrVEhq/gL+WNldSaWOdjjJMa79nNJ2aHh/sul5J7z4BqerHklY08PdybwVLN3 7k9+c/fS2PJtTict5IIrK/d5fXTBpfed42FgnlLIyEkUFd/PovwYKfGa4i503b196/rF RVcJt7SQXGJnzqZghtXAKKd4gFNvQ5nmgDLi9Wi4vWAFtnlzzIczKiSJ6urYkpcLlaT2 4SCsgirYHSDE/+2PHuJ9FDcelyh7BgQmLv/gl3SB1Oudqip4xtdeYst39ABgAiwZogr5 MKHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752022883; x=1752627683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IZC5q8LZ5pc6UFxmCdVHkQ+xcSY0x1BRxLFRLW7GuXk=; b=ANCNM0dcIppFExQzXfSAtXsgVTjKUbmMwg1YI+DHUAG5T5uIRPV6JDuiD01UrWsy61 Q1n700wlHAq7pYCeNku29L5CgGPJAcPf33NdNF7afnYMre18KP0nE1ptirIlf9YEbYZ2 bn8zhk3CVVm0ZX0UyFRrBsbHLNVhkvgcZRzZxP9OGxYL7/8s9ZgH2ljIye4SdCgdp5Wj Jr9YYPZr2YjHxjTCfSeUrMOLxelCOJ22WkJMvF9zwKl8WWbNhPxlb2BroWLVO8CKkDv5 Zl8j2UcvLFagg+ITOT3xVqu62PYxzGoT/aSY5BhGf8iw2k8+dnSYoKPnCO7qmKhx/78u Fx0Q== X-Forwarded-Encrypted: i=1; AJvYcCUeomKF8sIgfVDrKxTAJx9pYDb1y72+NNG1nkupbByLsH9Pvtg+7bjivOPOGCuKNMSOgDCLNJPLEqsb7gZs@vger.kernel.org, AJvYcCVQlUGFuvm1EMPnDnj1z/I2BZnLyWmnOygdzaVSgbjcqIRIOiGRwluxHRf1z+CGrpSF6Nwdn8REv5w=@vger.kernel.org X-Gm-Message-State: AOJu0YzQRhVf3NSinZo0TlaGPO9bviia0RDp6wivW8lIE5Xscy82w3Jj ydgF1BgJ0pAQXQnp/kPzhrpDk7aaQldx4xmnR6dS8RSy2Lzz8PDGWDbt X-Gm-Gg: ASbGncu7mBra8qguwcNdCuT4cfnCE5dUDzA4kcE4GQ6A/cBuUSatlz2jUFWZG+DNu7b 9yeLlvz5J4Z8AhXnJ8hn15/Nlex+iPKHvBOczEEyxoif1BPuleZ2eCwpDmm0XKc1YbQlEnJHB9A v2LRP2o6h7pVdrSITwwOA1SInGqMkXot3/iACNj+9tZVkueYH1aFgJyx8wmbtr8AObmh37x3FWS ZpOqNlvhyVA9kLitO32pn40X5+XUOM9i9UCcp/vNXJ/yP2EriZvfkA7Qs6ifG/wQiu8xESJlnqI zUh8JOTD1NndjFpFLHG0dHzlbekU0JdEZPtvtgEp4b2ick2d3JosNso63C0eWSHsNqPkZhogl/K IoF34m2A= X-Google-Smtp-Source: AGHT+IGBVL08fCEmXie0BqOThtC53srTZke6UZuD3rNGM0GVPqcqyBQP9Gr6apPaTrB4/7lyEi3sSA== X-Received: by 2002:a05:6902:2609:b0:e8b:444a:9298 with SMTP id 3f1490d57ef6-e8b6e0de728mr1064674276.5.1752022883567; Tue, 08 Jul 2025 18:01:23 -0700 (PDT) Received: from bijan-laptop.attlocal.net ([2600:1700:680e:c000:235f:99bb:f36e:a060]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e899c43ed8asm3656043276.26.2025.07.08.18.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 18:01:23 -0700 (PDT) From: Bijan Tabatabai To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijantabatab@micron.com, venkataravis@micron.com, emirakhur@micron.com, vtavarespetr@micron.com, ajayjoshi@micron.com, Ravi Shankar Jonnalagadda Subject: [PATCH v4 13/13] mm/damon/vaddr: Apply filters in migrate_{hot/cold} Date: Tue, 8 Jul 2025 19:59:43 -0500 Message-ID: <20250709005952.17776-14-bijan311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com> References: <20250709005952.17776-1-bijan311@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bijan Tabatabai The paddr versions of migrate_{hot/cold} filter out folios from migration based on the scheme's filters. This patch does the same for the vaddr versions of those schemes. The filtering code is mostly the same for the paddr and vaddr versions. The exception is the young filter. paddr determines if a page is young by doing a folio rmap walk to find the page table entries corresponding to the folio. However, vaddr schemes have easier access to the page tables, so we add some logic to avoid the extra work. Co-developed-by: Ravi Shankar Jonnalagadda Signed-off-by: Ravi Shankar Jonnalagadda Signed-off-by: Bijan Tabatabai Reviewed-by: SeongJae Park --- mm/damon/vaddr.c | 69 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 47d5f33f89c8..7f5dc9c221a0 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -611,9 +611,60 @@ static unsigned int damon_va_check_accesses(struct dam= on_ctx *ctx) return max_nr_accesses; } =20 +static bool damos_va_filter_young_match(struct damos_filter *filter, + struct folio *folio, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, pmd_t *pmdp) +{ + bool young =3D false; + + if (ptep) + young =3D pte_young(ptep_get(ptep)); + else if (pmdp) + young =3D pmd_young(pmdp_get(pmdp)); + + young =3D young || !folio_test_idle(folio) || + mmu_notifier_test_young(vma->vm_mm, addr); + + if (young && ptep) + damon_ptep_mkold(ptep, vma, addr); + else if (young && pmdp) + damon_pmdp_mkold(pmdp, vma, addr); + + return young =3D=3D filter->matching; +} + +static bool damos_va_filter_out(struct damos *scheme, struct folio *folio, + struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, pmd_t *pmdp) +{ + struct damos_filter *filter; + bool matched; + + if (scheme->core_filters_allowed) + return false; + + damos_for_each_ops_filter(filter, scheme) { + /* + * damos_folio_filter_match checks the young filter by doing an + * rmap on the folio to find its page table. However, being the + * vaddr scheme, we have direct access to the page tables, so + * use that instead. + */ + if (filter->type =3D=3D DAMOS_FILTER_TYPE_YOUNG) + matched =3D damos_va_filter_young_match(filter, folio, + vma, addr, ptep, pmdp); + else + matched =3D damos_folio_filter_match(filter, folio); + + if (matched) + return !filter->allow; + } + return scheme->ops_filters_default_reject; +} + struct damos_va_migrate_private { struct list_head *migration_lists; - struct damos_migrate_dests *dests; + struct damos *scheme; }; =20 /* @@ -673,7 +724,8 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsig= ned long addr, { struct damos_va_migrate_private *priv =3D walk->private; struct list_head *migration_lists =3D priv->migration_lists; - struct damos_migrate_dests *dests =3D priv->dests; + struct damos *s =3D priv->scheme; + struct damos_migrate_dests *dests =3D &s->migrate_dests; struct folio *folio; spinlock_t *ptl; pmd_t pmde; @@ -691,9 +743,13 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsi= gned long addr, if (!folio) goto unlock; =20 + if (damos_va_filter_out(s, folio, walk->vma, addr, NULL, pmd)) + goto put_folio; + damos_va_migrate_dests_add(folio, walk->vma, addr, dests, migration_lists); =20 +put_folio: folio_put(folio); unlock: spin_unlock(ptl); @@ -708,7 +764,8 @@ static int damos_va_migrate_pte_entry(pte_t *pte, unsig= ned long addr, { struct damos_va_migrate_private *priv =3D walk->private; struct list_head *migration_lists =3D priv->migration_lists; - struct damos_migrate_dests *dests =3D priv->dests; + struct damos *s =3D priv->scheme; + struct damos_migrate_dests *dests =3D &s->migrate_dests; struct folio *folio; pte_t ptent; =20 @@ -720,9 +777,13 @@ static int damos_va_migrate_pte_entry(pte_t *pte, unsi= gned long addr, if (!folio) return 0; =20 + if (damos_va_filter_out(s, folio, walk->vma, addr, pte, NULL)) + goto put_folio; + damos_va_migrate_dests_add(folio, walk->vma, addr, dests, migration_lists); =20 +put_folio: folio_put(folio); return 0; } @@ -790,7 +851,7 @@ static unsigned long damos_va_migrate(struct damon_targ= et *target, =20 use_target_nid =3D dests->nr_dests =3D=3D 0; nr_dests =3D use_target_nid ? 1 : dests->nr_dests; - priv.dests =3D dests; + priv.scheme =3D s; priv.migration_lists =3D kmalloc_array(nr_dests, sizeof(*priv.migration_lists), GFP_KERNEL); if (!priv.migration_lists) --=20 2.43.0