From patchwork Tue Nov 22 19:48:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 24531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2410243wrr; Tue, 22 Nov 2022 11:55:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf7shE2ViQxhi7hQa4VIJf3JU7wrxBeucm4R5xosnKwRuRrvWp/4J7EDPTloH24rSczeXOfE X-Received: by 2002:a63:e617:0:b0:41a:4bd4:f466 with SMTP id g23-20020a63e617000000b0041a4bd4f466mr13077012pgh.499.1669146933387; Tue, 22 Nov 2022 11:55:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669146933; cv=none; d=google.com; s=arc-20160816; b=ax8cQhPfTCiOcQyeQpQUcgGmd2ULVPNqoafIbEClwt/l6YybqhxkaBqKJYtL2LKX6M VDjRpnHaEhnUhbsabgXDaxUJAddIOZZZSlq50IWhn0CzYT3ksHJxnH81s/4oW13gLgi9 4X4WdwgQ6d0imnU5VOwIalg6VpWRZcKr3QW3dhr+niqi77129QsmE4LpzRApTI9BYfk9 LjhVr8OzaXPq8btFthY0FWKz24OPlrKfnS9VMqoupNBd5ycD2ukwiET97kOgydVIaItS HwDkVTjAWy5/lqJP1NYC9rQEwBLOGDxbrYoCLZHifRimDk2PvcNuz3U3S+aeThx60Ebl Kbug== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a170902e75200b00188e9ec511bsi15013299plf.113.2022.11.22.11.55.17; Tue, 22 Nov 2022 11:55:33 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750227414950713739?= X-GMAIL-MSGID: =?utf-8?q?1750227414950713739?= 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 Signed-off-by: SeongJae Park Signed-off-by: Andrew Morton Signed-off-by: SeongJae Park Signed-off-by: Andrew Morton --- 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]);