Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6356344rwb; Tue, 22 Nov 2022 12:10:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6MH+YAPz38R+FGWoWa1wgO9zIPU9CGsUAjdAby8uI72w7cpoURxuE0e2NnXC8WFc+LpINA X-Received: by 2002:a17:906:560c:b0:7ae:5884:81b1 with SMTP id f12-20020a170906560c00b007ae588481b1mr6360353ejq.155.1669147811025; Tue, 22 Nov 2022 12:10:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669147811; cv=none; d=google.com; s=arc-20160816; b=iYhwix4XjbjRBcqrkVMPBAR1JWKwY7GpgL7UYfxEJ+uycwavOv+EU+Zn5F7OrFf4Bm rqjwx3epWn+IStXaU9rGB+O0UfJr+OdgBb2nKljCm5O1RAwS1gQWt2EESshikc/9BsnF yeAoNRfcEBU+krDzC0QEsCNSOMSWrkXKE/M83SvoQmcbva1FXponBfV2qxFv2ixSDVv1 cxTQP1H9jXPT9DmMVl2XT2tZHY4eK+25XHqyzSEk8mKFO/Nz78WwlHbGXv/9FDMJggKy 9xMVWsws8NNoJxszioPOnNc+dBa/go52NqSYqaHbBpLmMdY0rEr1Is+WGS6LlgOo5IBx RBsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zowx84FG8w5R5K6uw0UVZlJgHnG18KVzPrFpNoa8G1g=; b=yisRPvUBLASWmP4INLJAa8m4pvQM7PCH6rCe5ExNkCR1cRGUM2dLoReexxTXCNge/2 /sB4tQMGFpCh4MFApsQ21by6/yvW/xhrBQo0haODF+bGoN64DyxP+Kr6Dj1uknIjEGwx DvVJeTm86hXK1b8nxlsnk5rAogqsITlBbTk2vLfo+JbT0hFIELECdSFwWBiwQUzWaBrA ZfPLfpdwVOni0UlQAjERUC5OOXSRBXfhKWRRjYDOAwbiWuXu7UL0lGOktW5yf9HATKSG qKUC0K83KGJYnrfhK1q1fBw+fh9zXUoordy5nSqsg5X1aPaPbzMmo45X5heaEphTaBTf yRhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d9awUBAC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk18-20020a1709077f9200b0078849a014e9si15289543ejc.196.2022.11.22.12.09.47; Tue, 22 Nov 2022 12:10:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d9awUBAC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234549AbiKVTs4 (ORCPT + 90 others); Tue, 22 Nov 2022 14:48:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234578AbiKVTso (ORCPT ); Tue, 22 Nov 2022 14:48:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94DEA57B78; Tue, 22 Nov 2022 11:48:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 007EA61759; Tue, 22 Nov 2022 19:48:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8418C433D6; Tue, 22 Nov 2022 19:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669146518; bh=fELDYP7X7g2hQl01HL1seDQ0enwlGxaSh2Vjv+ZYToU=; h=From:To:Cc:Subject:Date:From; b=d9awUBACiXT6NtF2V4ad/eJjEaQCigkXO/j1aQoYsuFW6RdPlhNvCz352QKphf6uv YeHKeIHQLBktbxEvc0HOp+LzekGhy5IIrfe6vuqQZ0djQb/haE5Rq+vjd2jxYOP3AB bzUfe4vQLX7dcyuwlXhqofokrNoUPDH4XD832fhZ31mJAv3yjMpbSoctQF0+vJNA5a pJLEyOhcaZTvflI94IT8T66up2b/V6KJpR60+xl9uz4atP+qUNuq9fJzOYRWnXvWX5 yXFFaeNg50ZldZGB7nOgFqPk1bBpqglkmqfDflyfWghPpY5OZ37nRSKAcdsfSWB67p TOTO1D6eWMa7Q== From: SeongJae Park To: akpm@linux-foundation.org Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park , stable@vger.kernel.org Subject: [PATCH mm-hotfixes-unstable] mm/damon/sysfs: fix wrong empty schemes assumption under online tuning in damon_sysfs_set_schemes() Date: Tue, 22 Nov 2022 19:48:31 +0000 Message-Id: <20221122194831.3472-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: # 5.19.y Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 5ce403378c20..07e5f1bdf025 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2283,12 +2283,54 @@ static struct damos *damon_sysfs_mk_scheme( &wmarks); } +static void damon_sysfs_update_scheme(struct damos *scheme, + struct damon_sysfs_scheme *sysfs_scheme) +{ + struct damon_sysfs_access_pattern *access_pattern = + sysfs_scheme->access_pattern; + struct damon_sysfs_quotas *sysfs_quotas = sysfs_scheme->quotas; + struct damon_sysfs_weights *sysfs_weights = sysfs_quotas->weights; + struct damon_sysfs_watermarks *sysfs_wmarks = sysfs_scheme->watermarks; + + scheme->pattern.min_sz_region = access_pattern->sz->min; + scheme->pattern.max_sz_region = access_pattern->sz->max; + scheme->pattern.min_nr_accesses = access_pattern->nr_accesses->min; + scheme->pattern.max_nr_accesses = access_pattern->nr_accesses->max; + scheme->pattern.min_age_region = access_pattern->age->min; + scheme->pattern.max_age_region = access_pattern->age->max; + + scheme->action = sysfs_scheme->action; + + scheme->quota.ms = sysfs_quotas->ms; + scheme->quota.sz = sysfs_quotas->sz; + scheme->quota.reset_interval = sysfs_quotas->reset_interval_ms; + scheme->quota.weight_sz = sysfs_weights->sz; + scheme->quota.weight_nr_accesses = sysfs_weights->nr_accesses; + scheme->quota.weight_age = sysfs_weights->age; + + scheme->wmarks.metric = sysfs_wmarks->metric; + scheme->wmarks.interval = sysfs_wmarks->interval_us; + scheme->wmarks.high = sysfs_wmarks->high; + scheme->wmarks.mid = sysfs_wmarks->mid; + scheme->wmarks.low = sysfs_wmarks->low; +} + static int damon_sysfs_set_schemes(struct damon_ctx *ctx, struct damon_sysfs_schemes *sysfs_schemes) { - int i; + struct damos *scheme, *next; + int i = 0; + + damon_for_each_scheme_safe(scheme, next, ctx) { + if (i < sysfs_schemes->nr) + damon_sysfs_update_scheme(scheme, + sysfs_schemes->schemes_arr[i]); + else + damon_destroy_scheme(scheme); + i++; + } - for (i = 0; i < sysfs_schemes->nr; i++) { + for (; i < sysfs_schemes->nr; i++) { struct damos *scheme, *next; scheme = damon_sysfs_mk_scheme(sysfs_schemes->schemes_arr[i]); -- 2.25.1