From patchwork Fri Oct 20 17:23:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 156235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1213166vqb; Fri, 20 Oct 2023 10:23:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/3RUSKwE8w7rMIxalGUteyYesa6WfKvHJiUETiJbLKdSp5I9gB9Cz0xDO6MHtSguWWHin X-Received: by 2002:a05:6a21:3b45:b0:16b:7602:1837 with SMTP id zy5-20020a056a213b4500b0016b76021837mr2242129pzb.29.1697822614439; Fri, 20 Oct 2023 10:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822614; cv=none; d=google.com; s=arc-20160816; b=fBayXQ8ixuD08O9q5it4tLD4PKBP32TppDOcPaL/YktOIIyWTgW/Q3VKNgAOkUSDYb f5nK+d94pjbAMTVHQnHdiCVPXZIV9IOkCRREYZ6vt6LRfyfU1TMnoduWeM1Epk27c5vG jqnoH8m7ht1HpR0lxXzP/3SXLMLYNDorxQkpflOnTNOdzt2ubwJf/NON0rVHK4DWM7+l ltrrg6GT0Nxy08ZO48cx9qsp0jNv10XYv8Hg5KZ3ckTxYuAHjHmpHQirQWuGjs9Mqq3T VGWrZjxbt4/Ggm6/472n+gbrMksuDZpHBwgIicHfixYP2T/3jNFN+pOla3KhvJlNYa3h JnEw== 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:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u6-20020a056a00158600b006935df3019esi2366632pfk.235.2023.10.20.10.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; 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:7 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 snail.vger.email (Postfix) with ESMTP id A71E7830C328; Fri, 20 Oct 2023 10:23:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377938AbjJTRXb (ORCPT + 26 others); Fri, 20 Oct 2023 13:23:31 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:23:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780296045822059863 X-GMAIL-MSGID: 1780296045822059863 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;