Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp60785lqh; Mon, 6 May 2024 11:13:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXgW2FKh6/pRQhvwjVv5OqAgeodRlNPKf2ibeSUwALKXmdyI2qI3AVrbAPW28KkZoouZzZdqxzF3mFa/HJJ7FyjlCoIAXrXSE4tW4vrDg== X-Google-Smtp-Source: AGHT+IHVw4TIl+XQ5nVi7/CjzQ1eV5WLnlCrGoE0idZLbLnu4JhRDCUMlm5EqXWuSY4MmtMnFYHj X-Received: by 2002:a05:6512:3608:b0:51a:c2ec:72f9 with SMTP id f8-20020a056512360800b0051ac2ec72f9mr5941162lfs.49.1715019199287; Mon, 06 May 2024 11:13:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715019199; cv=pass; d=google.com; s=arc-20160816; b=L6PJ+vldNIOkv/iwZPgBTIXFRNxFZLPP6Blg4Bovav5XgD4+vxaAeVYNnM61IRkizy MGMogmQBnRXGbGh5o6gnEtkdI+XfQeF4/f3KpP+iqQPX7C3akO/jyp/HV5fPCET/KiDV f/3NlaY1ip9t0vm1Fy2rAc4mwHtzLhLxAKJPssbea1sxeKqjqlNDiNM9OlZWsG9X0Z+O N9QL6fnP/GWoSJZ4nFJA57bo4QynBDHfuIdu3KUdLKOk5VSfJHuiYkEKOBKmDNLHkcyh Ls2SQgISAABSSL0lbXUP46OTpN+bBwl+qMwyS2ghlbxsNmiRAzVywyKyx9kDIIOjZ2WQ gwXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=8/Ng1N1Z2EqPnVBvsCQp3RptDaVDlXRuyPl8HON9cQo=; fh=hcD51qppzMPKhVnmwM8Qt99E3knaYm1MF0KowtVKfFk=; b=uAfdxUdaW/twqtO6JuQ7B8omSg2/m8nb0eUqF0IcMG1y6cxMlZHIdU9OuNdQ4I+DQw 6QCoSp9TFW0FiE8AifdARdNa2EovvBfAtJJTBtLR4fn1OUKFV9sMJCUfNRHoA2DH8jGP 8UmIWQmNGMFi/Fw5jlxbApRrWmWBU5nu7EObka7RyumBkIOiq3m+JsHr8Cn4IBsoYwFy 2AC0dM+wF0PAGE+JLfshKLN9MMaB0yewygvZkXZnxfRp3hqmQJSQY9qXp1KlaAiiGncN 6wnFUPS8c0j+e/VCORDm4zt+4/WQplnXH5O5jj2OwzQtgE+BpyZGXjBLx44npcz6Y8KS Xh8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qhkBB7in; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170273-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qb12-20020a1709077e8c00b00a59b7220ff2si2528579ejc.414.2024.05.06.11.13.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 11:13:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qhkBB7in; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170273-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 28FE71F26D6A for ; Mon, 6 May 2024 18:03:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1025F158D88; Mon, 6 May 2024 18:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qhkBB7in" 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 360D3158845; Mon, 6 May 2024 18:02:44 +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=1715018565; cv=none; b=fKLX/ATH5C/Oy5MWIEPgkUhoWVl1zNnZVuT1Zmco7msotpW83lnPWiFWBK9OLvw2f0fCkmaQaKT1E4BuPuO0wO4t8peOEYzdEaS0GX3f7is/jDb9t+cUtRb5kqXmyAT4nx4R/t08KX20GtJ+0ho+oiQqBMVT9X6OBIu6rajTAnE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018565; c=relaxed/simple; bh=fqRLeDpMpLEhNJVbHZLCTU75BBCRbuwZMSWodHnJdO0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=pF81mP2+1f+JiDsj8mDCK0F9viXkqVKL+4WPN7cfw75zynXLEonWEK/Hdon+hDqiiV6UhbDvfvBjsV0eHyN8UvuTenLJn0soUcJ+tYlqgJFEpC4lAsXuuU1gNy/jyIfGcZOe4+FORXpJq4PUUuPrxhTzmpDsJ2VJ7h19LgSpFqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qhkBB7in; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40D56C116B1; Mon, 6 May 2024 18:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715018564; bh=fqRLeDpMpLEhNJVbHZLCTU75BBCRbuwZMSWodHnJdO0=; h=From:To:Cc:Subject:Date:From; b=qhkBB7in8mS9W1tIqHCEPWz5aZqW5cfimQodAJooz4TEaNkJOLCX7+MGkuP34BBCq v9aFDXNjhEBjTusv8n/LIGzL+Ar/JOJInwutge/ypD6XICQWSsgLOl3Z1Db9K4HdCV Bkmij/ktc1VwJL6egTUmTNt3vH6nd5GfYKNvWj73mMnIN+dHgdwStaytOWY6HVsTGH YD/cEcOhmatDTuifUAQZA2QD8IJ3JnIi/g5TbtR6hdEu7KBZ53rYmAytXyUaM1ZO3C Jo4+gsoS3k/m9xpP3sgdJLX3cYV+TLKA13sx16j+/ww9WmF84zDPYhFRAkOMcqK5N6 ZDWNbgu58Nmsg== From: SeongJae Park To: Andrew Morton Cc: Alex Rusuf , SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] mm/damon/core: Fix return value from damos_wmark_metric_value Date: Mon, 6 May 2024 11:02:38 -0700 Message-Id: <20240506180238.53842-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Alex Rusuf damos_wmark_metric_value's return value is 'unsigned long', so returning -EINVAL as 'unsigned long' may turn out to be very different from the expected one (using 2's complement) and treat as usual matric's value. So, fix that, checking if returned value is not 0. Fixes: ee801b7dd782 ("mm/damon/schemes: activate schemes based on a watermarks mechanism") Signed-off-by: Alex Rusuf Reviewed-by: SeongJae Park Signed-off-by: SeongJae Park --- Changes from v3 (https://lore.kernel.org/20240428191439.194027-1-yorha.op@gmail.com) - Add Reviewed-by: SeongJae Park - Send to Andrew and linux-mm@ for being merged in mm tree mm/damon/core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 939ecfcd4641..6392f1cc97a3 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1481,12 +1481,14 @@ static bool kdamond_need_stop(struct damon_ctx *ctx) return true; } -static unsigned long damos_wmark_metric_value(enum damos_wmark_metric metric) +static int damos_get_wmark_metric_value(enum damos_wmark_metric metric, + unsigned long *metric_value) { switch (metric) { case DAMOS_WMARK_FREE_MEM_RATE: - return global_zone_page_state(NR_FREE_PAGES) * 1000 / + *metric_value = global_zone_page_state(NR_FREE_PAGES) * 1000 / totalram_pages(); + return 0; default: break; } @@ -1501,10 +1503,9 @@ static unsigned long damos_wmark_wait_us(struct damos *scheme) { unsigned long metric; - if (scheme->wmarks.metric == DAMOS_WMARK_NONE) + if (damos_get_wmark_metric_value(scheme->wmarks.metric, &metric)) return 0; - metric = damos_wmark_metric_value(scheme->wmarks.metric); /* higher than high watermark or lower than low watermark */ if (metric > scheme->wmarks.high || scheme->wmarks.low > metric) { if (scheme->wmarks.activated) -- 2.39.2