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: 155700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp616414vqb; Thu, 19 Oct 2023 12:50:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0Kl+5Y5DpENzrou57iniMQ04/GhJQ19yRqyw1/Zhu2dMmaOEuDlFKH5aePdoWksdijRLa X-Received: by 2002:a17:90a:49:b0:27d:5946:5e36 with SMTP id 9-20020a17090a004900b0027d59465e36mr3308764pjb.32.1697745005516; Thu, 19 Oct 2023 12:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697745005; cv=none; d=google.com; s=arc-20160816; b=F72LqCkFU3+PsDga5GdwizwCii/XTmE022Lzlm4GIS3Av+ajNStjmpFTUv4lbNOpqi ahP9R5lmy7Kfx69h2kDg3am7+us/7T5GM6NjWjCE4+NmtL0i12GLDgOix0avz8FNt6Ih B/QR9Czmf/C6ajCXeR+hTXoxWP/VbiRrRTku4CoTa0iJZzwvcG2QBHC3WcCP9LopuDDS cTBCU6WynmCmhYVVYfTe95V7qI57IJnsk5L8AeaywXc7VhbJALdvZYkmDPl+iSBABgin BDAUhbfhYI5KqqPxeGO24MjDfl0DpjkKh6yQW3ZwrndxGEcJx+jjfClL0T1/C0a4kfB1 3qNA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k3jW9/aa516YLgiCw2729Ckj7mfBIGuYgRCR/BJg5Q8=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=Ds64HLDZfyfPAMODIK2dzE+Aakr8BcWToDta1pR1J6I7elYhyolKNfNpuVm7ue/wMU QP5bEre53wt+iOR2FO81Z/SEy4BelPNYMQPGLxisoXwr1/JsHfdBhmdkwoYCY9N+eoRa ZTeI8jPN38S5VyIf0dsCmUUugLmZdx/RrIHsI+Sbije8QFYmbHEktT0HWa1MvUPZo3OK EG33ibbqODTg5bme8+KvXYwcLYNdrNWqNRFlR2iGtM5MM3yH0JUwqIYLVgLfmxXqHw2q HP4Eyzx1RwYW6NqDNcbogIczR9fGhkBKaNbGdysd3W9arWtJlAhc6EIvKAje21mREEv2 l++A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OOgE1jz3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id lk3-20020a17090b33c300b0027d60ad5caesi371644pjb.110.2023.10.19.12.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:50:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OOgE1jz3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 272AB81BE2D9; Thu, 19 Oct 2023 12:50:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346534AbjJSTth (ORCPT + 26 others); Thu, 19 Oct 2023 15:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346503AbjJSTte (ORCPT ); Thu, 19 Oct 2023 15:49:34 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6876311B; Thu, 19 Oct 2023 12:49:32 -0700 (PDT) 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-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 12:50:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780214666912001046 X-GMAIL-MSGID: 1780214666912001046 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;