From patchwork Thu Oct 19 19:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 155699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp616380vqb; Thu, 19 Oct 2023 12:50:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxaCpdSMcg0ozMeiE/1v6T1AgSFJnmz9/KRoxs1aixfuY7ekFP9rEu+bNXb6hWfvlyNu6e X-Received: by 2002:a05:6a20:440a:b0:17a:e941:b0a3 with SMTP id ce10-20020a056a20440a00b0017ae941b0a3mr3887772pzb.39.1697745002791; Thu, 19 Oct 2023 12:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697745002; cv=none; d=google.com; s=arc-20160816; b=z9MnvLX4lemjgIA3TI7HbmQmXWwtwpRSOQ7FdeWJinydt12bJggYnHcSl3DiJUOY72 F6U7tv3WGUv8Wz897uJbL1t6g9916JKpYzFc8XSftsIDl+y1wI/zbN2dkqECxeSKy+rg AvYwiS7UUd7EcjXffAm57NZfVe999FjDFD0NTbVHZBmQDdZppXgh/A4M5KB5jgtaTHFg ufExyg7nmQqkggAEjPtMv0wq/sV71G101EwQ2MMxIqFMdNhzZJ2EZ3T44nFWgNnhhd5J +IRqU1upCoFYp5FQb0uQ5C0iR0ubX6iN6k/TdoescwT9ttz2P6biBAHhD3owRZY0jlH5 sOIQ== 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=B/CCsTDa+XZDlq5k3rMLYJEgO7TntQ3l0uMTeRRAAts=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=l0JQdG4tzxo0JdzHAnAF9rZvIGLJ1yJoWtIJXkSmj7ImfjJBVFl4lq9taxmgGW706p am6KBFB/q5loL1bnrCLK2Drm9DrWzSqeaKdDjWUPiqSzUM4vHkqLdiHPyKIFtJJwenfI rzPIPbRV9W2fpeu+/luuX4VBlyh08Yolthn3XbdJnCnq9chG5041Bi8FPfZxieZ9hLe3 oz63CXa4bigDe9Ye7jZtgJdCCFgFEcAPSbbVCrFL0RsOjm4d0YnXibQC2NznxOu57w2N aU6StUfsy4mWcY1zoaR2TEaSAulw8geNYmWxZbyKnhKL+PBUgJVoA08vL2FteBLWSPiM TYEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DIpRll2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t13-20020a17090ad50d00b0027927b9debcsi2831252pju.60.2023.10.19.12.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:50:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DIpRll2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 1E1A782CBA70; Thu, 19 Oct 2023 12:49:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346548AbjJSTtj (ORCPT + 26 others); Thu, 19 Oct 2023 15:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346477AbjJSTtd (ORCPT ); Thu, 19 Oct 2023 15:49:33 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD157CA; Thu, 19 Oct 2023 12:49:31 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A42C433CB; Thu, 19 Oct 2023 19:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744971; bh=mCKYxJG6okaaxTlaAJiDWBfMeecgvhed2+n6U1OL4CI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DIpRll2dkGyuM/W1HY/OtCJ0rVq9bgajq0d8Ehg4VUWQ+lGFeTkQxBJjxh7927Hi9 uKHjKJjL5AQ5O6adkHXP684YQsUouzmOfAujbPozk8M3KHgXEKdIzLfxfiwsDdnxES boqYYS+F2Jcj+R1reI40WC6tfNeK0UiQnh1EFUyCvLYx6pyLPpEbJJGzu46FKY0IoY Fvl84swfOFhwCdZh9ZJzhO3w35UPmexJuKUte56Gfe7CwJJGB/j0sX3xffpEeDHNmN 6bP2glF0upzkOFUED5Q+3MUI51uFt0C67sqqVbo4OutJCy735/57FsWLl7U5qaOmjD A31VZ5YTiz7Jg== 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 2/5] mm/damon/core: avoid divide-by-zero during monitoring results update Date: Thu, 19 Oct 2023 19:49:21 +0000 Message-Id: <20231019194924.100347-3-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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 12:49:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780214664012238361 X-GMAIL-MSGID: 1780214664012238361 When monitoring attributes are changed, DAMON updates access rate of the monitoring results accordingly. For that, it 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: 2f5bef5a590b ("mm/damon/core: update monitoring results for new monitoring attributes") Cc: # 6.3.x Signed-off-by: SeongJae Park --- mm/damon/core.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 9f4f7c378cf3..e194c8075235 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -500,20 +500,14 @@ static unsigned int damon_age_for_new_attrs(unsigned int age, static unsigned int damon_accesses_bp_to_nr_accesses( unsigned int accesses_bp, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return accesses_bp * max_nr_accesses / 10000; + return accesses_bp * damon_max_nr_accesses(attrs) / 10000; } /* convert nr_accesses to access ratio in bp (per 10,000) */ static unsigned int damon_nr_accesses_to_accesses_bp( unsigned int nr_accesses, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return nr_accesses * 10000 / max_nr_accesses; + return nr_accesses * 10000 / damon_max_nr_accesses(attrs); } static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses,