From patchwork Thu Oct 19 19:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13429773 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 A13D5CDB485 for ; Thu, 19 Oct 2023 19:49:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67DDA800B3; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DF6F800B1; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E4CB800B4; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0D4D7800B1 for ; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C01D51CBE8F for ; Thu, 19 Oct 2023 19:49:36 +0000 (UTC) X-FDA: 81363250752.25.FEC3DCB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id C58F0120002 for ; Thu, 19 Oct 2023 19:49:34 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DIpRll2d; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 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=1697744975; 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=B/CCsTDa+XZDlq5k3rMLYJEgO7TntQ3l0uMTeRRAAts=; b=gClYq9oafGdBBzoP3UHZvxpVpq5fJlu7lgcr7mA41e46NDt+wraupvSfZwKdhCqz8vh50x tMx9QQBvmPSRhltx3x6z+Cxx9YGOH8SC+A5qguHTIJxIu83oL1hkyk9NxRqXClp2rfqxZa 8WrUOAu17bvWHfwXViwIf7f2F4aMrdU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DIpRll2d; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697744975; a=rsa-sha256; cv=none; b=XLlV9av2kLUtYf9AOrEeS65jYDaXvha4XHjs8/4LEEcy0CdpPwmJF4Czr7gA2GZNmYCMWB Oj5tpGQtM0BBEUsZ8kMNwyrVuaopvcUEr5+9S7dlXxji0hoztYqBNMaDGhigcpPNF9oQKL VNMI4mClS4mo+UJf+UE+8OWvbK/WIiU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 3135CCE31DF; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A42C433CB; Thu, 19 Oct 2023 19:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744971; bh=mCKYxJG6okaaxTlaAJiDWBfMeecgvhed2+n6U1OL4CI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DIpRll2dkGyuM/W1HY/OtCJ0rVq9bgajq0d8Ehg4VUWQ+lGFeTkQxBJjxh7927Hi9 uKHjKJjL5AQ5O6adkHXP684YQsUouzmOfAujbPozk8M3KHgXEKdIzLfxfiwsDdnxES boqYYS+F2Jcj+R1reI40WC6tfNeK0UiQnh1EFUyCvLYx6pyLPpEbJJGzu46FKY0IoY Fvl84swfOFhwCdZh9ZJzhO3w35UPmexJuKUte56Gfe7CwJJGB/j0sX3xffpEeDHNmN 6bP2glF0upzkOFUED5Q+3MUI51uFt0C67sqqVbo4OutJCy735/57FsWLl7U5qaOmjD A31VZ5YTiz7Jg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/5] mm/damon/core: avoid divide-by-zero during monitoring results update Date: Thu, 19 Oct 2023 19:49:21 +0000 Message-Id: <20231019194924.100347-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: <20231019194924.100347-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C58F0120002 X-Stat-Signature: cktzto4j1fhpj4befxerfuqw96sk546w X-Rspam-User: X-HE-Tag: 1697744974-179725 X-HE-Meta: U2FsdGVkX18MqwfggWcdUvbLDffSXqCvekJaXUO9XqQeirQhaybekHJSKbhxD7uz3TGWKMG8bueEhysBxXrU2//uRBzRwPqc/hhi2+yn+K3nFt+aJQEsecdRhojzd/OSFc4qBkkKcMjayp9W2azf8R4VYuNObLIg/sjjOuCcPpDhWBr9upVkkTtVg5lVDqXyjckGzKyuqa05AT/fh8C/Chrq5aNDbQ9r51VWAivUsNa5hRb8AkP++NXhjgxw80S+cAo+zvIGRIiL8r/Myl+mMStTLqTyh87MH51FmQF10U2ulGJxcdJx0MI49G/8zphNnNODCVcg2RxD2jb5j6VMySgqzFU88QA7/L6O2e39uOa0j57h3nxJFWzxitI0RvDb2bHKKOPRekN84T1NSKlu/7tAkX5YDs0/RIpQV/3Tbv6h8SjwTNveT8gy2fRdjRawPWtc6ack12D06IrbQiE8ptiowanvveDfK8x1L+lhfPP25n4d2FIUY2lKxf7QdtzsAeRawLaiaaDP3zI0GmdO5CeGK7TTgbLdHLrwlqiUtr3qjWX/G8IgRDm/gppgnEpPAZBrLDnxkZyAbN+QrIf/NiJOeK/nz2l2GTuc+TMnEUEsvUHVU9bS+rAKPXVbS2suD3q+pc5x1rW1eQfrHgnxH+6uAEvJ6IPVbeYwIoYSP64VvzudDRj19CgOIU0P3oqg81qmGJuyLs8IZBp0HA9oU16pmDEKv0147ovaSWMdZzhE7R358+x0kuAkVtMwYIajKH7+YELJYUE/hn3fL3sbpqaRD50jIDXcsIhtR/fIeMJHOjvBxqtuyj+m9qy8u8izCEIZQYdIYRCMSviPUMy7dMGDqjgEdN9FDVzNMoXMcEevsrejpO6uMu4eF8hif0KuIJEbqCth4w+QBqdjKm/WpZ6WC6RbcsCW6MTMqIbT3YpzFclAjbGMtvny2EAvra0WeAPwkAYKPbgkcHXh0Jx 9u+0ZDRZ +eMbkGkshB95Y4PkSwVZuelYQcVRaVJwj+6gHoys/kpgY9N8zeFjl0I3JrSmDg5N31qdBNEYXMyxNjilDNZdtRnUuK1hGMkRRE/KVEw2rxIRoKgIbUcVDV7mmaSEFRMpIDJAYwquyv+pWdDHHLZfso96DUR8ZqcDoOnacGS9t9drIKx7MNEP6kcOb/nWh7iuxJxp3xWfI/ithZywV/sh4R7xV3UqsFi6oaxPqrnpRpey4aCU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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. 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,