From patchwork Fri Oct 20 17:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13430979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42CE6C001DF for ; Fri, 20 Oct 2023 17:23:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA6048D01CC; Fri, 20 Oct 2023 13:23:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5EA38D01CD; Fri, 20 Oct 2023 13:23:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F2B18D01CC; Fri, 20 Oct 2023 13:23:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 865188D0003 for ; Fri, 20 Oct 2023 13:23:28 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 650A614122D for ; Fri, 20 Oct 2023 17:23:28 +0000 (UTC) X-FDA: 81366511296.16.C5FE111 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id C2AB94000A for ; Fri, 20 Oct 2023 17:23:26 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tibiLrMD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697822606; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gHG3JngsXmc6BwWUvB8MOvbIsEavnDuQdNxca10fgBw=; b=MQtPnRbeH7yWtFokmrqrQ8bmwnDt7cn76y2SvBGohzmWN78C2hHkiXVNC2jJinRjjxSxRr 1NdokeCnPxHg4QLxZMHm8tzcNLxKRqHXxtx139dEO0GQX+I1ct15WImglprskzEy4k6LLp heUhP/tcgbA9OPLWuVfRZVemaOuNQ20= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tibiLrMD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697822606; a=rsa-sha256; cv=none; b=BSIcz0uSPVKGWiFELp7qyJkCoEXV0jpeKq9PiHAIjAFQ15uCU8ryHQ4TE0CLirvGZecg3W gbC27T3PNKxv8FAOlhe4NKwAg2amDSzizm4pZ3otQzDGhNvRdsU0VXHspZHXhHFF4y+HMO itDs/dvSXAyTEpYykNQatZFBWoR93O0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DCCE7622C6; Fri, 20 Oct 2023 17:23:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1487BC433C7; Fri, 20 Oct 2023 17:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822604; bh=OyGTPA4KF2+eYVdgVawdmd836X4nvWEWuxM0J39C7SY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tibiLrMDEW1tJPRD83m27OwLCd/3DldWtN6HSY+GRNl2CN2/lGFqdA8TQQ727MbK1 RXghEBiUVpRYW2wWEiF2yiDTw4Mz9aUN/5jKYr74Dv/eki3xYKDE93RdSo9tqctrMh CQYh7C/JT6Pd/m/Lx4jnpiYh3AL+5ZGjJ0Dgwm8qeCTjxEkZ//jSvkKcBywnn8qJsk xIov6mao/lOfYVmBmQThgDh3lKi7Zq5LeWX+G0A45G30D5VHCYpRwm1A1Anhin9GeL YqhXZxPUTshcAwA2xiNxXzGXvG7BgM88reL/1z9rKcS6B3dNgRns0LUK1vsgdWaqlG PvGSzwlgnkpAg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jakub Acs , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 2/5] mm/damon/core: avoid divide-by-zero during monitoring results update Date: Fri, 20 Oct 2023 17:23:14 +0000 Message-Id: <20231020172317.64192-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020172317.64192-1-sj@kernel.org> References: <20231020172317.64192-1-sj@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: k3axh8ou1991timmgxyrt8z7af4haiba X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C2AB94000A X-HE-Tag: 1697822606-586157 X-HE-Meta: U2FsdGVkX1//Ddotja3OwgFcvjTdz/DV+yTcBvOK1hnOoCM9VyS4iG2lgnyh6FvfuxRG/INo5VqbW8MfL4vXuVLhDtAZEMLREGZI68T2+hFu1lXORGAI1yWtPn38R0231ZqalUVHDX3GtiovEJFy1FqkSrDE0xlSJsKJn3Ia7F6Hwlvy1DNNBqulfA434R4gEGVZ7kLglGpb8kRb+cU2VEMy9f0zQ7YIsKG2RFIvF/VT0gJ7QK9GGLlE0J+dnGjkIFyRao7bug1eBGstgKhdd141o7T6ftYciTG9Ims9rNKVOcjin2rOCDAiGoDNVBnzqTcoINhD+DBIVGAfrPH8kLAmnGS15nVX20LzhID+dmD5YPbH08LI1ewFYdXUwObqguyoREF/jEY1+h5odBaJsLFhxUG/fXU8JAfAMzpVIhM5Dji+AyhdvDSSs2Uk2d8wMpDF6rGhO4/MaLXBn8Ap03hYcjZzJ0pEHDxFwDQtNJwWuBI4mrcwLE3BrLPGwXAzm6u0ZjBXc7F0ZM8puwgPOnptAXkbE4tECfHjxuS2I/bOa2EJ08UwmdF3/9U/0K/qRxoxGwFMuxbqyrmXXoXzDkOMkVDPr9iReU3e7XfNaEHMb3A0/CmC0GULDb0114wjOfrCt71XOEnHAkLB8miJvOoVqpiKaUpHtwrOMKFxyDZbo4JwcocfpTWGDQ50Hnm/PWTZqXTYyQQN4zLqKv5pze2/7n+kUDn2MDCGKgHvMjXD7jpj7zQujOUnSa6rqLv/uaQyOAcbm+BYU9rQsJkF87+aegl3/aNpTrFlYA2bJ4EEPRH3BccvFrUbzVCb3KGRt8iKPLJcYXOgibKJpgfHhP3AomVlC2Q0HNxw2Vz7QMT8fHswdjP/PHvSKVrTXhAzfjZ/tIWVHlOxvxMOYNduUTX07JIXiOHqTgXRU8aN4WVMyxtJUImf22SDVOLjEzZVn18N0cxrxgL6dfuqflh pwutdcOJ S7H6XPMIF/76Ud6e6RvtYidfbfFU3lnxssQiNgsmekjJCe8xv28Lz7YmnhHnZQjGMa96qyNzzb6TayTnyCmIYOtxeU4GgfVDgQ7BDBNkK7QQAT7oOPFyYjFmfPTheCj5gdPwPxNnXiRL16ljkNz/0B5pH2GgfhBXwKivOKnIR2j4Xko04JDrxh3lYH8sRE26G6E29+ngRJmlvIJk3DiWbPMimPza5S3qEnNFj7J5FSGOahBE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When monitoring attributes are changed, DAMON updates access rate of the monitoring results accordingly. For that, it divides some values by the maximum nr_accesses. However, due to the type of the related variables, simple division-based calculation of the divisor can return zero. As a result, divide-by-zero is possible. Fix it by using damon_max_nr_accesses(), which handles the case. Reported-by: Jakub Acs Fixes: 2f5bef5a590b ("mm/damon/core: update monitoring results for new monitoring attributes") Cc: # 6.3.x Signed-off-by: SeongJae Park --- mm/damon/core.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 9f4f7c378cf3..e194c8075235 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -500,20 +500,14 @@ static unsigned int damon_age_for_new_attrs(unsigned int age, static unsigned int damon_accesses_bp_to_nr_accesses( unsigned int accesses_bp, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return accesses_bp * max_nr_accesses / 10000; + return accesses_bp * damon_max_nr_accesses(attrs) / 10000; } /* convert nr_accesses to access ratio in bp (per 10,000) */ static unsigned int damon_nr_accesses_to_accesses_bp( unsigned int nr_accesses, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return nr_accesses * 10000 / max_nr_accesses; + return nr_accesses * 10000 / damon_max_nr_accesses(attrs); } static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses,