Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1176366rdb; Fri, 20 Oct 2023 10:23:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGY/LHeH1dDTXzPHf3y80ZhCBXRtqfDekzlfDFfP4SgGKdK071arZiXo9eXPeGWBq9iI2zJ X-Received: by 2002:a05:6358:e4a7:b0:166:a7ff:afbe with SMTP id by39-20020a056358e4a700b00166a7ffafbemr2676807rwb.0.1697822638320; Fri, 20 Oct 2023 10:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822638; cv=none; d=google.com; s=arc-20160816; b=MSPvsXqlIfuR/1kZpfDQ4Y+3OHgX3ldVrhmQb/vcOB0nE8D7W5ueBNe2tEAYrdlHu1 wAfp9S4ogdwZyFwpLdAuzqqswVIlFhtYwLl9clT8RXFyeL0JnfXIOBMxH6kTFOTemjCY NHtsgx30mMSjVTaDHVi6M1ObOQIwEzWTFPdqf1cN/PCaEwxUnle3T+y+3eNWkefEUqtQ bNYqPmV0MKzBrO+MN2o0XhAEfUwrfnFBbBTB3tQQhlG8vrYuOjPASN2uZF1gHH95GY7K BHyczKswlLzW2nZXH0M5mttNUY1pBhUgZkZABbeqbhvSDz9QhtzxHkXa88IwxUhRXmeT 9/8g== 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=NqYMoR8rx5Eey8gExHV0UoVh6y7tL0W0AcY+8h1xyrM=; fh=nlZbZM/lrRfzHQcwYZKnNixXg4ySijwiL5np8ihS7AE=; b=pxAjBF53YYhKhIA4gCfLJnKemqCIuTsSa9xDaCjmBpzs8I+/MdptJOFGKDIiGMogMS oaTcbOKX40CUpbDF7x1waHKWn8L00bioQOvL5Nnm9gcz0me0eWx/HDMw5nUvmfxLX6tr ZQKc8V2huOKX3D2P0cC9Bb0gQofhXMdM4DEWg+LoI+NCKQGhFIgspFO9PSbokFpDWosF fQl9SrDexjG52pvz8vf6tUcBACrvVg+FVERcrq1Uk0CA8TgE1of2Wfxn6hZ3zSnUmYsO jPelOu7gskDAHDxJbf0pWguQeP0GBOZF7oxx7VulT6niQyynhgiFs5KF5cHHd/83fo3z TlOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t9O9pz8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id b69-20020a633448000000b005ab190f94ffsi2286452pga.605.2023.10.20.10.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:23:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t9O9pz8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 8B55A82FD7C1; Fri, 20 Oct 2023 10:23:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377936AbjJTRXa (ORCPT + 99 others); Fri, 20 Oct 2023 13:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377927AbjJTRX1 (ORCPT ); Fri, 20 Oct 2023 13:23:27 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D512A3; Fri, 20 Oct 2023 10:23:26 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78EB3C433CA; Fri, 20 Oct 2023 17:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822606; bh=GfglrsOk5qGjGnmruIH7Op0UcLOq5YxxSRcQby/wYY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t9O9pz8w8PavHtJRAmDjnfs+pzDqdv3x4tnFpqQpQW1CJed83FYVNs8li7TGn1UA+ inQgRhjia22JOeOI1IOX/SU72zUdILTB4zjucts/LRz4x26P/X2PpEbbKFOOvzENqP dKo+VdyORmHfwzLfarroponzPoeHT8djRKCvqTMW1WtHdE0g6GJD957y+s2jxH4Urs QFIzBdNY3ViZk53G1vYRSdwpxAlC/HrSaZug/ZAIIXroUlMmTWB8Z61PD7o6nsbsBr aDrtNJE0Qkr2Z/vqvRHNvfNu3zG7BvnrJYEkW94xpTpAp0LOz/mKWk9XUqXVvox+lk GpfvMq1vSBR6w== 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 3/5] mm/damon/ops-common: avoid divide-by-zero during region hotness calculation Date: Fri, 20 Oct 2023 17:23:15 +0000 Message-Id: <20231020172317.64192-4-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 Content-Transfer-Encoding: 8bit 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 morse.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 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:23:55 -0700 (PDT) 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. Reported-by: Jakub Acs 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; -- 2.34.1