From patchwork Fri Oct 20 17:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 156236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1213199vqb; Fri, 20 Oct 2023 10:23:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwJucAe6pq67hJLmiczublPAImeRu5WUB2w1r7m3bfpxWsIpU1WqSwdZmOxu2Axv1y+TQk X-Received: by 2002:a05:6a20:440c:b0:17b:cfee:9b9 with SMTP id ce12-20020a056a20440c00b0017bcfee09b9mr2854856pzb.41.1697822619748; Fri, 20 Oct 2023 10:23:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822619; cv=none; d=google.com; s=arc-20160816; b=PPqrDLC8LoF9hYgzFoDhagwM4qEM50JUqnM2czVBBpWjjv4YwHocBEcnsF1n5yZlRM 3gBxZwJUpXUQUgQmskEJg7OzmrzW5PFeuaVDqftK5qMsBOktL6AYXx6/pVUQC5vSI+eD RkCP5ed8oQnaAYfHBidUrQMzCrnKPqS3NtbkbqMI4tRmya9OizpSqRyqpxkZ0okRGMtj mv72usLpWYB80EKNWxiM1AqkI00JFcPPfLcy364PIvpQzJRS+bTT69++rqyBpEkPj2do 75HNETCjhMcZlSsJ/si2X6GmchjhlXH4MZVmfO0oCIDmzbhHIidaUmZfjQwzJlTygniK HKhQ== 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=HLqUQe00dMgNr2OfwqUnWCJdJQVpHibxoVFBKdDb3FE=; fh=nlZbZM/lrRfzHQcwYZKnNixXg4ySijwiL5np8ihS7AE=; b=GenxRDsuh/Lqr9NglF0rqBgFQN554/m7PIDGFvcmNKVnGWccK9wTLNkco6U6HmGM6w UJr9RAWODcVtzt7pRi9f4oeQY3vxq+CSvKZ2jRA/7jpLEjXNlHHwLlHjSo0nu2TwkYWQ EYfEO20YCMXOzbzEkz0JJbHhqAkk4oA9/MWAfPUN8gpKhtNARs4iGq9zFKOQ0gyg1fYD Nb3juc6Yr335mOm1dht47LYlTDuyJWkQhUCsjJafefeajyPoRpqxsCWtITkBH2X+kDNr mY/5Qz1SaPUVXAhZEPBNf9/wTyM5oYaYoqrhcMAVWrBmwWud8oPC/M9XBAynhyf/LbVU X5rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHtmFc93; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id j187-20020a638bc4000000b00578e5228c76si2327352pge.505.2023.10.20.10.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:23:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHtmFc93; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 EA003830C335; Fri, 20 Oct 2023 10:23:38 -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 S1377931AbjJTRXe (ORCPT + 26 others); Fri, 20 Oct 2023 13:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377916AbjJTRX3 (ORCPT ); Fri, 20 Oct 2023 13:23:29 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B067511B; Fri, 20 Oct 2023 10:23:27 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E62BEC433CB; Fri, 20 Oct 2023 17:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822607; bh=6lmYsv8XJqW/eM+lXLzhU7HxZ5CdX1w8lmt0qOdrzr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHtmFc93b57yZn/bDpAh7gBhcfHbj20IeY+fuu4053yIw8MoFaaDnmQ0MsrNV8IEo X1ZOjlEl1Kmq4ngCLAeoC0621PhULQJp8lkT0Kw5Kc+APiSyMONoLooY1MQILhnSDk 1W2Lt47fEK5O7FwRtUdgtoRCWawLtS8RrNJAvD6jDE3sWD3ipUbb1AYqpnahNa2Anz tLyFDzmIrQ4k/2QD4TQMawE617DS+D+Cktc6QL7UdhoZ140dK+/y11tdkGzEEIlkn7 D8LoBKqBNUcwmM8as1ufxtbE2HDuPWHtSNOJh3KGLxL+1+9gAKAdCjl0b2J+e8c26P Q5JlslM9OsQqQ== 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 4/5] mm/damon/lru_sort: avoid divide-by-zero in hot threshold calculation Date: Fri, 20 Oct 2023 17:23:16 +0000 Message-Id: <20231020172317.64192-5-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:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780296051637907118 X-GMAIL-MSGID: 1780296051637907118 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. Reported-by: Jakub Acs 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)