Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp943707ybk; Wed, 20 May 2020 16:28:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTypVNY1HUyhyXmWG3qeaiMGExdJQzZr1a47JQQX+alStzYx9kqfLgpgLvLRIowRA0e7+x X-Received: by 2002:aa7:d90b:: with SMTP id a11mr5613038edr.159.1590017335102; Wed, 20 May 2020 16:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590017335; cv=none; d=google.com; s=arc-20160816; b=f2Zax5GZNsYPmdFATIOOKHINmcKcPgvEbzsCrczGItWunZDauGnlPMJQ2F9xCk4Bdm df1Z9Mkgtisp8Ni29U/sdhocRULxprPtUjBy3VaUl8B/KaDpHFCR4MV8o6WrA3pmvA0r AQDkJ9Eab4IUhdh+gWCuccN1h+cjzEpyZI//nQBwMXQ+AfyUFreqUjCIg0lR4XhPO71a DfL3YcHEbJEKLa43gV4R5bG89AGZAh4d+Wg9qIRrUD/lUU9UtFzgxeWb0g7VMkbxqUDT iRJXO9DdWO0vHUGvRlxUrLGumIRg9+4vPfgtJuvmLMlcudCdpUb5gR0NrGnXQLLQaAEn k1dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k1mJyFxqpgpRzCt8CICzuJvDAagkfPR/HMnvDC6JCyY=; b=qvMNC56rjOGVeU890BkyMOzvcCigevOk3IUDZiCDCqjZZ++EI1yzysDO0NmcoNfPBR Dfv7fdo45R2k/UB1uOI9a3+/WTZYZEwoF/MfZxvd1gjaA+3CGVn8NY2FW28Ki+J1CwbY egh+mP1yiuf6tdQebn/3m+tl8GSUkyPiIu0Z8HCWaFGGWknSAHQizQdDenPfNqRsYlDw +bMy+OLhXuxCj046VVjk8KnYpxQ29oOIlzwmVSf/i64UW2C2vQ/umpVcXWY4ZZef8MD4 9lEmMA1z0qUrWBwVh5usBxLHPBdN67clJ8nABzMBcf261RYJiBj/Jnbyxp1jIFQ/JgNb 5ygg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ztU73FgX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r23si2115806edp.515.2020.05.20.16.28.32; Wed, 20 May 2020 16:28:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ztU73FgX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728847AbgETX0Q (ORCPT + 99 others); Wed, 20 May 2020 19:26:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728800AbgETX0N (ORCPT ); Wed, 20 May 2020 19:26:13 -0400 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2352C061A0E for ; Wed, 20 May 2020 16:26:11 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id dh1so2223907qvb.13 for ; Wed, 20 May 2020 16:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k1mJyFxqpgpRzCt8CICzuJvDAagkfPR/HMnvDC6JCyY=; b=ztU73FgX01oSp/NMDzA3s6wLAWqemke1edTHLBlfwK9d2FVAn7pD+tArAISYdGoz7L Ypfr5EHdNe9un0Ie+AMD5IE3dm8h3CGusgw8hsPu9ZUkXVG8A51EaAffxsk5T8iiWFAe xtiaaL5aQURwIyCVnz5CyGKiPgfPVsamum8BJ2c5ofoLUyoiXENrOdR+1uWnUSbKXPBg Ff0B+cycL5NqIdYQs2aD/eFO88CRg0vYo1gIEcjYRcGHPnKueMcv/yv5jd7nRU09os5u t7ma1B4qYkHr6/J8Qjog9NU4MXUf45aePH1niFKtNgTZxnfzY31ZKSQajZ0tIwE3Rbat lHDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k1mJyFxqpgpRzCt8CICzuJvDAagkfPR/HMnvDC6JCyY=; b=JDKQfELv9BkO+0h04aA0x4rWI0OaLqjwI/ihc5vMhNqmJVciIsRCpGCCgpn4UWpLqK NC6JiIV/42L5LZpSOjqTbMXc0IgPFxVqgVnPgPMEcKFyGXg4ctA+6Q/bv4t1tNVVU0Jv 3XmvOqxtpIPaAGf4MTXqY9a8LlVHJ2HaIeOEeFpKheSDtw9qdrfB3pS5srSlCr06wt5E SDmYBTqc7i4Vqz8FgXbRHMROl98QDUYTdMqsRJYtIh+bOukt0hE0yCQQKt/ZqNayyq5c 9liD/H6Iz6lmzTjPOqVaqv7yBM0kIMlgkQkZV6SCvm8atKQBKEmhapYqdvnm7HWp9x5V qkDg== X-Gm-Message-State: AOAM532WvcJrTrdKYws+ZVy95Vk57lP8yn8q3QRmUTIY8aXoekRE7kJk 0IGGs/m6t3nR/IHfF/Uejtkwqw== X-Received: by 2002:a0c:f407:: with SMTP id h7mr7159580qvl.116.1590017170707; Wed, 20 May 2020 16:26:10 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:4708]) by smtp.gmail.com with ESMTPSA id j36sm3921691qta.71.2020.05.20.16.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 16:26:10 -0700 (PDT) From: Johannes Weiner To: linux-mm@kvack.org Cc: Rik van Riel , Minchan Kim , Michal Hocko , Andrew Morton , Joonsoo Kim , linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/14] mm: vmscan: drop unnecessary div0 avoidance rounding in get_scan_count() Date: Wed, 20 May 2020 19:25:18 -0400 Message-Id: <20200520232525.798933-8-hannes@cmpxchg.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200520232525.798933-1-hannes@cmpxchg.org> References: <20200520232525.798933-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we calculate the relative scan pressure between the anon and file LRU lists, we have to assume that reclaim_stat can contain zeroes. To avoid div0 crashes, we add 1 to all denominators like so: anon_prio = swappiness; file_prio = 200 - anon_prio; [...] /* * The amount of pressure on anon vs file pages is inversely * proportional to the fraction of recently scanned pages on * each list that were recently referenced and in active use. */ ap = anon_prio * (reclaim_stat->recent_scanned[0] + 1); ap /= reclaim_stat->recent_rotated[0] + 1; fp = file_prio * (reclaim_stat->recent_scanned[1] + 1); fp /= reclaim_stat->recent_rotated[1] + 1; spin_unlock_irq(&pgdat->lru_lock); fraction[0] = ap; fraction[1] = fp; denominator = ap + fp + 1; While reclaim_stat can contain 0, it's not actually possible for ap + fp to be 0. One of anon_prio or file_prio could be zero, but they must still add up to 200. And the reclaim_stat fraction, due to the +1 in there, is always at least 1. So if one of the two numerators is 0, the other one can't be. ap + fp is always at least 1. Drop the + 1. Signed-off-by: Johannes Weiner --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 43f88b1a4f14..6cd1029ea9d4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2348,7 +2348,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, fraction[0] = ap; fraction[1] = fp; - denominator = ap + fp + 1; + denominator = ap + fp; out: for_each_evictable_lru(lru) { int file = is_file_lru(lru); -- 2.26.2