From nobody Sat Oct 4 21:02:18 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 944052BE04A for ; Wed, 13 Aug 2025 03:52:37 +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=1755057160; cv=none; b=lLRR1b0jAY9ueooiCIeZpAGUwtDbjVXsyMlNmrq1abgWz5rLAyFj5F+BYFKskHiRzdXqVfzwkwOjEVU0QHKdVPt/E3QQYGSxb267CYGVyj6u+zE15rkdCCTSvX9fN/6ofIZ1ysthRueRaVaKq8XB4b+Xx4SV/VJnOp5YXRQudIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057160; c=relaxed/simple; bh=QwXB4tFt9ZGSdeTC4+s1rqlroCTnpyScmQ6IhAuRxXU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BMYd5S3jRNvQ2b20G+WUyYnLz03q3L76w5c7Ue9wL5p6f5IOxutLrtkvA5+YojBA4ymmhsffN92+jUxg+k+fDgQqXF7HXr3FzvEQFjMTipn/oKRSwF2s5aLJ4N8aNwNaqopu97Pmpr9YDNk83S7ighem8SC8GlehCEUFWb+xEuA= 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 4c1vWl71b9z1R90b; Wed, 13 Aug 2025 11:49:39 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id CC95D1A0188; Wed, 13 Aug 2025 11:52:29 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:29 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 01/16] mm/damon/core: add damon_ctx->addr_unit Date: Wed, 13 Aug 2025 13:06:51 +0800 Message-ID: <20250813050706.1564229-2-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- 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 f13664c62ddd..b85c6c669cd0 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 52a48c9316bc..1a8d3009d606 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 @@ -1213,6 +1215,7 @@ int damon_commit_ctx(struct damon_ctx *dst, struct da= mon_ctx *src) if (err) return err; dst->ops =3D src->ops; + dst->addr_unit =3D src->addr_unit ? : 1; =20 return 0; } --=20 2.34.1 From nobody Sat Oct 4 21:02:18 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 F12DC1D63C5 for ; Wed, 13 Aug 2025 03:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057155; cv=none; b=DygiLEgFos1xYZZKbnqxhVTijtR77Ppd4O3ihDUHO2yxQsYvvwacxcwZrrkN/h4qetS3IiI63Fpb8Q2IVMRa9NLe4hjgruYxB5k82oucbwjkOZKchcf92lhQJB54WUYzPRfSEwgmdjXDXaoGc6oPU+1svbnT3hgnzd/eUZ9O+NM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057155; c=relaxed/simple; bh=ulyPcoNRDmysDpX5p6CVFB/4BZyldT+Vcx2scY389o0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RM3W2hyEVV1cHpNdnFwuK0rqviy/s29VJmhCuMJ07IPJVcsUUpnXMlarA1iIaxZwo6mneBmJBTxhIr8EBfPwPvSoA9h74usUyqGgu/6TXhZzs+dEaYGXGzqyLB/qnnZXvqI3dlehhbFv72pK46RClyzG0UBGJlfz30Xx2/A/f6c= 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.189 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.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4c1vV25thZzdcD1; Wed, 13 Aug 2025 11:48:10 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 91E7D1402ED; Wed, 13 Aug 2025 11:52:30 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:29 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 02/16] mm/damon/paddr: support addr_unit for access monitoring Date: Wed, 13 Aug 2025 13:06:52 +0800 Message-ID: <20250813050706.1564229-3-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- 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 53a55c5114fb..345a0ae63b19 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.34.1 From nobody Sat Oct 4 21:02:18 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 973C72BE04C for ; Wed, 13 Aug 2025 03:52:38 +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=1755057160; cv=none; b=HyTSBoWkiTMPqtVxuWhjoaTc3Di+CrX5gCerows21vNPZ5LoLTRJcFS2mBPcp9TXg5TnLVQ5aFdo2uMZnE177UEYkIoxdabVpCd68uWq02VkxAWpFOJdzVOjhCQsOFkLF4N4MabLbKKFJxZsBVGjl23UFvteMjtAA0rRwitslXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057160; c=relaxed/simple; bh=PWVx+knEVZztwvnexj6um5NDbk2aVK8/y7TEP3wE+WE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PjABPm2srivDEQhdxywMP4U+AywvX/KrIq8cRkfWl8v5MkmzCv1sFYAYIVd5yKWbeBi0Mi51oZovFzSwBdoimhJVl3AjpBRFh8pgNRPIBdqqkQwdahHeb2wVrAsm8W+yVK/PyYchHRdOfHq+XBcHKNhw1lNedsePzb4KYanWO5s= 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.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c1vWn3kzRz1R90f; Wed, 13 Aug 2025 11:49:41 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 5EB98180044; Wed, 13 Aug 2025 11:52:31 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:30 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 03/16] mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT Date: Wed, 13 Aug 2025 13:06:53 +0800 Message-ID: <20250813050706.1564229-4-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- mm/damon/paddr.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 345a0ae63b19..b548813a0472 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -135,10 +135,12 @@ 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; + unsigned long applied; LIST_HEAD(folio_list); bool install_young_filter =3D true; struct damos_filter *filter; @@ -159,8 +161,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; @@ -311,9 +313,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.34.1 From nobody Sat Oct 4 21:02:18 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 D46052BE630 for ; Wed, 13 Aug 2025 03:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057162; cv=none; b=aZQhG8MufTb3iCwNURBCf4l66WAtBd6CX34q6P01bxQXXsnir0hmPwEUjPn1IjGB0xjd8fl7WMBe82+NCnbPy2Ahr1plodX3OFd5qHNMWdprg5kaTHRGjibQBzozElOnDsizQChkfOrt1xeF24kEgJ7VFoMAf0mxxZKmyT1XP0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057162; c=relaxed/simple; bh=qt9jQ18cGuKe6XFCz3xonlrzigV9tibsPEPRR6wcQnY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PtbpVbnJNoQja8UjAv49M6RtwCS2AaUtiH7Bk05gGhE5vGtSZi+MwBKhlxRyZ4eR3isLb6SY2jw2IXryxXZy20WqXHIVEG8QrVxxla4jOXZ8VxI7Bft1j0xlpQUvPCVXJu1Sqf83l2q8JBR3OMcM+wt3SoONHEQS4C2aqVL9sgQ= 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.190 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 szxga04-in.huawei.com (SkyGuard) with ESMTP id 4c1vV44ktFz2Cg50; Wed, 13 Aug 2025 11:48:12 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 2CEFD140109; Wed, 13 Aug 2025 11:52:32 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:31 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 04/16] mm/damon/paddr: support addr_unit for DAMOS_LRU_[DE]PRIO Date: Wed, 13 Aug 2025 13:06:54 +0800 Message-ID: <20250813050706.1564229-5-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- mm/damon/paddr.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b548813a0472..b8a7f462967b 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -195,14 +195,16 @@ 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; + unsigned long 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; @@ -228,16 +230,18 @@ static inline unsigned long damon_pa_mark_accessed_or= _deactivate( } =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 @@ -319,9 +323,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.34.1 From nobody Sat Oct 4 21:02:18 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 245311E9919 for ; Wed, 13 Aug 2025 03:52:35 +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=1755057158; cv=none; b=iElTZi0YwxmDpTv52uTXJ2cMaBtl8L/BAZuv/SYGoFCVp4bxXuGw2rgFWfWPcfxTqDE16ZoTj98BnA/tSa9uSW679joX+g3m/YAB0GaeCXBA0rQRjfvWU7mtNBI9dxMTYRCJSOiyBPUTYqKtiwYJqn8z71KGvU6jMacP0/21GMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057158; c=relaxed/simple; bh=YyfkuuZ1Ujm+PMhnwJcHFUQkjzkuSC17Isp2jorE/mk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uzvsORLNcuDWaExZlonUvHI3qudcPS8SUthpFKqv5OwCHVUAch/j/zQ149LNLjo6K9MbC6Q/BXgL+8uAUokvwUrPjgPvWyLkn5T9AwQt/zObRMf99SpX2QhqeYrnFDmkEk9OYV5nPbhoGT6szxCoYVGayWauKyArmhgtq84Dr7s= 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.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c1vTK4X9Vz14MRH; Wed, 13 Aug 2025 11:47:33 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id E88C3140202; Wed, 13 Aug 2025 11:52:32 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:32 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 05/16] mm/damon/paddr: support addr_unit for MIGRATE_{HOT,COLD} Date: Wed, 13 Aug 2025 13:06:55 +0800 Message-ID: <20250813050706.1564229-6-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- mm/damon/paddr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b8a7f462967b..76e1ee82b441 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -245,15 +245,17 @@ 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; + unsigned long 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; @@ -330,7 +332,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.34.1 From nobody Sat Oct 4 21:02:18 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 C41D525A2C0 for ; Wed, 13 Aug 2025 03:52:41 +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=1755057163; cv=none; b=LXIeFu/81xD65hhURly/vleZqKKTnXO95gJwNtq/rUIoJygRplreSlOhhB3AFPBPmdso9kfGtg+tewvSOT6nR5R3NKDgkIk4ziihB17UaZV4LS9L07B1Ud+k/Uw2Ui0HdQqZOzNZnlf2krF4kig1mGrb1zwclsNuMJ2p0bIIoVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057163; c=relaxed/simple; bh=3wd0t2c2+VJKodUzDTdYTGuKzZ2NWATSOKx9NCa2o/w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eI+9ceyfgv/JzQR6GZWrn51rf7xyGFEWTmoalmM/Xl3RS8L+sNEiIZ//lJkCEH8LnDPsV7QIdxMqXzahFG9cDAZAKB/VC1tQ1rzzWluj7hzGcU8PSuzke0JYEf0Fd3EeIVrE3AegZJlaIXrvctyPuWrhWCSZe7ZrebBirJHBtMk= 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 4c1vWq69vzz1R91D; Wed, 13 Aug 2025 11:49:43 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id B40CA1402C1; Wed, 13 Aug 2025 11:52:33 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:32 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 06/16] mm/damon/paddr: support addr_unit for DAMOS_STAT Date: Wed, 13 Aug 2025 13:06:56 +0800 Message-ID: <20250813050706.1564229-7-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- mm/damon/paddr.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 76e1ee82b441..530bc9d3ce3b 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -289,17 +289,18 @@ static bool damon_pa_scheme_has_filter(struct damos *= s) return false; } =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 (!damon_pa_scheme_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; @@ -334,7 +335,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.34.1 From nobody Sat Oct 4 21:02:18 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 8576E1DF725 for ; Wed, 13 Aug 2025 03:52:42 +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=1755057165; cv=none; b=Rf4/U13kgvqCs/dPJ31BWOzElXV41aauitxxp9LHE5eVsFuqMkheu3uYjDx3O4gid8K1Czp+XHLjdvW7NsvTFG8B0TK7JLdNvDzNc6M2OatQCUCsM1vvTuk6IvCD/KcVwSgdi4m+eI14GYMY7msvK9jJAqC66kUc+l6UmhjfkrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057165; c=relaxed/simple; bh=tmw0EN1T6liUtcRnaAKtCndgxrlNAmg8cwMNDr+GtwI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qq+Ffb5Gby0Yv8H3N40IKcfhhsYBJfR9h6Ih560an+c1+DgsNJgyG2arqik69SDo56YrLhAshk9wIVjqzBMTe8P+c1pH3GEPwJ4gcHcNq3HaSKHneenTTK0jGejH4kszRNUUApS+3I90y+JkEvZ5Jd0ZlmEefazSTw1n1+iOEJQ= 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.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c1vX30h4Zz2Dc11; Wed, 13 Aug 2025 11:49:55 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 7EFDF180044; Wed, 13 Aug 2025 11:52:34 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:33 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 07/16] mm/damon/sysfs: implement addr_unit file under context dir Date: Wed, 13 Aug 2025 13:06:57 +0800 Message-ID: <20250813050706.1564229-8-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 6d2b0dab50cb..bea782b0a711 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,25 @@ 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); + int err =3D kstrtoul(buf, 0, &context->addr_unit); + + return err ? err : count; +} + static void damon_sysfs_context_release(struct kobject *kobj) { kfree(container_of(kobj, struct damon_sysfs_context, kobj)); @@ -1008,9 +1029,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 +1422,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.34.1 From nobody Sat Oct 4 21:02:18 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 585851DF725 for ; Wed, 13 Aug 2025 03:52:37 +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=1755057159; cv=none; b=INrbXcQCe08o6UJ4ZWznOzEGSKDSXd75aBa4/bi0aWrVGq7jwytEZGN1reJ9M+z5w6oW7TBvgNhZ38vu7HIZL9+IBNk618qESY3fKnEoTcZ2rX7wK6Dat4Ftbdf5O+hnvZG+vakcbkK6gMsriF5cTIbSTqs3/Oznhz2gPoCbKBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057159; c=relaxed/simple; bh=HvU3E/EZrYOQm87rtAfpaxHK5Sj8XoCon38Ydsvh/0o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pTnMZ1xdNC038bWA4P3fffyHECeixn07uJwpQ01QaOF9WZHF/rnABskBaWYLcyJh1bifDH6by1MiFdTECE0LLMH+SqzX0GrWwIWyy4EWtvq/nLvlZMijJJaV1Ey/KN3L94KkCnkyvxoD4lsFtOgwqYB0eskr5WOro9QTlT3iZaY= 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 4c1vTN04kPz14MTY; Wed, 13 Aug 2025 11:47:36 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 4F63818048D; Wed, 13 Aug 2025 11:52:35 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:34 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 08/16] Docs/mm/damon/design: document 'address unit' parameter Date: Wed, 13 Aug 2025 13:06:58 +0800 Message-ID: <20250813050706.1564229-9-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- 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 03f8137256f5..cffa320ead88 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.34.1 From nobody Sat Oct 4 21:02:18 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 5805C2BE039 for ; Wed, 13 Aug 2025 03:52:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057160; cv=none; b=bmd1+gmdq1Vv/wTLdNu8bHAouRmDDVKrDST07Q/S816fjhqTEcB1CGA99W0hUYRCMVUVduDQVeudmmRw/I8pGGrIhqhJ76twXBE2YoLInv6n2A+ecwaB8Rk6RW6WhfIEOaemyC7kVuzo2XTAkyjgL+yyhQDoBQoUexOiI1pkzQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057160; c=relaxed/simple; bh=GHFdrvaKvhnnrrpgwO7zPJ05kYU1StmDteG3A7yKz0E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AgEnvCOTvfTOyby58C19qZvO5ZeSIKnYpBFB5QmbspAZK8gE7ZJYOxTZUZJVu1wiHJ0Hyftpmy3r29pJSTGxzRmldtLOL13t5fjUncxp055jeTqhJRZWteKLrUU2uPFJoOF7Vs2xWO+Rat8l8cNlOQCm2jMDf4XIdPcfBl6pyWw= 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.189 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.252]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4c1vV82RYxzdcD3; Wed, 13 Aug 2025 11:48:16 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 1B457180B62; Wed, 13 Aug 2025 11:52:36 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:35 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 09/16] Docs/admin-guide/mm/damon/usage: document addr_unit file Date: Wed, 13 Aug 2025 13:06:59 +0800 Message-ID: <20250813050706.1564229-10-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- 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 cffa320ead88..fd183cd09ef2 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.34.1 From nobody Sat Oct 4 21:02:18 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 ADD892BE628 for ; Wed, 13 Aug 2025 03:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057162; cv=none; b=aaAPKBEa++4lK31Xpt1VsDCgQOE2bsCRRieu8Q3bqMYRr9Fxw6Uaj+zLXRiMMoh7JtpRkd1vRiXG7nTMnlYCVQoRREbmOKwwxv6eF5GJUHtyxFAM4HLL33G3SUFF+Qppbt9kic6xM/kmAs90rOyRvYM+37f+PuhX5t+jVBgr6Oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057162; c=relaxed/simple; bh=tHivql+8yY5N+pKKO2AHPDUGB53gkQkeLOh8st5HaU0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YTNFOFCbBoD53NivF0e16uUBZpMFcP0d3eRFeOI3Fu9ayIDrDuw3ZF5oqmzIDO7hGKdh0EA1y7SE3x++YuCYz6jRYjUPOLWy05HHuw7w+gq8TGJWJGfKO+UXlRTh0Ov3Hs/qenc8Lw74ds8yzmwiJZO8peq5plIYv37gIDRrCcA= 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.189 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.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4c1vV90jyvzdcGJ; Wed, 13 Aug 2025 11:48:17 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id D403714020C; Wed, 13 Aug 2025 11:52:36 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:36 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 10/16] Docs/ABI/damon: document addr_unit file Date: Wed, 13 Aug 2025 13:07:00 +0800 Message-ID: <20250813050706.1564229-11-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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 --- 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..cf4d66bd119d 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: Apr 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.34.1 From nobody Sat Oct 4 21:02:18 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 A6F682BE05F for ; Wed, 13 Aug 2025 03:52:39 +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=1755057163; cv=none; b=Rqm2o8zFKipXvCHuVsU2BDNag1fKmZY7bvHFKYrjSqNBB0gxNw0LV2WeMCdkpTWakeYImaUv/UeXUxw+OADnUWJI9kshM0yI2jdZYeGgGMtacIWydZDaZobSJt1LIGBsTJJCOnpP98ujE0KOmSrW1+SAt8UdqvjUWkYOe8F4JSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057163; c=relaxed/simple; bh=NPl6Roqme+Eca9XUDIdnx22Kx5TjGaW/ZJ+9UNI8550=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UEg1OhqTIIpNdLlKTsVx+G/Cq8TSuvzk5N4VnjX5rn+3ydDl+sUcuLfzU+WpAarz0MvoChto6v2Scq3aNxqK8jetEQeIzQJRg2iZL87O+38bbVS8dWXUbXNLKT8GRio5SkFctqoizDSZpDCvDU1w9sKSTDlgG9iRNIZ2FQMhgHY= 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 4c1vWv5tP6z1R902; Wed, 13 Aug 2025 11:49:47 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id AB8D114027A; Wed, 13 Aug 2025 11:52:37 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:36 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 11/16] mm/damon: add addr_unit for DAMON_RECLAIM and LRU_SORT Date: Wed, 13 Aug 2025 13:07:01 +0800 Message-ID: <20250813050706.1564229-12-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" In module DAMON_RECLAIM and DAMON_LRU_SORT, the damon_ctx is independent of the core, necessitating dedicated addr_unit integration for these features. Additionally, if the input monitor_region_start and monitor_region_end are both 0 while addr_unit is set to a non-zero valuethe default system RAM range should be divided by addr_unit. Signed-off-by: Quanmin Yan --- include/linux/damon.h | 4 +++- mm/damon/core.c | 14 ++++++++++---- mm/damon/lru_sort.c | 16 +++++++++++++--- mm/damon/modules-common.c | 5 ++++- mm/damon/modules-common.h | 2 +- mm/damon/reclaim.c | 16 +++++++++++++--- mm/damon/stat.c | 2 +- 7 files changed, 45 insertions(+), 14 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index b85c6c669cd0..1b7b4cf1a3c5 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -942,7 +942,9 @@ int damon_call(struct damon_ctx *ctx, struct damon_call= _control *control); int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control); =20 int damon_set_region_biggest_system_ram_default(struct damon_target *t, - unsigned long *start, unsigned long *end); + unsigned long *start, + unsigned long *end, + unsigned long addr_unit); =20 #endif /* CONFIG_DAMON */ =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 1a8d3009d606..803c30f64b94 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2714,6 +2714,7 @@ static bool damon_find_biggest_system_ram(unsigned lo= ng *start, * @t: The monitoring target to set the region. * @start: The pointer to the start address of the region. * @end: The pointer to the end address of the region. + * @addr_unit: Scale factor for core to ops address conversion. * * This function sets the region of @t as requested by @start and @end. I= f the * values of @start and @end are zero, however, this function finds the bi= ggest @@ -2724,16 +2725,21 @@ static bool damon_find_biggest_system_ram(unsigned = long *start, * Return: 0 on success, negative error code otherwise. */ int damon_set_region_biggest_system_ram_default(struct damon_target *t, - unsigned long *start, unsigned long *end) + unsigned long *start, + unsigned long *end, + unsigned long addr_unit) { struct damon_addr_range addr_range; =20 if (*start > *end) return -EINVAL; =20 - if (!*start && !*end && - !damon_find_biggest_system_ram(start, end)) - return -EINVAL; + if (!*start && !*end) { + if (!damon_find_biggest_system_ram(start, end) || !addr_unit) + return -EINVAL; + *start /=3D addr_unit; + *end /=3D addr_unit; + } =20 addr_range.start =3D *start; addr_range.end =3D *end; diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 151a9de5ad8b..8107d08c5e4b 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -111,6 +111,14 @@ module_param(monitor_region_start, ulong, 0600); static unsigned long monitor_region_end __read_mostly; module_param(monitor_region_end, ulong, 0600); =20 +/* + * Scale factor for DAMON_LRU_SORT to ops address conversion. + * + * This parameter is used to convert to the actual physical address. + */ +static unsigned long addr_unit __read_mostly =3D 1; +module_param(addr_unit, ulong, 0600); + /* * PID of the DAMON thread * @@ -194,7 +202,8 @@ static int damon_lru_sort_apply_parameters(void) unsigned int hot_thres, cold_thres; int err; =20 - err =3D damon_modules_new_paddr_ctx_target(¶m_ctx, ¶m_target); + err =3D damon_modules_new_paddr_ctx_target(¶m_ctx, ¶m_target, + addr_unit); if (err) return err; =20 @@ -221,7 +230,8 @@ static int damon_lru_sort_apply_parameters(void) =20 err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, - &monitor_region_end); + &monitor_region_end, + addr_unit); if (err) goto out; err =3D damon_commit_ctx(ctx, param_ctx); @@ -323,7 +333,7 @@ MODULE_PARM_DESC(enabled, =20 static int __init damon_lru_sort_init(void) { - int err =3D damon_modules_new_paddr_ctx_target(&ctx, &target); + int err =3D damon_modules_new_paddr_ctx_target(&ctx, &target, 1); =20 if (err) goto out; diff --git a/mm/damon/modules-common.c b/mm/damon/modules-common.c index 86d58f8c4f63..613b7cc99368 100644 --- a/mm/damon/modules-common.c +++ b/mm/damon/modules-common.c @@ -13,9 +13,10 @@ * Allocate, set, and return a DAMON context for the physical address spac= e. * @ctxp: Pointer to save the point to the newly created context * @targetp: Pointer to save the point to the newly created target + * @addr_unit: Scale factor for modules to ops address conversion. */ int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp, - struct damon_target **targetp) + struct damon_target **targetp, unsigned long addr_unit) { struct damon_ctx *ctx; struct damon_target *target; @@ -24,6 +25,8 @@ int damon_modules_new_paddr_ctx_target(struct damon_ctx *= *ctxp, if (!ctx) return -ENOMEM; =20 + ctx->addr_unit =3D addr_unit; + if (damon_select_ops(ctx, DAMON_OPS_PADDR)) { damon_destroy_ctx(ctx); return -EINVAL; diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h index f103ad556368..c7048a449321 100644 --- a/mm/damon/modules-common.h +++ b/mm/damon/modules-common.h @@ -46,4 +46,4 @@ 0400); =20 int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp, - struct damon_target **targetp); + struct damon_target **targetp, unsigned long addr_unit); diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 3c71b4596676..0e11b121d693 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -128,6 +128,14 @@ module_param(monitor_region_start, ulong, 0600); static unsigned long monitor_region_end __read_mostly; module_param(monitor_region_end, ulong, 0600); =20 +/* + * Scale factor for DAMON_RECLAIM to ops address conversion. + * + * This parameter is used to convert to the actual physical address. + */ +static unsigned long addr_unit __read_mostly =3D 1; +module_param(addr_unit, ulong, 0600); + /* * Skip anonymous pages reclamation. * @@ -190,7 +198,8 @@ static int damon_reclaim_apply_parameters(void) struct damos_filter *filter; int err; =20 - err =3D damon_modules_new_paddr_ctx_target(¶m_ctx, ¶m_target); + err =3D damon_modules_new_paddr_ctx_target(¶m_ctx, ¶m_target, + addr_unit); if (err) return err; =20 @@ -229,7 +238,8 @@ static int damon_reclaim_apply_parameters(void) =20 err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, - &monitor_region_end); + &monitor_region_end, + addr_unit); if (err) goto out; err =3D damon_commit_ctx(ctx, param_ctx); @@ -327,7 +337,7 @@ MODULE_PARM_DESC(enabled, =20 static int __init damon_reclaim_init(void) { - int err =3D damon_modules_new_paddr_ctx_target(&ctx, &target); + int err =3D damon_modules_new_paddr_ctx_target(&ctx, &target, 1); =20 if (err) goto out; diff --git a/mm/damon/stat.c b/mm/damon/stat.c index 87bcd8866d4b..ae7377e7409f 100644 --- a/mm/damon/stat.c +++ b/mm/damon/stat.c @@ -181,7 +181,7 @@ static struct damon_ctx *damon_stat_build_ctx(void) if (!target) goto free_out; damon_add_target(ctx, target); - if (damon_set_region_biggest_system_ram_default(target, &start, &end)) + if (damon_set_region_biggest_system_ram_default(target, &start, &end, ctx= ->addr_unit)) goto free_out; return ctx; free_out: --=20 2.34.1 From nobody Sat Oct 4 21:02:18 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 2A2772BE7CF for ; Wed, 13 Aug 2025 03:52:40 +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=1755057165; cv=none; b=crFQxvtcW5Qc6QxtvqGluKjqDYcz5Nop+ZwJuhUnWRzXlIxyKf+4Zp03DKxM5VypFbMw0+RaNW2CtdrJIks3R4yZ1fHqbLjxwa0wvbLJYSIWCRPId8Qw3shopk+SlbVTc2/cnKOSy1u8593t5QWyqTKX/wssdlBCzrr9jR7TcK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057165; c=relaxed/simple; bh=K8zueaRJo3gNUjC+lIEOH6g3TS9WguEf58BxphKiDew=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CZqpqh800qTtVnGaypPvF8dy9xYMXumyyP9tNcLIFYQEKmINMfWkP/tR7SZdRP8OdOR66zOextlJQ3rrjKXy8GnedrpIyoNOCYtxsFpoMb0WX2EVYOb+tI8s2CluEXMdNhAK+27jS5xVWgqeJ3UlvkKR++rbw67o+mkVyKY99t0= 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 4c1vZ21RvTztTBG; Wed, 13 Aug 2025 11:51:38 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 70073180064; Wed, 13 Aug 2025 11:52:38 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:37 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 12/16] mm/damon: add damon_ctx->min_region and damon_target->min_region Date: Wed, 13 Aug 2025 13:07:02 +0800 Message-ID: <20250813050706.1564229-13-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) 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_region to change DAMON_MIN_REGION from a global macro value to per-context variable, let target inherit the min_region from its associated ctx to avoid excessive passing of ctx. [1] https://lore.kernel.org/all/527714dd-0e33-43ab-bbbd-d89670ba79e7@huawei= .com Signed-off-by: Quanmin Yan --- include/linux/damon.h | 7 ++++++- mm/damon/core.c | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 1b7b4cf1a3c5..aa045dcb5b5d 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -88,6 +88,7 @@ struct damon_region { /** * struct damon_target - Represents a monitoring target. * @pid: The PID of the virtual address space to monitor. + * @min_region: Minimum Region Size. * @nr_regions: Number of monitoring target regions of this target. * @regions_list: Head of the monitoring target regions of this target. * @list: List head for siblings. @@ -95,10 +96,12 @@ struct damon_region { * Each monitoring context could have multiple targets. For example, a co= ntext * for virtual memory address spaces could have multiple target processes.= The * @pid should be set for appropriate &struct damon_operations including t= he - * virtual address spaces monitoring operations. + * virtual address spaces monitoring operations. The @min_region Keeps con= sistent + * with the associated monitoring context. */ struct damon_target { struct pid *pid; + unsigned long min_region; unsigned int nr_regions; struct list_head regions_list; struct list_head list; @@ -747,6 +750,7 @@ struct damon_attrs { * * @ops: Set of monitoring operations for given use cases. * @addr_unit: Scale factor for core to ops address conversion. + * @min_region: Minimum Region Size. * @adaptive_targets: Head of monitoring targets (&damon_target) list. * @schemes: Head of schemes (&damos) list. */ @@ -789,6 +793,7 @@ struct damon_ctx { =20 struct damon_operations ops; unsigned long addr_unit; + unsigned long min_region; =20 struct list_head adaptive_targets; struct list_head schemes; diff --git a/mm/damon/core.c b/mm/damon/core.c index 803c30f64b94..b162aa1156fc 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -245,16 +245,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)); + t->min_region), + ALIGN(range->end, t->min_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); + t->min_region); + last->ar.end =3D ALIGN(range->end, t->min_region); =20 /* fill possible holes in the range */ err =3D damon_fill_regions_holes(first, last, t); @@ -472,6 +472,7 @@ struct damon_target *damon_new_target(void) =20 t->pid =3D NULL; t->nr_regions =3D 0; + t->min_region =3D DAMON_MIN_REGION; INIT_LIST_HEAD(&t->regions_list); INIT_LIST_HEAD(&t->list); =20 @@ -480,6 +481,7 @@ struct damon_target *damon_new_target(void) =20 void damon_add_target(struct damon_ctx *ctx, struct damon_target *t) { + t->min_region =3D ctx->min_region; list_add_tail(&t->list, &ctx->adaptive_targets); } =20 @@ -545,6 +547,7 @@ struct damon_ctx *damon_new_ctx(void) ctx->attrs.max_nr_regions =3D 1000; =20 ctx->addr_unit =3D 1; + ctx->min_region =3D DAMON_MIN_REGION; =20 INIT_LIST_HEAD(&ctx->adaptive_targets); INIT_LIST_HEAD(&ctx->schemes); @@ -1181,6 +1184,14 @@ static int damon_commit_targets( return 0; } =20 +static void damon_sync_target_min_region(struct damon_ctx *ctx) +{ + struct damon_target *t; + + damon_for_each_target(t, ctx) + t->min_region =3D ctx->min_region; +} + /** * damon_commit_ctx() - Commit parameters of a DAMON context to another. * @dst: The commit destination DAMON context. @@ -1216,6 +1227,8 @@ 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 ? : 1; + dst->min_region =3D max(DAMON_MIN_REGION / dst->addr_unit, 1); + damon_sync_target_min_region(dst); =20 return 0; } @@ -1248,8 +1261,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_region) + sz =3D ctx->min_region; =20 return sz; } @@ -1632,11 +1645,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, t->min_region); if (!sz_to_skip) { - if (damon_sz_region(r) <=3D DAMON_MIN_REGION) + if (damon_sz_region(r) <=3D t->min_region) return true; - sz_to_skip =3D DAMON_MIN_REGION; + sz_to_skip =3D t->min_region; } damon_split_region_at(t, r, sz_to_skip); r =3D damon_next_region(r); @@ -1678,8 +1691,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, t->min_region); + end =3D ALIGN_DOWN(filter->addr_range.end, t->min_region); =20 /* inside the range */ if (start <=3D r->ar.start && r->ar.end <=3D end) { @@ -1850,7 +1863,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_region); if (!sz) goto update_stat; damon_split_region_at(t, r, sz); @@ -2302,13 +2315,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 * t->min_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, t->min_region); /* Do not allow blank region */ if (sz_sub =3D=3D 0 || sz_sub >=3D sz_region) continue; --=20 2.34.1 From nobody Sat Oct 4 21:02:18 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 65D852BEC39 for ; Wed, 13 Aug 2025 03:52:41 +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=1755057163; cv=none; b=AcInThul9uld9hxthH8vBX21u5kTw9VOAmNs596nWKnOcVlBR4HpYLf5yOR0uPHEbNYfW7XUBdj6/QzsvKSzeMZltQR1Dhyfb9pDD0tXJwIUr9W1AHZJGPbjKMOdjja4B78lesmV3gyRuB/xVLIwb8Xcfv7hm/WBBQwtOqWnYBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057163; c=relaxed/simple; bh=6OQWbs0ie8Bbvcb/zi1GEW9dbd6YPXGmply5Lej6GMw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J9E2lo8RRhP39e8LOQkPp8dJd4e77xWYMwZCL7gmOykcFOkkune7/4sd7tbLStbOZiGXwhU01vWoU04b2VmvAbisqcRbOQylfDayJW9tQZ4K2ep4OdUGCOSGSGniUPwfkVny+rF6FRQVR3G5Hi3a4eTYyNvCM1CMxrbPtij0DMk= 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.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4c1vZ26v1JztTC0; Wed, 13 Aug 2025 11:51:38 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 37FD5140202; Wed, 13 Aug 2025 11:52:39 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:38 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 13/16] mm/damon/sysfs: ensure valid addr_unit setting in damon_sysfs_apply_inputs() Date: Wed, 13 Aug 2025 13:07:03 +0800 Message-ID: <20250813050706.1564229-14-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" By calling damon_sysfs_turn_damon_on(), the execution of damon_commit_ctx() can be bypassed. Therefore, it is necessary to prevent ctx->addr_unit from being set to 0 in damon_sysfs_apply_inputs() and update min_region to avoid potential issues. Signed-off-by: Quanmin Yan --- mm/damon/sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index bea782b0a711..122824776c1d 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1422,7 +1422,8 @@ 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; + ctx->addr_unit =3D sys_ctx->addr_unit ? : 1; + ctx->min_region =3D max(DAMON_MIN_REGION / ctx->addr_unit, 1); err =3D damon_sysfs_set_attrs(ctx, sys_ctx->attrs); if (err) return err; --=20 2.34.1 From nobody Sat Oct 4 21:02:18 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 D961F2BEFF6 for ; Wed, 13 Aug 2025 03:52:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057164; cv=none; b=qMgyzmU4PmSu+gPx3u2lNxg38/jniOuCPHfS8MMWzz3ksOhWm/tXLGAHHd1qABbRK6QwxXcfHrnfHYgB5V0k7QZlkUMIomJr+qM8jbb4OEIsLTjlrN0cN4a2hpuFJnbaRymGazKJUN96jAalGbQ8zAnmGViQ9Q8vW9+lxRnrLjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057164; c=relaxed/simple; bh=10qd6fSly3ctGc4adVw8duzY13qi9J1PB82YZSHdMOk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rD4u65osygW8WQpveB1OmzjrPK0WLefQ+Dnv6mY7DV6ZqGeo8lt03OyFjkDU25oJPNyElMR6oknf8W921mPiN99NsWW0s23VFuheqapWk1c9qscidFoveE0KDBqHEYTA7++09cLls4Twmxyezah2lZUcrKoC8ek2q81oQI4XnzE= 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.190 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 szxga04-in.huawei.com (SkyGuard) with ESMTP id 4c1vVD3dxvz2Cg76; Wed, 13 Aug 2025 11:48:20 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 07C2F140109; Wed, 13 Aug 2025 11:52:40 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:39 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 14/16] mm/damon/core: convert sz to byte units when updating state Date: Wed, 13 Aug 2025 13:07:04 +0800 Message-ID: <20250813050706.1564229-15-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" After introducing ctx->addr_unit, the unit of sz might not be in bytes. However, sz_applied is returned in bytes after processing by paddr. To maintain external consistency, sz is converted to byte units when updating the state. Signed-off-by: Quanmin Yan --- mm/damon/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index b162aa1156fc..bc764f9dc5c5 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1889,7 +1889,9 @@ static void damos_apply_scheme(struct damon_ctx *c, s= truct damon_target *t, r->age =3D 0; =20 update_stat: - damos_update_stat(s, sz, sz_applied, sz_ops_filter_passed); + damos_update_stat(s, + sz * (c->ops.id =3D=3D DAMON_OPS_PADDR ? c->addr_unit : 1), + sz_applied, sz_ops_filter_passed); } =20 static void damon_do_apply_schemes(struct damon_ctx *c, --=20 2.34.1 From nobody Sat Oct 4 21:02:18 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 ABE962BFC9D for ; Wed, 13 Aug 2025 03:52:42 +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=1755057166; cv=none; b=Xy9VkD8YW2WATcIDsX8zCSHHy4C1BBCspAHcpgj4g2RBU7q3djujYmFbiK5GgIBIQuQIBBtl/Kuz5fuFJ/lFjDBJzhcJQ+Y4CtDH+8ovd0jtLnKQlRRVEA3qLUpebfLGGk1HnbqyYofgpxbnJTKSkdq6oeaN6L0ifSWzmkpNhZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057166; c=relaxed/simple; bh=NFkQ0BjAyA9lbIoCn/gcSJKu0cBcu4WTTcpeERtypeQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BK5Ae7w/QsXIBDReMluH1CDcvYffbfYatcvqOOm3/ZpqcGyslKcMLTECb5Rf9JXktkEK3m/lk5Itb7py2BC6DIR7tdxk7Sik8baPH4Mbv+3bmqpKF1lrtbPGU+SzSk7/jKxOE7w/WVZiQse2Y4L6+NitVQIe0if+A+1RiyEJ0oM= 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.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c1vWy6pGfz1R91H; Wed, 13 Aug 2025 11:49:50 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id CAB9B1401F2; Wed, 13 Aug 2025 11:52:40 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:40 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 15/16] mm/damon: the byte statistics data type in damos_stat uses unsigned long long Date: Wed, 13 Aug 2025 13:07:05 +0800 Message-ID: <20250813050706.1564229-16-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" For 32-bit systems, damos_stat now uses unsigned long long for byte statistics data to avoid integer overflow risks inherent in the previous design. Signed-off-by: Quanmin Yan --- include/linux/damon.h | 6 +++--- mm/damon/modules-common.h | 4 ++-- mm/damon/sysfs-schemes.c | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index aa045dcb5b5d..d85850cf06c5 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -333,10 +333,10 @@ struct damos_watermarks { */ struct damos_stat { unsigned long nr_tried; - unsigned long sz_tried; + unsigned long long sz_tried; unsigned long nr_applied; - unsigned long sz_applied; - unsigned long sz_ops_filter_passed; + unsigned long long sz_applied; + unsigned long long sz_ops_filter_passed; unsigned long qt_exceeds; }; =20 diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h index c7048a449321..ae45d0eb960e 100644 --- a/mm/damon/modules-common.h +++ b/mm/damon/modules-common.h @@ -36,11 +36,11 @@ #define DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(stat, try_name, \ succ_name, qt_exceed_name) \ module_param_named(nr_##try_name, stat.nr_tried, ulong, 0400); \ - module_param_named(bytes_##try_name, stat.sz_tried, ulong, \ + module_param_named(bytes_##try_name, stat.sz_tried, ullong, \ 0400); \ module_param_named(nr_##succ_name, stat.nr_applied, ulong, \ 0400); \ - module_param_named(bytes_##succ_name, stat.sz_applied, ulong, \ + module_param_named(bytes_##succ_name, stat.sz_applied, ullong, \ 0400); \ module_param_named(nr_##qt_exceed_name, stat.qt_exceeds, ulong, \ 0400); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 74056bcd6a2c..3c4882549a28 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -199,10 +199,10 @@ static const struct kobj_type damon_sysfs_scheme_regi= ons_ktype =3D { struct damon_sysfs_stats { struct kobject kobj; unsigned long nr_tried; - unsigned long sz_tried; + unsigned long long sz_tried; unsigned long nr_applied; - unsigned long sz_applied; - unsigned long sz_ops_filter_passed; + unsigned long long sz_applied; + unsigned long long sz_ops_filter_passed; unsigned long qt_exceeds; }; =20 @@ -226,7 +226,7 @@ static ssize_t sz_tried_show(struct kobject *kobj, stru= ct kobj_attribute *attr, struct damon_sysfs_stats *stats =3D container_of(kobj, struct damon_sysfs_stats, kobj); =20 - return sysfs_emit(buf, "%lu\n", stats->sz_tried); + return sysfs_emit(buf, "%llu\n", stats->sz_tried); } =20 static ssize_t nr_applied_show(struct kobject *kobj, @@ -244,7 +244,7 @@ static ssize_t sz_applied_show(struct kobject *kobj, struct damon_sysfs_stats *stats =3D container_of(kobj, struct damon_sysfs_stats, kobj); =20 - return sysfs_emit(buf, "%lu\n", stats->sz_applied); + return sysfs_emit(buf, "%llu\n", stats->sz_applied); } =20 static ssize_t sz_ops_filter_passed_show(struct kobject *kobj, @@ -253,7 +253,7 @@ static ssize_t sz_ops_filter_passed_show(struct kobject= *kobj, struct damon_sysfs_stats *stats =3D container_of(kobj, struct damon_sysfs_stats, kobj); =20 - return sysfs_emit(buf, "%lu\n", stats->sz_ops_filter_passed); + return sysfs_emit(buf, "%llu\n", stats->sz_ops_filter_passed); } =20 static ssize_t qt_exceeds_show(struct kobject *kobj, --=20 2.34.1 From nobody Sat Oct 4 21:02:18 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 AB2AC2C158E for ; Wed, 13 Aug 2025 03:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057165; cv=none; b=Syb03YgYrh9ut4pTnt77gijfG765QcxWeuqQ2SEoj9WrzDU2AXO5y9t+0pXmInPUxkwOaOJ84Faf8Kmu+/ywhUjfTlJuj4hR8ooEoadQWIXcc49tJHbpNLItXAjMw5PdxkCHC6aq+A4GyjeAxCDELspQZyUzARQIEFE75sW2now= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755057165; c=relaxed/simple; bh=+TtvvtkfcdQbySxJLg/HYRDdGbJtc9HKEZuMK+x1i0Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jxyZ239K3cqgG88+WjTG3elSDENvWDMSEv4im+A81Wl7PaH8yIWBfvTkm/qFu77ZcIeOZAYQWYG1S91zH1XbG4F4Sku6Nm8Nvs3SluAJx31QtcGsn7AQpaJoSZW6EGpwE40xouh1flQxj8E+8qAolE9JeZdFBkC5gyuLeJyk66w= 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.190 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 szxga04-in.huawei.com (SkyGuard) with ESMTP id 4c1vVG0VLFz2Cg7V; Wed, 13 Aug 2025 11:48:22 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 92E2A14027A; Wed, 13 Aug 2025 11:52:41 +0800 (CST) Received: from huawei.com (10.175.113.32) 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; Wed, 13 Aug 2025 11:52:40 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [RFC PATCH -next 16/16] mm/damon/core: handle quota->esz overflow issues Date: Wed, 13 Aug 2025 13:07:06 +0800 Message-ID: <20250813050706.1564229-17-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com> References: <20250813050706.1564229-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: kwepems100002.china.huawei.com (7.221.188.206) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" In the original quota enforcement implementation, the traffic calculation multiplied A by 1000000 due to time unit conversion, making it highly prone to overflow on 32-bit systems: damos_set_effective_quota if (quota->total_charged_ns) throughput =3D quota->total_charged_sz * 1000000 / quota->total_charged_ns; Requiring total_charged_sz to be less than 4GB/1000000 is unreasonable. Additionally, when overflow occurs and causes quota->esz to become extremely small, the subsequent damos_apply_scheme logic permanently sets sz to 0, while quota stop updating, ultimately leading to complete functional failure: damos_apply_scheme if (quota->esz && quota->charged_sz + sz > quota->esz) sz =3D ALIGN_DOWN(quota->esz - quota->charged_sz, DAMON_MIN_REGION); Total charged stats use the unsigned long long data type to reduce overflow risk, with data reset capability after overflow occurs. Signed-off-by: Quanmin Yan --- include/linux/damon.h | 4 ++-- mm/damon/core.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index d85850cf06c5..45aab331dfb7 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -247,8 +247,8 @@ struct damos_quota { =20 /* private: */ /* For throughput estimation */ - unsigned long total_charged_sz; - unsigned long total_charged_ns; + unsigned long long total_charged_sz; + unsigned long long total_charged_ns; =20 /* For charging the quota */ unsigned long charged_sz; diff --git a/mm/damon/core.c b/mm/damon/core.c index bc764f9dc5c5..5e05fdd91c12 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #define CREATE_TRACE_POINTS #include @@ -2059,8 +2060,8 @@ static unsigned long damos_quota_score(struct damos_q= uota *quota) */ static void damos_set_effective_quota(struct damos_quota *quota) { - unsigned long throughput; - unsigned long esz =3D ULONG_MAX; + unsigned long long throughput; + unsigned long long esz =3D ULLONG_MAX; =20 if (!quota->ms && list_empty("a->goals)) { quota->esz =3D quota->sz; @@ -2077,11 +2078,16 @@ static void damos_set_effective_quota(struct damos_= quota *quota) } =20 if (quota->ms) { - if (quota->total_charged_ns) - throughput =3D quota->total_charged_sz * 1000000 / - quota->total_charged_ns; - else + if (quota->total_charged_ns && + likely(quota->total_charged_sz < ULLONG_MAX / 1000000)) { + throughput =3D div64_u64(quota->total_charged_sz * 1000000, + quota->total_charged_ns); + } else { throughput =3D PAGE_SIZE * 1024; + /* Reset the variable when an overflow occurs */ + quota->total_charged_ns =3D 0; + quota->total_charged_sz =3D 0; + } esz =3D min(throughput * quota->ms, esz); } =20 --=20 2.34.1