From nobody Fri Dec 19 15:00:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 092D446450; Mon, 26 Aug 2024 04:23:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646209; cv=none; b=q7AybhwyksWn2qlAu93PYoAr84y8x2Q9IqtjidZi2MylwuR2hFDpLnDUB3FiKCAvychuLC+kqpMYF/Pg8hg6+X0bJGJ2MmNUpqR5ROPFVI6wy+G+UvQTCet4xnRYu6+cKnsaqqpuxNVNniBOWpUQsCZzLmmOW70k9sFgm63UUnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646209; c=relaxed/simple; bh=AC0J/gaemr58bowZatGs1lVoNaCBAqyQ8IjIhHKBMDs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KUpXykTpE4qQAhA0X91kGViIu1KV63ZE2LX9Sy9ugPZJhZ58lEp2p3KgUQASbcQaJg9BpKozAa2Uijy8PGOgGoB4s/eobphSOPx5MhU6+kbFdk2VaKQZLxo+fYDKEQrFglKR89qSDJqdPdqxrEHQREMmAeoU7FPoMALuFHHo7/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DdZIct5F; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DdZIct5F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 496CBC4AF51; Mon, 26 Aug 2024 04:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724646208; bh=AC0J/gaemr58bowZatGs1lVoNaCBAqyQ8IjIhHKBMDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DdZIct5FgY14f39r9PJTSNx9KWZM02CHokBUpwLEj3RlL9e58paF4dVBckzZYJHV3 Rq5eIRwlsMA9JVx7rmU6KVE2QBRe7VRQe0681ySeKXRhDrYtm5mDQf8Nr73WHzKYi7 nznJ8ZBcGTrA2bVOlTOZut3J0Vq91mnMV+78qY/Ac31H9HT2jm1gq93wcChHXJbjYX lzbFXb/fiF29oba41xcYRu97hCGizUzeOOnJJyn/YkddZuEW5pUjpNE1lu1wc830io JucMQygfS/WqyYCpygUp0VBAveOS7ul6b9L+sP0KJIEkaoto5R5uMWYdsFWAQ9dVl0 EoUnFr0IX7Efg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] mm/damon/core: intorduce per-context region priorities histogram buffer Date: Sun, 25 Aug 2024 21:23:20 -0700 Message-Id: <20240826042323.87025-2-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240826042323.87025-1-sj@kernel.org> References: <20240826042323.87025-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce per-context buffer for region priority scores-total size histogram. Same to the per-quota one (->histogram of struct damos_quota), the new buffer is hidden from DAMON API users by being defined as a private field of DAMON context structure. It is dynamically allocated and de-allocated at the beginning and ending of the execution of the kdamond by kdamond_fn() itself. [1] commit 0742cadf5e4c ("mm/damon/lru_sort: adjust local variable to dynam= ic allocation") [2] https://lore.kernel.org/20240531122320.909060-1-yorha.op@gmail.com Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 ++ mm/damon/core.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index fcccaa9b9d54..6342d8f9b0fd 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -661,6 +661,8 @@ struct damon_ctx { unsigned long next_ops_update_sis; /* for waiting until the execution of the kdamond_fn is started */ struct completion kdamond_started; + /* for scheme quotas prioritization */ + unsigned long *regions_score_histogram; =20 /* public: */ struct task_struct *kdamond; diff --git a/mm/damon/core.c b/mm/damon/core.c index 84d9b0fd8ace..be3d05357667 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2019,6 +2019,10 @@ static int kdamond_fn(void *data) ctx->ops.init(ctx); if (ctx->callback.before_start && ctx->callback.before_start(ctx)) goto done; + ctx->regions_score_histogram =3D kmalloc_array(DAMOS_MAX_SCORE + 1, + sizeof(*ctx->regions_score_histogram), GFP_KERNEL); + if (!ctx->regions_score_histogram) + goto done; =20 sz_limit =3D damon_region_sz_limit(ctx); =20 @@ -2096,6 +2100,7 @@ static int kdamond_fn(void *data) ctx->callback.before_terminate(ctx); if (ctx->ops.cleanup) ctx->ops.cleanup(ctx); + kfree(ctx->regions_score_histogram); =20 pr_debug("kdamond (%d) finishes\n", current->pid); mutex_lock(&ctx->kdamond_lock); --=20 2.39.2 From nobody Fri Dec 19 15:00:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4C3C357CAC; Mon, 26 Aug 2024 04:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646209; cv=none; b=VltCM/H56vs9FeR9Gsaa9F+T6pJ4qgyId9GLTXwZzSq2jG7GDitieUsd7Pcny4SUTmEkJnhTfRrmtFZnLtCpzAhbokN4j27gD7P0LF2SoEgrXDic7iP8QgpeaTtmpfmEvChHF9+YHF97MFR61BJHvZ7yKQ9ueJz7WxmIYVb5A/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646209; c=relaxed/simple; bh=UHW9Q+oQECc2cZmhHjnUjTteD4lWCzsp9j3YCv5KfTc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CM45xKC95kr1t/TBtdPqS+C6nNabRgGAfT/+iJOXmHeFiEePq4LUYayRZ1VcV6E6dZKc+80xCRkT1FC6yQCWsyepBIBu5XQNfPf5fqblc1FiZ1sZRB7PW6MNy6ykiSu/xp/YoPJ/rPxDBNxq2Ae5SbLwaO+gEYylZ5DDeqFHWzU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=It+qUYQY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="It+qUYQY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF9C4C4AF52; Mon, 26 Aug 2024 04:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724646209; bh=UHW9Q+oQECc2cZmhHjnUjTteD4lWCzsp9j3YCv5KfTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=It+qUYQYI6bSGiBuQ7eQvfcSLKDhnTSOby0Gfr09tqVkz5soNjjwMncsbWCyBgWYw KIUCcHid4uZAuLNfiYE48GT2Fz/TLtJIMk93WIZXcYbq9Ux7L0OHPS1aSGaLLKbxsI Hzg/rT/iHuxN7d3EeKiu9G+9yYL9sKFzZEukxKdRaCyWZL/gWJGIuYE0dF3POnwzBt wOiALKG3z4HYIHJsb9EntuUgldbe3++qPlehVsVaA3c3Q6WXkU9klzTVSmARS6yQpM 3W+s+ZQbKJiJ57juiuAckFvMaZmKgV/0VwFXdQJ6BgbRbXfVLmV504mjgUkpzLnUig gWRVkzQ6WcBgA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] mm/damon/core: replace per-quota regions priority histogram buffer usage with per-context one Date: Sun, 25 Aug 2024 21:23:21 -0700 Message-Id: <20240826042323.87025-3-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240826042323.87025-1-sj@kernel.org> References: <20240826042323.87025-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the usage of per-quota region priorities histogram buffer with the per-context one. After this change, the per-quota histogram is not used by anyone, and hence it is ready to be removed. Signed-off-by: SeongJae Park --- mm/damon/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index be3d05357667..a1c32becfc73 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1623,13 +1623,16 @@ static void damos_adjust_quota(struct damon_ctx *c,= struct damos *s) return; =20 /* Fill up the score histogram */ - memset(quota->histogram, 0, sizeof(quota->histogram)); + memset(c->regions_score_histogram, 0, + sizeof(*c->regions_score_histogram) * + (DAMOS_MAX_SCORE + 1)); damon_for_each_target(t, c) { damon_for_each_region(r, t) { if (!__damos_valid_target(r, s)) continue; score =3D c->ops.get_scheme_score(c, t, r, s); - quota->histogram[score] +=3D damon_sz_region(r); + c->regions_score_histogram[score] +=3D + damon_sz_region(r); if (score > max_score) max_score =3D score; } @@ -1637,7 +1640,7 @@ static void damos_adjust_quota(struct damon_ctx *c, s= truct damos *s) =20 /* Set the min score limit */ for (cumulated_sz =3D 0, score =3D max_score; ; score--) { - cumulated_sz +=3D quota->histogram[score]; + cumulated_sz +=3D c->regions_score_histogram[score]; if (cumulated_sz >=3D quota->esz || !score) break; } --=20 2.39.2 From nobody Fri Dec 19 15:00:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DA8CF6F30E; Mon, 26 Aug 2024 04:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646209; cv=none; b=resD6N9L8ufpYmESvFAXdmwP+VFC+jR5dVw88uz+g7Z3ULwG/ygURO9PAeMSqPuNPJThB2Hv9/pONLNKE1jRn5a5DHJ85qP0G6mn9DwA/Sq8A4kGpVgaQ5+swbvc0jwjl5PFxRzh/prFg1gCXSzMR5mUQx6Ih0Ilf2Dw91m6x+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646209; c=relaxed/simple; bh=n5ClRs5YIXQT8CMYq5oeALUYRkNDMyxAjHzrI1UVrP0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kfp2MsxaEE1b7UVewwBKYxJ+qI/xDBuLJ8uvjQKsgVZhhuhlFHkBXpPkeuRW6wOX/w6gTR5Ts6t/SWHz8Non0wcn+2N9KG4Ki7DQKBpR2A3lvfyRicEvc21zw7SHQaPtZDHy3jR7wKrKy2z4brF78n5WH9/amJFM6ZnnXFxacjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=su1FSJ+k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="su1FSJ+k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61391C4AF55; Mon, 26 Aug 2024 04:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724646209; bh=n5ClRs5YIXQT8CMYq5oeALUYRkNDMyxAjHzrI1UVrP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=su1FSJ+kiS0GzuCEOWg1E6hJR1S4LhNnJ4sp+JK3RfLL+KW+mjJr0lSEFkdyouPD4 SxAjSLe6CNApUTwxE2wY9pSAt7LxTkVplkTBixMzP3f9FGpul3/0Jx4iS6YWuUiI90 QXKZTZAnEcbmbnXOSLjEyqrsJPQicwV/70w/V0S5e4CkwTO8HAn7D/TjJ8FYUdvibi 14nTMIXIIaIMLgwpATQcOJ6QC1qhLL3treWUkN9FIhGrcUzLOwXGiIOUIRJs+E5YbX hMHZq60WD3vH38VBrk1f5tSSQG/S/9Cxv7NTMwu6VdYqb5f0SY5KtYhiLNWI+bDNv3 uekw/S9J2ivBQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] mm/damon/core: remove per-scheme region priority histogram buffer Date: Sun, 25 Aug 2024 21:23:22 -0700 Message-Id: <20240826042323.87025-4-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240826042323.87025-1-sj@kernel.org> References: <20240826042323.87025-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Nobody is reading from or writing to the per-scheme region priorities histogram buffer. It is only wasting memory. Remove it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 6342d8f9b0fd..0ac8b862bdcb 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -242,7 +242,6 @@ struct damos_quota { unsigned long charge_addr_from; =20 /* For prioritization */ - unsigned long histogram[DAMOS_MAX_SCORE + 1]; unsigned int min_score; =20 /* For feedback loop */ --=20 2.39.2 From nobody Fri Dec 19 15:00:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C0CD377103; Mon, 26 Aug 2024 04:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646210; cv=none; b=Dyt37ZXjnzYUGeLSu5VamZdDegF7akL5A9Po6hlDlQny7KbY9LEdsuXQvJMBs7e9ALy/7LhRkPfSW1DmOl+ArY/0peyPJY/M8+NxRLQX9LLsd+S/3uEKkNLRqd+CgBwk4wfCsWuGD4C+xftyoYByIE0t8q4kV0WjM1QBxUm4tfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724646210; c=relaxed/simple; bh=8KWTe6g417NjxQYOu8DbwjfveiZLDo0pwWEWfK9DvjQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PNvrulF+hzWaIYFUNLQfOXCeJr4Mxn0qq7HcKYpgI1fsPxoZslxXBNG/zaXNDXwPqr7lqb1C7vkwNFPUl+IKv5tEOK+wSylT49mWWO52UxuFA8I+csH1om05ekY3RLl3fhVbjMoq7hmP4y6ewWcxUJ5ym3es0KlsDJTLClzk568= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qPWGxV5F; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qPWGxV5F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6A9BC4AF67; Mon, 26 Aug 2024 04:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724646210; bh=8KWTe6g417NjxQYOu8DbwjfveiZLDo0pwWEWfK9DvjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qPWGxV5FGARu1NIS/Xn8xAdpW19/evFCGNH3EP2m6L+LSg6KT4VeBp4oB/ThoQ45D iPkF6RN+oEnwI73janQ9Fh7Qk7qFKyntXTo0FUv8/LTRAKWsiQrAKE35iKKLamOuj5 45o59P11Egip5YnveSSZXeK+MNesvM3tWvaVbBtmwYZSCoGZEK2ReUJMYtKdChWlRJ zoN4nRQPQtNbNw0jTgRa0xMaYNz+8/NayjNYhNkHxyzt8p3dsYCwxqE5d+zsiA67Cm 2x9BkA4ElJZJ30BW8EukK17m/S4jApjRXW7HBTmWn2YEcdmq9VbmWi44jIH/SL0d0a azOewe0o615Mg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] Revert "mm/damon/lru_sort: adjust local variable to dynamic allocation" Date: Sun, 25 Aug 2024 21:23:23 -0700 Message-Id: <20240826042323.87025-5-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240826042323.87025-1-sj@kernel.org> References: <20240826042323.87025-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit 0742cadf5e4c080aa9bab323dfb234c37a86e884. The commit was introduced to avoid unnecessary usage of stack memory for per-scheme region priorities histogram buffer. The fix is nice, but the point of the fix looks not very clear if the commit message is not read together. That's mainly because the buffer is a private field, which means it is hidden from the DAMON API users. That's not the fault of the fix but the underlying data structure. Now the per-scheme histogram buffer is gone, so the problem that the commit was fixing is also removed. The use of kmemdup() has no more point but just making the code bit difficult to understand. Revert the fix. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 0b35bd5fb659..4af8fd4a390b 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -148,17 +148,12 @@ static struct damon_target *target; static struct damos *damon_lru_sort_new_scheme( struct damos_access_pattern *pattern, enum damos_action action) { - struct damos *damos; - struct damos_quota *quota =3D kmemdup(&damon_lru_sort_quota, - sizeof(damon_lru_sort_quota), GFP_KERNEL); - - if (!quota) - return NULL; + struct damos_quota quota =3D damon_lru_sort_quota; =20 /* Use half of total quota for hot/cold pages sorting */ - quota->ms =3D quota->ms / 2; + quota.ms =3D quota.ms / 2; =20 - damos =3D damon_new_scheme( + return damon_new_scheme( /* find the pattern, and */ pattern, /* (de)prioritize on LRU-lists */ @@ -166,12 +161,10 @@ static struct damos *damon_lru_sort_new_scheme( /* for each aggregation interval */ 0, /* under the quota. */ - quota, + "a, /* (De)activate this according to the watermarks. */ &damon_lru_sort_wmarks, NUMA_NO_NODE); - kfree(quota); - return damos; } =20 /* Create a DAMON-based operation scheme for hot memory regions */ --=20 2.39.2