From nobody Fri Oct 3 23:09:40 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87F992F6166 for ; Fri, 22 Aug 2025 09:48:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856091; cv=none; b=dEc/nLmemoS/eNAYrtvBPD4npkHPmXXj8CpmdbsjuZe/Iov7FulyZId4OJfMhKUy6woag8MxOh9Y7vqeucYbOtxFJpkUDrjMLyxYn8dk4fnFrDgeRLjXAEEScVA1lnjCrFoaw2gnvu77reJDb+5Vwim5lBRJimSD928WtfLw+wA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856091; c=relaxed/simple; bh=5PapXx7OfgHNeQJ1skQxmL0Z3wBUyEShYfI765jZ9TU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r6Pz/+jzsQy4c0vsMX1xHCd2uf4UVae57vkPX8PTy+qjrsXHwatGSgXrJStD0rVjvvPE6znssM2l/YK0J7ifj8uc4kES35qiLTVoryrSqf5Iptlz37XnoiPFGp0kaHLbplK4YEZvsweWDMP5ttGbRXLkcugBO9v2fW40DoSP534= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4c7Zxt4M4fzPqM9; Fri, 22 Aug 2025 17:43:30 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 8DC7F180080; Fri, 22 Aug 2025 17:48:06 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:05 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 01/11] mm/damon/core: add damon_ctx->addr_unit Date: Fri, 22 Aug 2025 17:34:09 +0800 Message-ID: <20250822093420.2103803-2-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park In some cases, some of the real address that handled by the underlying operations set cannot be handled by DAMON since it uses only 'unsinged long' as the address type. Using DAMON for physical address space monitoring of 32 bit ARM devices with large physical address extension (LPAE) is one example[1]. Add a parameter name 'addr_unit' to core layer to help such cases. DAMON core API callers can set it as the scale factor that will be used by the operations set for translating the core layer's addresses to the real address by multiplying the parameter value to the core layer address. Support of the parameter is up to each operations set layer. The support from the physical address space operations set (paddr) will be added with following commits. [1] https://lore.kernel.org/20250408075553.959388-1-zuoze1@huawei.com Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- include/linux/damon.h | 3 ++- mm/damon/core.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index d01bfee80bd6..6fa52f7495d9 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -746,7 +746,7 @@ struct damon_attrs { * Accesses to other fields must be protected by themselves. * * @ops: Set of monitoring operations for given use cases. - * + * @addr_unit: Scale factor for core to ops address conversion. * @adaptive_targets: Head of monitoring targets (&damon_target) list. * @schemes: Head of schemes (&damos) list. */ @@ -788,6 +788,7 @@ struct damon_ctx { struct mutex kdamond_lock; =20 struct damon_operations ops; + unsigned long addr_unit; =20 struct list_head adaptive_targets; struct list_head schemes; diff --git a/mm/damon/core.c b/mm/damon/core.c index cb41fddca78c..8f8aa84953ac 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -544,6 +544,8 @@ struct damon_ctx *damon_new_ctx(void) ctx->attrs.min_nr_regions =3D 10; ctx->attrs.max_nr_regions =3D 1000; =20 + ctx->addr_unit =3D 1; + INIT_LIST_HEAD(&ctx->adaptive_targets); INIT_LIST_HEAD(&ctx->schemes); =20 @@ -1245,6 +1247,7 @@ int damon_commit_ctx(struct damon_ctx *dst, struct da= mon_ctx *src) return err; } dst->ops =3D src->ops; + dst->addr_unit =3D src->addr_unit; =20 return 0; } --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 874A62EE5FE for ; Fri, 22 Aug 2025 09:48:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856092; cv=none; b=BhhnVIcNW8PHO3dIQeJS9HUbyRJkRvPr+6flxwAppCYnrVrTbWPUBK/p0GJuVlkfqtmtCl5kS7AUEUVb8TlddZuDU9bpB/xyRTazkTdgVtleHSO6XZ+CpfHA7362F0vJsLqJExj+cr6d6V20ykc7FLFKvYWuS4SphizwdyhZwq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856092; c=relaxed/simple; bh=Fgut11h8yU4yWyJQWtddUDJ/FKEdzel6IfB24RRD29o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cmWEOglQoDVAVfyVeeW4md4I/LLRomhuTZDH146pH8LofwWAyiyugQP3th6VXEQ/dqFs6MzZtsM0ioZrBoFMSw8a0CkCaSMSmj3vcFbLCBTsnROaUT7BbHncDYvzqxkk9TAdyEEqyVZx3ip9LniwL0HfgK48CZBRlnFAFfaK220= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4c7Zxv1mnlzPnbw; Fri, 22 Aug 2025 17:43:31 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 2DC64180495; Fri, 22 Aug 2025 17:48:07 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:06 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 02/11] mm/damon/paddr: support addr_unit for access monitoring Date: Fri, 22 Aug 2025 17:34:10 +0800 Message-ID: <20250822093420.2103803-3-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Add support of addr_unit paramer for access monitoing operations of paddr. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- mm/damon/paddr.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 0b67d9321460..d497373c2bd2 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -18,7 +18,13 @@ #include "../internal.h" #include "ops-common.h" =20 -static void damon_pa_mkold(unsigned long paddr) +static phys_addr_t damon_pa_phys_addr( + unsigned long addr, unsigned long addr_unit) +{ + return (phys_addr_t)addr * addr_unit; +} + +static void damon_pa_mkold(phys_addr_t paddr) { struct folio *folio =3D damon_get_folio(PHYS_PFN(paddr)); =20 @@ -29,11 +35,12 @@ static void damon_pa_mkold(unsigned long paddr) folio_put(folio); } =20 -static void __damon_pa_prepare_access_check(struct damon_region *r) +static void __damon_pa_prepare_access_check(struct damon_region *r, + unsigned long addr_unit) { r->sampling_addr =3D damon_rand(r->ar.start, r->ar.end); =20 - damon_pa_mkold(r->sampling_addr); + damon_pa_mkold(damon_pa_phys_addr(r->sampling_addr, addr_unit)); } =20 static void damon_pa_prepare_access_checks(struct damon_ctx *ctx) @@ -43,11 +50,11 @@ static void damon_pa_prepare_access_checks(struct damon= _ctx *ctx) =20 damon_for_each_target(t, ctx) { damon_for_each_region(r, t) - __damon_pa_prepare_access_check(r); + __damon_pa_prepare_access_check(r, ctx->addr_unit); } } =20 -static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz) +static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz) { struct folio *folio =3D damon_get_folio(PHYS_PFN(paddr)); bool accessed; @@ -62,23 +69,25 @@ static bool damon_pa_young(unsigned long paddr, unsigne= d long *folio_sz) } =20 static void __damon_pa_check_access(struct damon_region *r, - struct damon_attrs *attrs) + struct damon_attrs *attrs, unsigned long addr_unit) { - static unsigned long last_addr; + static phys_addr_t last_addr; static unsigned long last_folio_sz =3D PAGE_SIZE; static bool last_accessed; + phys_addr_t sampling_addr =3D damon_pa_phys_addr( + r->sampling_addr, addr_unit); =20 /* If the region is in the last checked page, reuse the result */ if (ALIGN_DOWN(last_addr, last_folio_sz) =3D=3D - ALIGN_DOWN(r->sampling_addr, last_folio_sz)) { + ALIGN_DOWN(sampling_addr, last_folio_sz)) { damon_update_region_access_rate(r, last_accessed, attrs); return; } =20 - last_accessed =3D damon_pa_young(r->sampling_addr, &last_folio_sz); + last_accessed =3D damon_pa_young(sampling_addr, &last_folio_sz); damon_update_region_access_rate(r, last_accessed, attrs); =20 - last_addr =3D r->sampling_addr; + last_addr =3D sampling_addr; } =20 static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) @@ -89,7 +98,8 @@ static unsigned int damon_pa_check_accesses(struct damon_= ctx *ctx) =20 damon_for_each_target(t, ctx) { damon_for_each_region(r, t) { - __damon_pa_check_access(r, &ctx->attrs); + __damon_pa_check_access( + r, &ctx->attrs, ctx->addr_unit); max_nr_accesses =3D max(r->nr_accesses, max_nr_accesses); } } --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C95982F618B for ; Fri, 22 Aug 2025 09:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856094; cv=none; b=n76blagDVntOwxV8sCkDeoB7Mpr/PwN0zsMPMMj+52eaPytCHC8yr+iJi9HpBmRm+bB1/+0FdgFqvWLc4RLtMGP9TJSd9XFL1qUSkQX5sOcSgoGmwym1pKWvJwykjd18wprlSI8a+vVzJoyo4OWYQkcE2q3aHXmBRfeaueLReRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856094; c=relaxed/simple; bh=EGiAcJ2uOIxk3qhNXlY6rL1YgjYX5YeT4zqc2Shw8D4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KPOcg0ZhN/Bt0X4Es63Jsvr2T2D5oz1rHuRsM043BK5nmvtpZ5IJ3Rfi0TkVi2ZswiSnz7N2Cd49AkzCEm+LerbEq5XgJqBJA2yVF+TVwvBU4UfSyqe/Z2YCIyP4PxuVyBaxmry7I4WGsPw9GRXbOCKfczmq2efdym89u65jCCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c7Zz36z9kz13NH4; Fri, 22 Aug 2025 17:44:31 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id CB43A180495; Fri, 22 Aug 2025 17:48:07 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:07 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 03/11] mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT Date: Fri, 22 Aug 2025 17:34:11 +0800 Message-ID: <20250822093420.2103803-4-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Add support of addr_unit for DAMOS_PAGEOUT action handling from the DAMOS operation implementation for the physical address space. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park Reported-by: kernel test robot --- mm/damon/paddr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index d497373c2bd2..826c2064dbfd 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -135,10 +135,11 @@ static bool damon_pa_invalid_damos_folio(struct folio= *folio, struct damos *s) return false; } =20 -static unsigned long damon_pa_pageout(struct damon_region *r, struct damos= *s, +static unsigned long damon_pa_pageout(struct damon_region *r, + unsigned long addr_unit, struct damos *s, unsigned long *sz_filter_passed) { - unsigned long addr, applied; + phys_addr_t addr, applied; LIST_HEAD(folio_list); bool install_young_filter =3D true; struct damos_filter *filter; @@ -159,8 +160,8 @@ static unsigned long damon_pa_pageout(struct damon_regi= on *r, struct damos *s, damos_add_filter(s, filter); } =20 - addr =3D r->ar.start; - while (addr < r->ar.end) { + addr =3D damon_pa_phys_addr(r->ar.start, addr_unit); + while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) { folio =3D damon_get_folio(PHYS_PFN(addr)); if (damon_pa_invalid_damos_folio(folio, s)) { addr +=3D PAGE_SIZE; @@ -170,7 +171,7 @@ static unsigned long damon_pa_pageout(struct damon_regi= on *r, struct damos *s, if (damos_pa_filter_out(s, folio)) goto put_folio; else - *sz_filter_passed +=3D folio_size(folio); + *sz_filter_passed +=3D folio_size(folio) / addr_unit; =20 folio_clear_referenced(folio); folio_test_clear_young(folio); @@ -189,7 +190,7 @@ static unsigned long damon_pa_pageout(struct damon_regi= on *r, struct damos *s, applied =3D reclaim_pages(&folio_list); cond_resched(); s->last_applied =3D folio; - return applied * PAGE_SIZE; + return applied * PAGE_SIZE / addr_unit; } =20 static inline unsigned long damon_pa_mark_accessed_or_deactivate( @@ -302,9 +303,11 @@ static unsigned long damon_pa_apply_scheme(struct damo= n_ctx *ctx, struct damon_target *t, struct damon_region *r, struct damos *scheme, unsigned long *sz_filter_passed) { + unsigned long aunit =3D ctx->addr_unit; + switch (scheme->action) { case DAMOS_PAGEOUT: - return damon_pa_pageout(r, scheme, sz_filter_passed); + return damon_pa_pageout(r, aunit, scheme, sz_filter_passed); case DAMOS_LRU_PRIO: return damon_pa_mark_accessed(r, scheme, sz_filter_passed); case DAMOS_LRU_DEPRIO: --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E644E2F6175 for ; Fri, 22 Aug 2025 09:48:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856093; cv=none; b=iGM5D+y93k1WMV5dSSBU8IPrH43+DR+3SoaoLIW+e8Bx+J+vfjBNJ0Mcgl2YsLgDp4VNWGod484ZDilWuhlECGL9CORoPhpC7ZaqPfbbd2rIB4TcC/Y2qgGRYYWksEiBk6nxSVPzICPonMJQZ9bBYYG1r99Va8MJmptBPeYFVZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856093; c=relaxed/simple; bh=zMZPKi7QCME8V+9xFzAIVhRyzvh6qYIF/C5rCFB1ZiI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=geVIbRCDRqk0N58hGI5dvuWGvJWOrtZ1KItksvxhLIYBxaH+40d+SF8oW4JK5mfxB1qsBR2RNniF2wCustIS5JNHlvrc/UQt1MIoV46NbHzAh8vCptjYCEgj6koYPm0veZ1XqdiQTlPVMue1ngFGREhGfDC6oKBfiQ8DYb3Jstg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4c7b4V0gxvz27jDb; Fri, 22 Aug 2025 17:49:14 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 63946140109; Fri, 22 Aug 2025 17:48:08 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:07 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 04/11] mm/damon/paddr: support addr_unit for DAMOS_LRU_[DE]PRIO Date: Fri, 22 Aug 2025 17:34:12 +0800 Message-ID: <20250822093420.2103803-5-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Add support of addr_unit for DAMOS_LRU_PRIO and DAMOS_LRU_DEPRIO action handling from the DAMOS operation implementation for the physical address space. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- mm/damon/paddr.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 826c2064dbfd..ed71dd0bf80e 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -194,14 +194,15 @@ static unsigned long damon_pa_pageout(struct damon_re= gion *r, } =20 static inline unsigned long damon_pa_mark_accessed_or_deactivate( - struct damon_region *r, struct damos *s, bool mark_accessed, + struct damon_region *r, unsigned long addr_unit, + struct damos *s, bool mark_accessed, unsigned long *sz_filter_passed) { - unsigned long addr, applied =3D 0; + phys_addr_t addr, applied =3D 0; struct folio *folio; =20 - addr =3D r->ar.start; - while (addr < r->ar.end) { + addr =3D damon_pa_phys_addr(r->ar.start, addr_unit); + while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) { folio =3D damon_get_folio(PHYS_PFN(addr)); if (damon_pa_invalid_damos_folio(folio, s)) { addr +=3D PAGE_SIZE; @@ -211,7 +212,7 @@ static inline unsigned long damon_pa_mark_accessed_or_d= eactivate( if (damos_pa_filter_out(s, folio)) goto put_folio; else - *sz_filter_passed +=3D folio_size(folio); + *sz_filter_passed +=3D folio_size(folio) / addr_unit; =20 if (mark_accessed) folio_mark_accessed(folio); @@ -223,20 +224,22 @@ static inline unsigned long damon_pa_mark_accessed_or= _deactivate( folio_put(folio); } s->last_applied =3D folio; - return applied * PAGE_SIZE; + return applied * PAGE_SIZE / addr_unit; } =20 static unsigned long damon_pa_mark_accessed(struct damon_region *r, - struct damos *s, unsigned long *sz_filter_passed) + unsigned long addr_unit, struct damos *s, + unsigned long *sz_filter_passed) { - return damon_pa_mark_accessed_or_deactivate(r, s, true, + return damon_pa_mark_accessed_or_deactivate(r, addr_unit, s, true, sz_filter_passed); } =20 static unsigned long damon_pa_deactivate_pages(struct damon_region *r, - struct damos *s, unsigned long *sz_filter_passed) + unsigned long addr_unit, struct damos *s, + unsigned long *sz_filter_passed) { - return damon_pa_mark_accessed_or_deactivate(r, s, false, + return damon_pa_mark_accessed_or_deactivate(r, addr_unit, s, false, sz_filter_passed); } =20 @@ -309,9 +312,11 @@ static unsigned long damon_pa_apply_scheme(struct damo= n_ctx *ctx, case DAMOS_PAGEOUT: return damon_pa_pageout(r, aunit, scheme, sz_filter_passed); case DAMOS_LRU_PRIO: - return damon_pa_mark_accessed(r, scheme, sz_filter_passed); + return damon_pa_mark_accessed(r, aunit, scheme, + sz_filter_passed); case DAMOS_LRU_DEPRIO: - return damon_pa_deactivate_pages(r, scheme, sz_filter_passed); + return damon_pa_deactivate_pages(r, aunit, scheme, + sz_filter_passed); case DAMOS_MIGRATE_HOT: case DAMOS_MIGRATE_COLD: return damon_pa_migrate(r, scheme, sz_filter_passed); --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDEB72F6184 for ; Fri, 22 Aug 2025 09:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856096; cv=none; b=CXO4Wd8oqTSFYkkQEt/qK16hr7fgvynZynMF263QnS6xtauXtehGO9yhk4RCcNjtPLVQOjF2S7pGXcjUBmWkpjimsFHKSdCk1DDjgZ0nXSsBIn5MjGZudKAp5vDN3ccudZp3a0IDQCr2RRI94amQoI63Z8WT1nN9da8kFhB2Ao8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856096; c=relaxed/simple; bh=ke/Ra6JvD61g62N7erN+vywbrquxQTLnIWafETq6+AE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cEah6ozjcxgLwYJ3KkY33lc9K88GPCEmyVicYS/i6K8Spgdl/NQONAkEP0rdY+m7lIeu3mNthjrD+loZSsq6pccf9ZbKgB4s9WIXbXVNoJVVo6/jzkl1WzmkLARYheV5c2AktCbDyRZRxaBukirJPOWN+5Ssdm++8k9mDe4vqa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c7Zzv022Qz1R91N; Fri, 22 Aug 2025 17:45:15 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 01A81140109; Fri, 22 Aug 2025 17:48:09 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:08 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 05/11] mm/damon/paddr: support addr_unit for MIGRATE_{HOT,COLD} Date: Fri, 22 Aug 2025 17:34:13 +0800 Message-ID: <20250822093420.2103803-6-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Add support of addr_unit for DAMOS_MIGRATE_HOT and DAMOS_MIGRATE_COLD action handling from the DAMOS operation implementation for the physical address space. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- mm/damon/paddr.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index ed71dd0bf80e..0305e59818da 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -243,15 +243,16 @@ static unsigned long damon_pa_deactivate_pages(struct= damon_region *r, sz_filter_passed); } =20 -static unsigned long damon_pa_migrate(struct damon_region *r, struct damos= *s, +static unsigned long damon_pa_migrate(struct damon_region *r, + unsigned long addr_unit, struct damos *s, unsigned long *sz_filter_passed) { - unsigned long addr, applied; + phys_addr_t addr, applied; LIST_HEAD(folio_list); struct folio *folio; =20 - addr =3D r->ar.start; - while (addr < r->ar.end) { + addr =3D damon_pa_phys_addr(r->ar.start, addr_unit); + while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) { folio =3D damon_get_folio(PHYS_PFN(addr)); if (damon_pa_invalid_damos_folio(folio, s)) { addr +=3D PAGE_SIZE; @@ -261,7 +262,7 @@ static unsigned long damon_pa_migrate(struct damon_regi= on *r, struct damos *s, if (damos_pa_filter_out(s, folio)) goto put_folio; else - *sz_filter_passed +=3D folio_size(folio); + *sz_filter_passed +=3D folio_size(folio) / addr_unit; =20 if (!folio_isolate_lru(folio)) goto put_folio; @@ -273,7 +274,7 @@ static unsigned long damon_pa_migrate(struct damon_regi= on *r, struct damos *s, applied =3D damon_migrate_pages(&folio_list, s->target_nid); cond_resched(); s->last_applied =3D folio; - return applied * PAGE_SIZE; + return applied * PAGE_SIZE / addr_unit; } =20 static unsigned long damon_pa_stat(struct damon_region *r, struct damos *s, @@ -319,7 +320,7 @@ static unsigned long damon_pa_apply_scheme(struct damon= _ctx *ctx, sz_filter_passed); case DAMOS_MIGRATE_HOT: case DAMOS_MIGRATE_COLD: - return damon_pa_migrate(r, scheme, sz_filter_passed); + return damon_pa_migrate(r, aunit, scheme, sz_filter_passed); case DAMOS_STAT: return damon_pa_stat(r, scheme, sz_filter_passed); default: --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F7D12F5491 for ; Fri, 22 Aug 2025 09:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856094; cv=none; b=o+sPS+tqbMgZm8S5Brl3/hZ+yVLkn6xoTFlhpXISN0wezmpkrfes3nXRHQJW/1F3bNXnsCXO+6atMW0faCZatnTqU58XBP5Y9AgaaFCzPimYjwlBMvU0lryG+DnVa923bsQSMg8JsCMtCe3gTPXTkuF2rhGlbpNx8TfJruA54TM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856094; c=relaxed/simple; bh=jX4XLa+Ei2Dcz7wnr9MkXGCLGpv8WXAzaE8JfLJD6CQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cVWPM9ltWKfmNUbG9naaANIyy0sK9carr9l5a3czYddQjPHzJVTfTZtAGU6C3gBxTfBj3lFH5SSmvgBEr2HHbi87yXAspy0YCeoImrsVZIDmfyy19hzn0zI6BOnaPXZKtKmHHRKXeNydFGXutfKgWiTF3i42su8qOBidLbHxTKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4c7b4W2Mkvz27jJG; Fri, 22 Aug 2025 17:49:15 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 9D58F140258; Fri, 22 Aug 2025 17:48:09 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:08 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 06/11] mm/damon/paddr: support addr_unit for DAMOS_STAT Date: Fri, 22 Aug 2025 17:34:14 +0800 Message-ID: <20250822093420.2103803-7-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Add support of addr_unit for DAMOS_STAT action handling from the DAMOS operation implementation for the physical address space. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- mm/damon/paddr.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 0305e59818da..5fad2f9a99a0 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -277,17 +277,18 @@ static unsigned long damon_pa_migrate(struct damon_re= gion *r, return applied * PAGE_SIZE / addr_unit; } =20 -static unsigned long damon_pa_stat(struct damon_region *r, struct damos *s, +static unsigned long damon_pa_stat(struct damon_region *r, + unsigned long addr_unit, struct damos *s, unsigned long *sz_filter_passed) { - unsigned long addr; + phys_addr_t addr; struct folio *folio; =20 if (!damos_ops_has_filter(s)) return 0; =20 - addr =3D r->ar.start; - while (addr < r->ar.end) { + addr =3D damon_pa_phys_addr(r->ar.start, addr_unit); + while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) { folio =3D damon_get_folio(PHYS_PFN(addr)); if (damon_pa_invalid_damos_folio(folio, s)) { addr +=3D PAGE_SIZE; @@ -295,7 +296,7 @@ static unsigned long damon_pa_stat(struct damon_region = *r, struct damos *s, } =20 if (!damos_pa_filter_out(s, folio)) - *sz_filter_passed +=3D folio_size(folio); + *sz_filter_passed +=3D folio_size(folio) / addr_unit; addr +=3D folio_size(folio); folio_put(folio); } @@ -322,7 +323,7 @@ static unsigned long damon_pa_apply_scheme(struct damon= _ctx *ctx, case DAMOS_MIGRATE_COLD: return damon_pa_migrate(r, aunit, scheme, sz_filter_passed); case DAMOS_STAT: - return damon_pa_stat(r, scheme, sz_filter_passed); + return damon_pa_stat(r, aunit, scheme, sz_filter_passed); default: /* DAMOS actions that not yet supported by 'paddr'. */ break; --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DBA02F6180 for ; Fri, 22 Aug 2025 09:48:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856095; cv=none; b=URrVs14GzNXw+qvolvjkesfU0Aha+f75tmrSTMuh1dFfc1PTm0jVMhjHwiywKG1Ak1NKa49EdhVhQaAWS01VHQ+PhI+vv4XQdRkuf6d8To99CgGu1RMzA22HhG0kjN3Gv42uZWUfQ0ZwS0Ld18GbTSvkHdD04eXxAvUO9Ibo3mg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856095; c=relaxed/simple; bh=H1sl/RRi+p5LzK40S3KU9YwqXYMPBq98JUgmJ7rTEdc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DzSwTa732ULEEhaVPnvfHjyVHw73bC3yYXdZSJjFas/UwcQvF4V3tJ4Suk4U6QSu4KAHffgFnfDShKz8TXTQYUsMc29DAkWIt0qgo/wotQXaKRWa0beMWGd3n/4IL8hDShSbYxtKJrDhMQdUo/ll9/vKTMeeIE2+9jbidDwYynQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4c7b4W6ts5z27jJ3; Fri, 22 Aug 2025 17:49:15 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 40FED1401F1; Fri, 22 Aug 2025 17:48:10 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:09 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 07/11] mm/damon/sysfs: implement addr_unit file under context dir Date: Fri, 22 Aug 2025 17:34:15 +0800 Message-ID: <20250822093420.2103803-8-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Only DAMON kernel API callers can use addr_unit parameter. Implement a sysfs file to let DAMON sysfs ABI users use it. Additionally, addr_unit must be set to a non-zero value. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- mm/damon/sysfs.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 6d2b0dab50cb..98bf15d403b2 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -834,6 +834,7 @@ static const struct damon_sysfs_ops_name damon_sysfs_op= s_names[] =3D { struct damon_sysfs_context { struct kobject kobj; enum damon_ops_id ops_id; + unsigned long addr_unit; struct damon_sysfs_attrs *attrs; struct damon_sysfs_targets *targets; struct damon_sysfs_schemes *schemes; @@ -849,6 +850,7 @@ static struct damon_sysfs_context *damon_sysfs_context_= alloc( return NULL; context->kobj =3D (struct kobject){}; context->ops_id =3D ops_id; + context->addr_unit =3D 1; return context; } =20 @@ -997,6 +999,32 @@ static ssize_t operations_store(struct kobject *kobj, return -EINVAL; } =20 +static ssize_t addr_unit_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_context *context =3D container_of(kobj, + struct damon_sysfs_context, kobj); + + return sysfs_emit(buf, "%lu\n", context->addr_unit); +} + +static ssize_t addr_unit_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_context *context =3D container_of(kobj, + struct damon_sysfs_context, kobj); + unsigned long input_addr_unit; + int err =3D kstrtoul(buf, 0, &input_addr_unit); + + if (err) + return err; + if (!input_addr_unit) + return -EINVAL; + + context->addr_unit =3D input_addr_unit; + return count; +} + static void damon_sysfs_context_release(struct kobject *kobj) { kfree(container_of(kobj, struct damon_sysfs_context, kobj)); @@ -1008,9 +1036,13 @@ static struct kobj_attribute damon_sysfs_context_ava= il_operations_attr =3D static struct kobj_attribute damon_sysfs_context_operations_attr =3D __ATTR_RW_MODE(operations, 0600); =20 +static struct kobj_attribute damon_sysfs_context_addr_unit_attr =3D + __ATTR_RW_MODE(addr_unit, 0600); + static struct attribute *damon_sysfs_context_attrs[] =3D { &damon_sysfs_context_avail_operations_attr.attr, &damon_sysfs_context_operations_attr.attr, + &damon_sysfs_context_addr_unit_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_context); @@ -1397,6 +1429,7 @@ static int damon_sysfs_apply_inputs(struct damon_ctx = *ctx, err =3D damon_select_ops(ctx, sys_ctx->ops_id); if (err) return err; + ctx->addr_unit =3D sys_ctx->addr_unit; err =3D damon_sysfs_set_attrs(ctx, sys_ctx->attrs); if (err) return err; --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31FC42F6170 for ; Fri, 22 Aug 2025 09:48:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856095; cv=none; b=PUv996+O4VpeLaHnGEBUY8GUwvDmIEH81OtXAKnNEuHvgSsB+daw0Vxb7kpJCAzqQoLD3KWemEVh3Lq34VziH5BLP14+EemQlWNtNhtWAnda8V0ZbrM4JJTdI19avZh01joTarXt0uL9quO8dF2w6F+17mf9g/GBjtnlxHtWKBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856095; c=relaxed/simple; bh=bOdxSrOvnNtm9n+/5utxfhd9zAJTC7p0Q1EKvGCzb+c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u4gfSL5cWQT2kJ3E/FxsI+Tv+RoKlOJ+3eQW8bFMUdg4EGobDUcdGKa594Mdi+8PW5282j6h+WjsP7jRLAcy5C2qxSxlIXzigITT+w6nj3lAA2dSkSGZ6bBVbsjAg8Fg97CqbRyj9d1E4Qi5QhYgPBafVBsYkvUmGGLIuCqetWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c7Zzz4d4Lz24hr6; Fri, 22 Aug 2025 17:45:19 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id D12B0140109; Fri, 22 Aug 2025 17:48:10 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:10 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 08/11] Docs/mm/damon/design: document 'address unit' parameter Date: Fri, 22 Aug 2025 17:34:16 +0800 Message-ID: <20250822093420.2103803-9-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Add 'addr_unit' parameter description on DAMON design document. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- Documentation/mm/damon/design.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index 2f6ba5c7f4c7..d9d5baa1ec87 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -67,7 +67,7 @@ processes, NUMA nodes, files, and backing memory devices = would be supportable. Also, if some architectures or devices support special optimized access ch= eck features, those will be easily configurable. =20 -DAMON currently provides below three operation sets. Below two subsections +DAMON currently provides below three operation sets. Below three subsecti= ons describe how those work. =20 - vaddr: Monitor virtual address spaces of specific processes @@ -135,6 +135,18 @@ the interference is the responsibility of sysadmins. = However, it solves the conflict with the reclaim logic using ``PG_idle`` and ``PG_young`` page fl= ags, as Idle page tracking does. =20 +Address Unit +------------ + +DAMON core layer uses ``unsinged long`` type for monitoring target address +ranges. In some cases, the address space for a given operations set could= be +too large to be handled with the type. ARM (32-bit) with large physical +address extension is an example. For such cases, a per-operations set +parameter called ``address unit`` is provided. It represents the scale fa= ctor +that need to be multiplied to the core layer's address for calculating real +address on the given address space. Support of ``address unit`` parameter= is +up to each operations set implementation. ``paddr`` is the only operation= s set +implementation that supports the parameter. =20 .. _damon_core_logic: =20 --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBB1E2F657C for ; Fri, 22 Aug 2025 09:48:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856097; cv=none; b=muJw9glIQgx0UJJlOL8Wmsu5+lo1lYQ1tNG2J4z30jfLj0Ldp0E7FNnR38lzN/E8o+1WeKBs3S55Fm6+8VWaFeGcs4vJTGEZGR/1O8EP+XaaX1AUj8Byj8qKOngJzX4DfLSoPqswMihIBGbH4eIq3rMNfUyeBJCfLOnAmZdRN5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856097; c=relaxed/simple; bh=ViQi5oP+9X7Zp+6A1NZAhO+SDfGhMMvFjNPoev8A//g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WdMiti8/va9tJc1Y6N+RkU6aKwOtiBs+eUYx2yA4an9UH+DHYbrvxqG4GCyWmqO5XdC6xwcTVhA3zb34iSCVEp/6JdHmFMfc+K5xSJ1B954XaAwh4+rAqtFssFlyCPrz+LKy1MZtUf0NNMP4Ld86Z/+jM3bFby7xzI8aFYmI3tg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c7b3B5g00z14MWC; Fri, 22 Aug 2025 17:48:06 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 75914180495; Fri, 22 Aug 2025 17:48:11 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:10 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 09/11] Docs/admin-guide/mm/damon/usage: document addr_unit file Date: Fri, 22 Aug 2025 17:34:17 +0800 Message-ID: <20250822093420.2103803-10-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) From: SeongJae Park Document addr_unit DAMON sysfs file on DAMON usage document. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 11 +++++++---- Documentation/mm/damon/design.rst | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index ff3a2dda1f02..2cae60b6f3ca 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -61,7 +61,7 @@ comma (","). =E2=94=82 :ref:`kdamonds `/nr_kdamonds =E2=94=82 =E2=94=82 :ref:`0 `/state,pid,refresh_ms =E2=94=82 =E2=94=82 =E2=94=82 :ref:`contexts `/nr_cont= exts - =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 :ref:`0 `/avail= _operations,operations + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 :ref:`0 `/avail= _operations,operations,addr_unit =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 :ref:`monitoring_att= rs `/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 intervals/= sample_us,aggr_us,update_us =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = intervals_goal/access_bp,aggrs,min_sample_us,max_sample_us @@ -188,9 +188,9 @@ details). At the moment, only one context per kdamond = is supported, so only contexts// ------------- =20 -In each context directory, two files (``avail_operations`` and ``operation= s``) -and three directories (``monitoring_attrs``, ``targets``, and ``schemes``) -exist. +In each context directory, three files (``avail_operations``, ``operations= `` +and ``addr_unit``) and three directories (``monitoring_attrs``, ``targets`= `, +and ``schemes``) exist. =20 DAMON supports multiple types of :ref:`monitoring operations `, including those for virtual a= ddress @@ -205,6 +205,9 @@ You can set and get what type of monitoring operations = DAMON will use for the context by writing one of the keywords listed in ``avail_operations`` file= and reading from the ``operations`` file. =20 +``addr_unit`` file is for setting and getting the :ref:`address unit +` parameter of the operations set. + .. _sysfs_monitoring_attrs: =20 contexts//monitoring_attrs/ diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index d9d5baa1ec87..80354f4f42ba 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -135,6 +135,8 @@ the interference is the responsibility of sysadmins. H= owever, it solves the conflict with the reclaim logic using ``PG_idle`` and ``PG_young`` page fl= ags, as Idle page tracking does. =20 +.. _damon_design_addr_unit: + Address Unit ------------ =20 --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87B882F744A for ; Fri, 22 Aug 2025 09:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856097; cv=none; b=MD8kM080+ILERVropn6koVUlRU1ZyBlnhY6sROq9GNnl6lUml/SAwby/1PVFadeufb7tqiluIrZ3UQX6WNhGzY7hwaQw/oANZII6hOChThYk8+ITyigE9ObocKl/OffusJDl47Pwgjn/tcpdE3azA4wscgvbvuj44scMPNoWsYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856097; c=relaxed/simple; bh=TcIoYhVEN2MsnPWOdHUGQFFGryKD1imr36MDA4Fif0g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jbQzL08SBHlnMWm3fXJBpUlJlQhORQXDdGxTJW3ElIvaxqZX2Xq2uwtizujj6JOntI0GKbR7Pe0y2Jj3D1/Srzrw5zUtIbpWg4zb0mC21QsZ41cVhWq3Zlpni+FyAmX8vkW/Fe9xO1agz0eG1EYny6teaHbwktrTMOMGAijBJvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c7b006GKqz24hrS; Fri, 22 Aug 2025 17:45:20 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 16E80140109; Fri, 22 Aug 2025 17:48:12 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:11 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 10/11] Docs/ABI/damon: document addr_unit file Date: Fri, 22 Aug 2025 17:34:18 +0800 Message-ID: <20250822093420.2103803-11-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" From: SeongJae Park Document addr_unit DAMON sysfs file on DAMON ABI document. Signed-off-by: SeongJae Park Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- Documentation/ABI/testing/sysfs-kernel-mm-damon | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentatio= n/ABI/testing/sysfs-kernel-mm-damon index 6791d879759e..b6b71db36ca7 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -77,6 +77,13 @@ Description: Writing a keyword for a monitoring operatio= ns set ('vaddr' for Note that only the operations sets that listed in 'avail_operations' file are valid inputs. =20 +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//addr_unit +Date: Aug 2025 +Contact: SeongJae Park +Description: Writing an integer to this file sets the 'address unit' + parameter of the given operations set of the context. Reading + the file returns the last-written 'address unit' value. + What: /sys/kernel/mm/damon/admin/kdamonds//contexts//monitoring_att= rs/intervals/sample_us Date: Mar 2022 Contact: SeongJae Park --=20 2.43.0 From nobody Fri Oct 3 23:09:40 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17A822F746E for ; Fri, 22 Aug 2025 09:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856098; cv=none; b=OgCw0AETrO42PONRdP0OlK4pATAQZx8PYPT/M7Zvb3SMNKwlLPM4fvdCOGnRy3KBeFD7ONHtGXjq+G2f+qd5uwzbqtKzKuICo81S2izNYjX5RfYeFgljzm9ubSiycd3XEEFbKVjwapsSaXsBmN8PRgDCaz99+71t2zQIgTbWgM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755856098; c=relaxed/simple; bh=urkxhQG+BmoxwgTc1i1XrmYYai+NprmFsFsUefoJAoc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ulh+w/OIccQvUyqvzTO4SLSES8YqsdYgiWzVn4CkOJ3FcbSqw+1nLoyvpC/HgWMbAVafoePCPeVik7Xvwz+El3Heuwj8Pzv0dWCKxuDRy6nt9wYj8VOeDcnJltIx/u+EM48O77AhL2kbxsfLnE2VzpdFlTFHwqViQJsopGrhsRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c7b013zJkz24hrH; Fri, 22 Aug 2025 17:45:21 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id B8E6C1A0188; Fri, 22 Aug 2025 17:48:12 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 17:48:12 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 11/11] mm/damon: add damon_ctx->min_sz_region Date: Fri, 22 Aug 2025 17:34:19 +0800 Message-ID: <20250822093420.2103803-12-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822093420.2103803-1-yanquanmin1@huawei.com> References: <20250822093420.2103803-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" Adopting addr_unit would make DAMON_MINREGION 'addr_unit * 4096' bytes and cause data alignment issues[1]. Add damon_ctx->min_sz_region to change DAMON_MIN_REGION from a global macro value to per-context variable. [1] https://lore.kernel.org/all/527714dd-0e33-43ab-bbbd-d89670ba79e7@huawei= .com Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- include/linux/damon.h | 4 ++- mm/damon/core.c | 67 ++++++++++++++++++++---------------- mm/damon/sysfs.c | 8 +++-- mm/damon/tests/core-kunit.h | 21 ++++++----- mm/damon/tests/vaddr-kunit.h | 2 +- mm/damon/vaddr.c | 2 +- 6 files changed, 61 insertions(+), 43 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 6fa52f7495d9..ec8716292c09 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -747,6 +747,7 @@ struct damon_attrs { * * @ops: Set of monitoring operations for given use cases. * @addr_unit: Scale factor for core to ops address conversion. + * @min_sz_region: Minimum region size. * @adaptive_targets: Head of monitoring targets (&damon_target) list. * @schemes: Head of schemes (&damos) list. */ @@ -789,6 +790,7 @@ struct damon_ctx { =20 struct damon_operations ops; unsigned long addr_unit; + unsigned long min_sz_region; =20 struct list_head adaptive_targets; struct list_head schemes; @@ -877,7 +879,7 @@ static inline void damon_insert_region(struct damon_reg= ion *r, void damon_add_region(struct damon_region *r, struct damon_target *t); void damon_destroy_region(struct damon_region *r, struct damon_target *t); int damon_set_regions(struct damon_target *t, struct damon_addr_range *ran= ges, - unsigned int nr_ranges); + unsigned int nr_ranges, unsigned long min_sz_region); void damon_update_region_access_rate(struct damon_region *r, bool accessed, struct damon_attrs *attrs); =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 8f8aa84953ac..7c332be4f291 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -201,6 +201,7 @@ static int damon_fill_regions_holes(struct damon_region= *first, * @t: the given target. * @ranges: array of new monitoring target ranges. * @nr_ranges: length of @ranges. + * @min_sz_region: minimum region size. * * This function adds new regions to, or modify existing regions of a * monitoring target to fit in specific ranges. @@ -208,7 +209,7 @@ static int damon_fill_regions_holes(struct damon_region= *first, * Return: 0 if success, or negative error code otherwise. */ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ran= ges, - unsigned int nr_ranges) + unsigned int nr_ranges, unsigned long min_sz_region) { struct damon_region *r, *next; unsigned int i; @@ -245,16 +246,16 @@ int damon_set_regions(struct damon_target *t, struct = damon_addr_range *ranges, /* no region intersects with this range */ newr =3D damon_new_region( ALIGN_DOWN(range->start, - DAMON_MIN_REGION), - ALIGN(range->end, DAMON_MIN_REGION)); + min_sz_region), + ALIGN(range->end, min_sz_region)); if (!newr) return -ENOMEM; damon_insert_region(newr, damon_prev_region(r), r, t); } else { /* resize intersecting regions to fit in this range */ first->ar.start =3D ALIGN_DOWN(range->start, - DAMON_MIN_REGION); - last->ar.end =3D ALIGN(range->end, DAMON_MIN_REGION); + min_sz_region); + last->ar.end =3D ALIGN(range->end, min_sz_region); =20 /* fill possible holes in the range */ err =3D damon_fill_regions_holes(first, last, t); @@ -545,6 +546,7 @@ struct damon_ctx *damon_new_ctx(void) ctx->attrs.max_nr_regions =3D 1000; =20 ctx->addr_unit =3D 1; + ctx->min_sz_region =3D DAMON_MIN_REGION; =20 INIT_LIST_HEAD(&ctx->adaptive_targets); INIT_LIST_HEAD(&ctx->schemes); @@ -1127,8 +1129,8 @@ static struct damon_target *damon_nth_target(int n, s= truct damon_ctx *ctx) * * If @src has no region, @dst keeps current regions. */ -static int damon_commit_target_regions( - struct damon_target *dst, struct damon_target *src) +static int damon_commit_target_regions(struct damon_target *dst, + struct damon_target *src, unsigned long src_min_sz_region) { struct damon_region *src_region; struct damon_addr_range *ranges; @@ -1145,18 +1147,19 @@ static int damon_commit_target_regions( i =3D 0; damon_for_each_region(src_region, src) ranges[i++] =3D src_region->ar; - err =3D damon_set_regions(dst, ranges, i); + err =3D damon_set_regions(dst, ranges, i, src_min_sz_region); kfree(ranges); return err; } =20 static int damon_commit_target( struct damon_target *dst, bool dst_has_pid, - struct damon_target *src, bool src_has_pid) + struct damon_target *src, bool src_has_pid, + unsigned long src_min_sz_region) { int err; =20 - err =3D damon_commit_target_regions(dst, src); + err =3D damon_commit_target_regions(dst, src, src_min_sz_region); if (err) return err; if (dst_has_pid) @@ -1178,7 +1181,8 @@ static int damon_commit_targets( if (src_target) { err =3D damon_commit_target( dst_target, damon_target_has_pid(dst), - src_target, damon_target_has_pid(src)); + src_target, damon_target_has_pid(src), + src->min_sz_region); if (err) return err; } else { @@ -1201,7 +1205,8 @@ static int damon_commit_targets( if (!new_target) return -ENOMEM; err =3D damon_commit_target(new_target, false, - src_target, damon_target_has_pid(src)); + src_target, damon_target_has_pid(src), + src->min_sz_region); if (err) { damon_destroy_target(new_target, NULL); return err; @@ -1248,6 +1253,7 @@ int damon_commit_ctx(struct damon_ctx *dst, struct da= mon_ctx *src) } dst->ops =3D src->ops; dst->addr_unit =3D src->addr_unit; + dst->min_sz_region =3D src->min_sz_region; =20 return 0; } @@ -1280,8 +1286,8 @@ static unsigned long damon_region_sz_limit(struct dam= on_ctx *ctx) =20 if (ctx->attrs.min_nr_regions) sz /=3D ctx->attrs.min_nr_regions; - if (sz < DAMON_MIN_REGION) - sz =3D DAMON_MIN_REGION; + if (sz < ctx->min_sz_region) + sz =3D ctx->min_sz_region; =20 return sz; } @@ -1625,6 +1631,7 @@ static bool damos_valid_target(struct damon_ctx *c, s= truct damon_target *t, * @t: The target of the region. * @rp: The pointer to the region. * @s: The scheme to be applied. + * @min_sz_region: minimum region size. * * If a quota of a scheme has exceeded in a quota charge window, the schem= e's * action would applied to only a part of the target access pattern fulfil= ling @@ -1642,7 +1649,7 @@ static bool damos_valid_target(struct damon_ctx *c, s= truct damon_target *t, * Return: true if the region should be entirely skipped, false otherwise. */ static bool damos_skip_charged_region(struct damon_target *t, - struct damon_region **rp, struct damos *s) + struct damon_region **rp, struct damos *s, unsigned long min_sz_region) { struct damon_region *r =3D *rp; struct damos_quota *quota =3D &s->quota; @@ -1664,11 +1671,11 @@ static bool damos_skip_charged_region(struct damon_= target *t, if (quota->charge_addr_from && r->ar.start < quota->charge_addr_from) { sz_to_skip =3D ALIGN_DOWN(quota->charge_addr_from - - r->ar.start, DAMON_MIN_REGION); + r->ar.start, min_sz_region); if (!sz_to_skip) { - if (damon_sz_region(r) <=3D DAMON_MIN_REGION) + if (damon_sz_region(r) <=3D min_sz_region) return true; - sz_to_skip =3D DAMON_MIN_REGION; + sz_to_skip =3D min_sz_region; } damon_split_region_at(t, r, sz_to_skip); r =3D damon_next_region(r); @@ -1693,7 +1700,8 @@ static void damos_update_stat(struct damos *s, } =20 static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target = *t, - struct damon_region *r, struct damos_filter *filter) + struct damon_region *r, struct damos_filter *filter, + unsigned long min_sz_region) { bool matched =3D false; struct damon_target *ti; @@ -1710,8 +1718,8 @@ static bool damos_filter_match(struct damon_ctx *ctx,= struct damon_target *t, matched =3D target_idx =3D=3D filter->target_idx; break; case DAMOS_FILTER_TYPE_ADDR: - start =3D ALIGN_DOWN(filter->addr_range.start, DAMON_MIN_REGION); - end =3D ALIGN_DOWN(filter->addr_range.end, DAMON_MIN_REGION); + start =3D ALIGN_DOWN(filter->addr_range.start, min_sz_region); + end =3D ALIGN_DOWN(filter->addr_range.end, min_sz_region); =20 /* inside the range */ if (start <=3D r->ar.start && r->ar.end <=3D end) { @@ -1747,7 +1755,7 @@ static bool damos_filter_out(struct damon_ctx *ctx, s= truct damon_target *t, =20 s->core_filters_allowed =3D false; damos_for_each_filter(filter, s) { - if (damos_filter_match(ctx, t, r, filter)) { + if (damos_filter_match(ctx, t, r, filter, ctx->min_sz_region)) { if (filter->allow) s->core_filters_allowed =3D true; return !filter->allow; @@ -1882,7 +1890,7 @@ static void damos_apply_scheme(struct damon_ctx *c, s= truct damon_target *t, if (c->ops.apply_scheme) { if (quota->esz && quota->charged_sz + sz > quota->esz) { sz =3D ALIGN_DOWN(quota->esz - quota->charged_sz, - DAMON_MIN_REGION); + c->min_sz_region); if (!sz) goto update_stat; damon_split_region_at(t, r, sz); @@ -1930,7 +1938,7 @@ static void damon_do_apply_schemes(struct damon_ctx *= c, if (quota->esz && quota->charged_sz >=3D quota->esz) continue; =20 - if (damos_skip_charged_region(t, &r, s)) + if (damos_skip_charged_region(t, &r, s, c->min_sz_region)) continue; =20 if (!damos_valid_target(c, t, r, s)) @@ -2324,7 +2332,8 @@ static void damon_split_region_at(struct damon_target= *t, } =20 /* Split every region in the given target into 'nr_subs' regions */ -static void damon_split_regions_of(struct damon_target *t, int nr_subs) +static void damon_split_regions_of(struct damon_target *t, int nr_subs, + unsigned long min_sz_region) { struct damon_region *r, *next; unsigned long sz_region, sz_sub =3D 0; @@ -2334,13 +2343,13 @@ static void damon_split_regions_of(struct damon_tar= get *t, int nr_subs) sz_region =3D damon_sz_region(r); =20 for (i =3D 0; i < nr_subs - 1 && - sz_region > 2 * DAMON_MIN_REGION; i++) { + sz_region > 2 * min_sz_region; i++) { /* * Randomly select size of left sub-region to be at * least 10 percent and at most 90% of original region */ sz_sub =3D ALIGN_DOWN(damon_rand(1, 10) * - sz_region / 10, DAMON_MIN_REGION); + sz_region / 10, min_sz_region); /* Do not allow blank region */ if (sz_sub =3D=3D 0 || sz_sub >=3D sz_region) continue; @@ -2380,7 +2389,7 @@ static void kdamond_split_regions(struct damon_ctx *c= tx) nr_subregions =3D 3; =20 damon_for_each_target(t, ctx) - damon_split_regions_of(t, nr_subregions); + damon_split_regions_of(t, nr_subregions, ctx->min_sz_region); =20 last_nr_regions =3D nr_regions; } @@ -2769,7 +2778,7 @@ int damon_set_region_biggest_system_ram_default(struc= t damon_target *t, =20 addr_range.start =3D *start; addr_range.end =3D *end; - return damon_set_regions(t, &addr_range, 1); + return damon_set_regions(t, &addr_range, 1, DAMON_MIN_REGION); } =20 /* diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 98bf15d403b2..0ed404c89f80 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1329,7 +1329,8 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ct= x, } =20 static int damon_sysfs_set_regions(struct damon_target *t, - struct damon_sysfs_regions *sysfs_regions) + struct damon_sysfs_regions *sysfs_regions, + unsigned long min_sz_region) { struct damon_addr_range *ranges =3D kmalloc_array(sysfs_regions->nr, sizeof(*ranges), GFP_KERNEL | __GFP_NOWARN); @@ -1351,7 +1352,7 @@ static int damon_sysfs_set_regions(struct damon_targe= t *t, if (ranges[i - 1].end > ranges[i].start) goto out; } - err =3D damon_set_regions(t, ranges, sysfs_regions->nr); + err =3D damon_set_regions(t, ranges, sysfs_regions->nr, min_sz_region); out: kfree(ranges); return err; @@ -1372,7 +1373,7 @@ static int damon_sysfs_add_target(struct damon_sysfs_= target *sys_target, /* caller will destroy targets */ return -EINVAL; } - return damon_sysfs_set_regions(t, sys_target->regions); + return damon_sysfs_set_regions(t, sys_target->regions, ctx->min_sz_region= ); } =20 static int damon_sysfs_add_targets(struct damon_ctx *ctx, @@ -1430,6 +1431,7 @@ static int damon_sysfs_apply_inputs(struct damon_ctx = *ctx, if (err) return err; ctx->addr_unit =3D sys_ctx->addr_unit; + ctx->min_sz_region =3D max(DAMON_MIN_REGION / sys_ctx->addr_unit, 1); err =3D damon_sysfs_set_attrs(ctx, sys_ctx->attrs); if (err) return err; diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 5f5dc9db2e90..51369e35298b 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -230,14 +230,14 @@ static void damon_test_split_regions_of(struct kunit = *test) t =3D damon_new_target(); r =3D damon_new_region(0, 22); damon_add_region(r, t); - damon_split_regions_of(t, 2); + damon_split_regions_of(t, 2, DAMON_MIN_REGION); KUNIT_EXPECT_LE(test, damon_nr_regions(t), 2u); damon_free_target(t); =20 t =3D damon_new_target(); r =3D damon_new_region(0, 220); damon_add_region(r, t); - damon_split_regions_of(t, 4); + damon_split_regions_of(t, 4, DAMON_MIN_REGION); KUNIT_EXPECT_LE(test, damon_nr_regions(t), 4u); damon_free_target(t); damon_destroy_ctx(c); @@ -303,7 +303,7 @@ static void damon_test_set_regions(struct kunit *test) =20 damon_add_region(r1, t); damon_add_region(r2, t); - damon_set_regions(t, &range, 1); + damon_set_regions(t, &range, 1, DAMON_MIN_REGION); =20 KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 3); damon_for_each_region(r, t) { @@ -450,25 +450,29 @@ static void damos_test_filter_out(struct kunit *test) damon_add_region(r, t); =20 /* region in the range */ - KUNIT_EXPECT_TRUE(test, damos_filter_match(NULL, t, r, f)); + KUNIT_EXPECT_TRUE(test, + damos_filter_match(NULL, t, r, f, DAMON_MIN_REGION)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); =20 /* region before the range */ r->ar.start =3D DAMON_MIN_REGION * 1; r->ar.end =3D DAMON_MIN_REGION * 2; - KUNIT_EXPECT_FALSE(test, damos_filter_match(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, + damos_filter_match(NULL, t, r, f, DAMON_MIN_REGION)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); =20 /* region after the range */ r->ar.start =3D DAMON_MIN_REGION * 6; r->ar.end =3D DAMON_MIN_REGION * 8; - KUNIT_EXPECT_FALSE(test, damos_filter_match(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, + damos_filter_match(NULL, t, r, f, DAMON_MIN_REGION)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); =20 /* region started before the range */ r->ar.start =3D DAMON_MIN_REGION * 1; r->ar.end =3D DAMON_MIN_REGION * 4; - KUNIT_EXPECT_FALSE(test, damos_filter_match(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, + damos_filter_match(NULL, t, r, f, DAMON_MIN_REGION)); /* filter should have split the region */ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 1); KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 2); @@ -481,7 +485,8 @@ static void damos_test_filter_out(struct kunit *test) /* region started in the range */ r->ar.start =3D DAMON_MIN_REGION * 2; r->ar.end =3D DAMON_MIN_REGION * 8; - KUNIT_EXPECT_TRUE(test, damos_filter_match(NULL, t, r, f)); + KUNIT_EXPECT_TRUE(test, + damos_filter_match(NULL, t, r, f, DAMON_MIN_REGION)); /* filter should have split the region */ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 2); KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 6); diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h index d2b37ccf2cc0..fce38dd53cf8 100644 --- a/mm/damon/tests/vaddr-kunit.h +++ b/mm/damon/tests/vaddr-kunit.h @@ -141,7 +141,7 @@ static void damon_do_test_apply_three_regions(struct ku= nit *test, damon_add_region(r, t); } =20 - damon_set_regions(t, three_regions, 3); + damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION); =20 for (i =3D 0; i < nr_expected / 2; i++) { r =3D __nth_region_of(t, i); diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 66ef9869eafe..8c048f9b129e 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -299,7 +299,7 @@ static void damon_va_update(struct damon_ctx *ctx) damon_for_each_target(t, ctx) { if (damon_va_three_regions(t, three_regions)) continue; - damon_set_regions(t, three_regions, 3); + damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION); } } =20 --=20 2.43.0