From patchwork Thu Oct 19 19:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13429775 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 A2BAACDB482 for ; Thu, 19 Oct 2023 19:49:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3286800B5; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6E19800B4; 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 B105B800B5; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 97D9D800B1 for ; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 75577140694 for ; Thu, 19 Oct 2023 19:49:37 +0000 (UTC) X-FDA: 81363250794.22.B47BFC9 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 6FBB3100006 for ; Thu, 19 Oct 2023 19:49:35 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OOgE1jz3; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.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=k3jW9/aa516YLgiCw2729Ckj7mfBIGuYgRCR/BJg5Q8=; b=l4QWL3R98MZ27LX/MDKn9WWpArKE2Cg75wBGJ8oDmn4CIfL5eeOtY8wqgUWHZkdk6RLOyF yhifEmDKnuGwUWg6kh0my/89NOo+iyrmNjkevrvpaeJAMlJUy/sZVz+EUtM/63IwqVp8ge ck8x4M8y+fvld/pBMZvHuGtYqRMnY6Y= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OOgE1jz3; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.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=D+KWJR+1swftFXdxJsUJeBq+PlgCyB1iNNN03OZPID+F1ueUz8Rnnmm4r9YoKofuYDY6kx JKfIH2Z/d5XwCgUcVIpUL/FC0aKqHqti1Nw/mA7nLDJhlgaF8q/M52XfLM9v6a/xKWbd1r Mw2kSwYNMq/iibdspXd7lQITa8qWz7U= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CE5E6CE31E0; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F662C433C8; Thu, 19 Oct 2023 19:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744972; bh=mpZ0rzQnlOTIrrYJTnG5fwff80O37UKmtsf+aHi2YNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OOgE1jz3lvMQfVP7TQZSOyc2aRshLkRxLJ6fzn2xEUat6kCKF9dHCXjOeqKgMRUkn JciYs/7W2GFKrLW8hHfKWb7PqfogevqMt/W8HSQOH0D+82UwlpAdZ4kkAZlACm/7Yd lD6zHpOrNamlwYL1JvFr3UqFSKsZRQ1C83Lu4MTrb569Z96fQBnp9j01s7w6xZ9Yus L+XY6w6H9dDlGykT60OConZ8snDx2JZCuR0vhKoLc74v3VmzIH7s8RZFN1aRYiH6OY +7tcNIopiD0jvwS2tVxbGdb8rayh09UhaZvj0Vg1VvBTo7/44eLy16O3BQ4MwcSBs7 FXMYu/8h+hHrw== 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 3/5] mm/damon/ops-common: avoid divide-by-zero during region hotness calculation Date: Thu, 19 Oct 2023 19:49:22 +0000 Message-Id: <20231019194924.100347-4-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: 6FBB3100006 X-Stat-Signature: xuqumbc7ydwhkqdm8q93prqm1ss95uiu X-Rspam-User: X-HE-Tag: 1697744975-311597 X-HE-Meta: U2FsdGVkX1+jV3+0smLLK0j2p966yMbwS1F1mbDKQug0PLi3m2Y4T0bbYvz6sLhJYXhN/QeGsLrrpZioKeYfZScYPfNN1mhtc+1Cf1elrrf1tcU5VOpRUYNSU2hL/l11IXZqsnT0vKh/zyZT/iCz2QwNogC0TdAykPOHyZcsQwZXP9Mf5iOqwX3EnctLl3puIl+eRFLxAo3agEVmyDYq4E1YzByNrwgCP7hkKxG7OxCBwhlmLn1fyvEvTV6P8ZrcwzK2XrYuSbkJs1xjcD9DTQ20jgIM+RT37GP/Nejn0izyRe4yKgp4JahIz9U+hlDoxuaqsCc0tUqWREsz7yR9F7p4iQhqDd/C/qqYuHfcIeLy4QgFsvJ4nJjljv8KQtct4ventWeyHy5jCozGuFaAs00XIB2dmLwGBlDfSbSc+j3pV+ETf1pyWs0evjkpXvpC552m9SaReVSx3brcKBB++4x+w2VMjAI7QzX0wFZzaVMnyEZxAQC6LYg3cbdMX7z03kyisen4eesPJsPTNGqXUsCfSLGDUcUga47/tZlzIAnRU74PggG0mDGkBNvunU5VlKXEuSdiUYaXDR4XS/tTib2NQVEgynXiO5SvtJqgaP7OuU/LgO1sdXog7AriOc02u3UHPe6DV+MnsLt2+MFvJXMLnnfjIUzsKYJPuadpNMmlayCcoYXtd0OPaAwsIHfnJx9FJ/O/b5xqhCVIYQYHGl/fN+BMm9+A646hWN7BvNDgEPUd9MeG1YwL7Y1jxTdCLIQJ6FBOjHeyCMQCPvT9i6JocttBAcJ3l9pRVQ8VKE93z9MZKLDnGlgUB19ENoHVIJNrc6gqDy8Hl2YkhOrMDxULESX1l7abbF3j3RhYPMBZ6zDmUUey1Uvx+/eNjKrz+toQNvD5g2BtxwQ4eflvx9SQUee0GPeZxIUNOHyoPGNCwyEfxdg75GvTTHXe91FU6SYHFDPthflPDYmI6DT 1Mfyo9Yf 7831Ysh/hvwkLF94AsmWUH3IOt2tDYboudosU28+DAohz3nj92fWWIg2R/EAdOxZ9FeL6e97RuMVBk4MXnRD5k3Xmwrg+u8ugGCI0BU3+pX77u9aVH3Nq4uizZVFbxtR8lzbBiV2WYD8eMz2FehBz4UwUjd3RuVgvwY4a/E1uF0+AuZIRwE8ZEckzDUxMCdPbM4vFFSY7Y1vUO5saPDI6feQf0TmuuNSurm5uUOKuKWGRtE4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000803, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When calculating the hotness of each region for the under-quota regions prioritization, DAMON 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: 198f0f4c58b9 ("mm/damon/vaddr,paddr: support pageout prioritization") Cc: # 5.16.x Signed-off-by: SeongJae Park --- mm/damon/ops-common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index ac1c3fa80f98..d25d99cb5f2b 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -73,7 +73,6 @@ void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr int damon_hot_score(struct damon_ctx *c, struct damon_region *r, struct damos *s) { - unsigned int max_nr_accesses; int freq_subscore; unsigned int age_in_sec; int age_in_log, age_subscore; @@ -81,8 +80,8 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r, unsigned int age_weight = s->quota.weight_age; int hotness; - max_nr_accesses = c->attrs.aggr_interval / c->attrs.sample_interval; - freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE / max_nr_accesses; + freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE / + damon_max_nr_accesses(&c->attrs); age_in_sec = (unsigned long)r->age * c->attrs.aggr_interval / 1000000; for (age_in_log = 0; age_in_log < DAMON_MAX_AGE_IN_LOG && age_in_sec;