Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp583807rdb; Thu, 19 Oct 2023 12:49:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8KurOMbXvnX76lUDgl/HM4jOdKrAYUdx4vy+VWWZzBfMdrGrdGCGe6JW7EbOJcN3CRn82 X-Received: by 2002:aa7:88d0:0:b0:6b1:bf32:4fc3 with SMTP id k16-20020aa788d0000000b006b1bf324fc3mr3059411pff.19.1697744998354; Thu, 19 Oct 2023 12:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697744998; cv=none; d=google.com; s=arc-20160816; b=jw6sHgMaSwPbyGqPfvjLn17ZB3sej/EBEsP/bCU1Ev4Wc3RqUO+/KDChlyjyYzGnk7 CW+epopMXG0uBVZRkFShyn3AHPEkQoK3te0kpPFRmb9V4S7GL0BVYxtvu1rlNQfP7yFc sCTW6QxNhpxf09h1b6Gjvkat0kdnu7qOg5IzFVpkyQ3YPVqhCfvfiTS5lMa+BOJ/2n7l G6H6+Ikjpj8uYRKtV1Y4wvvCF600FNRk10Kyw/Ae6QSUKHTL2R5qMANa0Cug2E2dat7B CieEc7/JLZXNBhEPS+AHmN6X0Xg/JqKm6hr9+Vap/60RI1gyifBVfbXpzcDaArx/Uy83 Zv7A== 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=BkVrEp98V3Y9dznK1aCI8PGO49GlQEZO+UOltbZCM3Y=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=PKKgUdtuWaeGJ2n0jU6LhkVzwRg80xqQOEvvJ+QSnPPT9C62CILBxuDOiSqSoEVET8 vKaZ87N3XZDn8T8nHWMEnS7CAzTESL2mcecMlA47/e5cpym7LFMJ9K81MsoGavRx6nq8 IBXn8WtM34o4rm1H/F+jeONCEEJ6T4yfL22LbaWdJOx4661FCM2dVS8wKsPrhdiW4Kh6 060QwRonZFhjrpReWMpSbphiD47oVBRFRwIF67eLZ50t0Ix4PO0vASHyLOir6pk5DC5t mMsSUDx/+gvj49+eLDA09tL+KVsyBBHg22Z6S9meSXxsuiolrNVl6vp0phBQOnUGxbRl cxhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Q/fE20KR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q12-20020aa7982c000000b006bd92819450si316888pfl.170.2023.10.19.12.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:49:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Q/fE20KR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id BE24E81DF246; Thu, 19 Oct 2023 12:49:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346528AbjJSTtl (ORCPT + 99 others); Thu, 19 Oct 2023 15:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346506AbjJSTte (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 13F37114; Thu, 19 Oct 2023 12:49:33 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48C9FC433CA; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744972; bh=JxnxpQi8Ul6nOhB30Sf8ttPU+Mbj0MwnPDqKZ/PALpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q/fE20KRyvJSGgRHegK3R+DBDTlM3NC4FaQxFC4fEJqSqwQHdqJucdhbh4cngKoMc 4Rii7MDRtomRT4L7TDzKSxzplwSoImsmMyfa3pLNK93O+F5ZWCTyb7IQdswuPcgchl 965fTzfU8pgybiLDqIrTq1WN72VSV27JSHJAoaMnrSmnzGcIde1GR1YtAwuXZXGr1W eg5GU5zj3caGORuA48hBOJgeswWu4AroqifVxo5HnxmR0uD99zC0Uig6ysPuqW9ijc ypsclOhxptVMU8Q7x6XKah1QWLn8ZPJiX2DEFntORfQiabj4NwIhRpZUTb/thUZHzA ufQlp0F+OjBaQ== 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 4/5] mm/damon/lru_sort: avoid divide-by-zero in hot threshold calculation Date: Thu, 19 Oct 2023 19:49:23 +0000 Message-Id: <20231019194924.100347-5-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 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 12:49:56 -0700 (PDT) When calculating the hotness threshold for lru_prio scheme of DAMON_LRU_SORT, the module 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: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting") Cc: # 6.0.x Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 3ecdcc029443..f2e5f9431892 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -195,9 +195,7 @@ static int damon_lru_sort_apply_parameters(void) if (err) return err; - /* aggr_interval / sample_interval is the maximum nr_accesses */ - hot_thres = damon_lru_sort_mon_attrs.aggr_interval / - damon_lru_sort_mon_attrs.sample_interval * + hot_thres = damon_max_nr_accesses(&damon_lru_sort_mon_attrs) * hot_thres_access_freq / 1000; scheme = damon_lru_sort_new_hot_scheme(hot_thres); if (!scheme) -- 2.34.1