Re: [PATCH mm-hotfixes-unstable] mm/damon/sysfs: fix wrong empty schemes assumption under online tuning in damon_sysfs_set_schemes()

From: SeongJae Park
Date: Tue Nov 22 2022 - 17:32:58 EST


On Tue, 22 Nov 2022 19:53:33 +0000 SeongJae Park <sj@xxxxxxxxxx> wrote:

> Hi Andrew,
>
> On Tue, 22 Nov 2022 19:48:31 +0000 SeongJae Park <sj@xxxxxxxxxx> wrote:
>
> > Commit da87878010e5 ("mm/damon/sysfs: support online inputs update")
> > made 'damon_sysfs_set_schemes()' to be called for running DAMON context,
> > which could have schemes. In the case, DAMON sysfs interface is
> > supposed to update, remove, or add schemes to reflect the sysfs files.
> > However, the code is assuming the DAMON context wouldn't have schemes at
> > all, and therefore creates and adds new schemes. As a result, the code
> > doesn't work as intended for online schemes tuning and could have more
> > than expected memory footprint. The schemes are all in the DAMON
> > context, so it doesn't leak the memory, though.
> >
> > Remove the wrong asssumption (the DAMON context wouldn't have schemes)
> > in 'damon_sysfs_set_schemes()' to fix the bug.
> >
> > Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update")
> > Cc: <stable@xxxxxxxxxxxxxxx> # 5.19.y
> > Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
>
> This patch is for a hotfix, so based on mm-hotfixes-unstable. And this makes a
> following sysfs refactoring patch, "mm/damon/sysfs: split out schemes directory
> implementation to separate file" conflicts. Below is the conflict resolved
> version of the patch. Please replace it with below one. Sorry for the
> inconvenience and thank you for your help in advance!
>
> ================================ 8< ===========================================
>
> From bfb5e978a34626f5b19ee777eeb3187323e6a546 Mon Sep 17 00:00:00 2001
> From: SeongJae Park <sj@xxxxxxxxxx>
> Date: Wed, 26 Oct 2022 22:59:41 +0000
> Subject: [PATCH mm-unstable] mm/damon/sysfs: split out schemes directory implementation to
> separate file
>
> DAMON sysfs interface for 'schemes' directory is implemented using about
> one thousand lines of code. It has no strong dependency with other
> parts of its file, so split it out to another file for better code
> management.
>
> Link: https://lkml.kernel.org/r/20221026225943.100429-11-sj@xxxxxxxxxx
> Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> ---
> mm/damon/Makefile | 2 +-
> mm/damon/sysfs-common.h | 22 +
> mm/damon/sysfs-schemes.c | 1068 ++++++++++++++++++++++++++++++++++++++
> mm/damon/sysfs.c | 1064 -------------------------------------
> 4 files changed, 1091 insertions(+), 1065 deletions(-)
> create mode 100644 mm/damon/sysfs-schemes.c
>
[...]
> diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> new file mode 100644
> index 000000000000..731a2314623c
> --- /dev/null
> +++ b/mm/damon/sysfs-schemes.c
[...]
> +static int damon_sysfs_set_schemes(struct damon_ctx *ctx,
> + struct damon_sysfs_schemes *sysfs_schemes)

Sorry, I made a mistake. This should be not static. Below is the fixed
version of the patch.

================================= 8< ==========================================