Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2298207rbb; Tue, 27 Feb 2024 18:27:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWvkSVmepJEKDa1EdyIX3/1uxy4r3xqbDH00b2l3CAQwcCsLgyDMTU8IFsoZEKerX76BtxuURTyswK4d7Sf63B0F5gYQJZQV7xD2Shhtg== X-Google-Smtp-Source: AGHT+IHEc+ciEFxn+SUoBVpv6kDwPVaLrUw1q64sbsJgcXDfps8rMUZAphcBOHDrOv2ss6WH4zcl X-Received: by 2002:a17:902:b906:b0:1dc:6130:ad28 with SMTP id bf6-20020a170902b90600b001dc6130ad28mr12205295plb.51.1709087240112; Tue, 27 Feb 2024 18:27:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709087240; cv=pass; d=google.com; s=arc-20160816; b=BI/PEDED5SKU5oCSzLmGgHCB2pmNhhkbDzBewiH6/yPg1dSkLqWV00Dycwy2+drpYg zKKs6c7sgfdJmJ4c54zRv+neHbIab3S8CGlzHpa3RajtCJhkFtUa5j5dRPkKko96LW4w EhO1jWeIcNV1XoEF8Z4wnNmDNgAHaPTij81or0BhJcdGohRoTUCVRZx5nGXPnK/N4eXa JGfo1dokTVzH6IqSddxKDP4TBRWVvWQ60xLQMJz5S8XhmD6LYH2lp6/s9iHBPODsuAZk 5tS+QS2QFnm2zq+2rcD1oqBz5u0iruU9QCAbEFdzlfGaRr2PRrXVZcCKskH2GMPJYRcV QJrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from; bh=tlFSIFjSwTC360dyql6gdgtA5/mNJv1EOBDFnxyRb5I=; fh=D6eYGX/rJ+sdYT0u7YYr2D8z9F9mrLZ2knBpzxxS2cE=; b=dz8MrZ+VCj3JM8BIe+q2RF/jCZNeOtokqF1XLjPOOjC4i2f0DcBz4Fn4NUXpCsnLy7 eI4ipZPi54U4rlmI99yeelY2lO9BCTphxtT0KEoKPlAS9ceN8eRLMVSE+BVGJWIRMeUz 02HZt67nG3lC8VnHoWf5UsS7+1PDAie01gx1Bs0/+UyXc2u4nWUlWH82j6W/1SU5BhpR g0lsPYymOVqa/jr8uc4sw1jAMC7GsA9p6rwg/T7zAk81qoGlnyZvxhL90/OF4s7Ehqjw XsE7U+mtxNWuxUOBstsHRHOByaa8vLTgbDx/dYscjrEmqk0jhSUzbpJJvGs0I7hbHx0g rc8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-84390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84390-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e15-20020a17090301cf00b001dc88bed194si2469192plh.21.2024.02.27.18.27.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 18:27:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-84390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84390-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 51D62B23A58 for ; Wed, 28 Feb 2024 01:55:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C492C2564; Wed, 28 Feb 2024 01:55:27 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 859B71CA98 for ; Wed, 28 Feb 2024 01:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.125.252.92 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709085327; cv=none; b=ndk0LNRv84ShH03nIxEMdPZJKtqqWxKIgLjaNlRXUxRbWXWmVEpIxLCLhELK42obJ+LMVLVUO/XLr36LsZa/MrlhbmVec0vUII5Sf3wEhgeKAAo647Q/Xy4sOzchtz5syscQw0wM6UqfIsl/xCP8Npeyc2lRViosKJOuCXnG8vQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709085327; c=relaxed/simple; bh=gWX6eid25B21mSNcHkDXJMfEPHC+VA3OlleXqUIRNtk=; h=From:To:Cc:Subject:Date:Message-Id; b=cjCkDIQzqZ1Lb51ys9J5ucqlOROlPn+iR20Zwc+hQMgUBtemHDBhqnql3K/WmUD+R4j6BGpgqFpjvnzFn1ni/yYnvVlbRPoRSk+F1XCxkTXfRpMPnpZ3WmLPKz1Eju/hmcBHtbVU8x52ywSH8hEDl9OPosHmoJPrUGFxvjENew8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com; spf=pass smtp.mailfrom=sk.com; arc=none smtp.client-ip=166.125.252.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-d6dff70000001748-61-65de927f07d1 From: Byungchul Park To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel_team@skhynix.com, hannes@cmpxchg.org Subject: [PATCH] mm/vmscan: simplify the calculation of fractions for SCAN_FRACT Date: Wed, 28 Feb 2024 10:55:00 +0900 Message-Id: <20240228015500.52452-1-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsXC9ZZnoW79pHupBo9OCljMWb+GzWL1Jl+L y7vmsFncW/Of1YHF4/Cb98wemz5NYvc4MeM3i8fnTXIBLFFcNimpOZllqUX6dglcGfPXdzMX zOCvOPu1m72BcRJPFyMnh4SAicTP1UfYYOzmvjnMIDabgLrEjRs/wWwRAVmJqX/Ps4DYzALp EpcbloPFhQUCJE6sucUOYrMIqErsudTMCGLzCphKHF35mAViprzE6g0HmCHsvawSk7+qQNiS EgdX3GCZwMi9gJFhFaNQZl5ZbmJmjoleRmVeZoVecn7uJkagz5fV/onewfjpQvAhRgEORiUe 3gt37qYKsSaWFVfmHmKU4GBWEuGVEQQK8aYkVlalFuXHF5XmpBYfYpTmYFES5zX6Vp4iJJCe WJKanZpakFoEk2Xi4JRqYAwu5Z/65Hzo/jydvg3RClPvKz1/13JlbWnkFCkxGeWs8NUl8086 V2Xc3qnNqFF8aso9z1dpFpoXdWVm+5gvjDFXL+E1vZ4rZ/sxX9AkT2Cq3PSjogq71wqHN9Ws 2ND5a529ceDhk5WTA/66Z77MU1r2Z3PC+5d9urHm/I91m1r7TrTGmCzIV2Ipzkg01GIuKk4E AAi0dVH1AQAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFJMWRmVeSWpSXmKPExsXC5WfdrFs/6V6qwaOrnBZz1q9hs1i9ydfi 8NyTrBaXd81hs7i35j+rA6vH4TfvmT02fZrE7nFixm8Wj8UvPjB5fN4kF8AaxWWTkpqTWZZa pG+XwJUxf303c8EM/oqzX7vZGxgn8XQxcnJICJhINPfNYQax2QTUJW7c+AlmiwjISkz9e54F xGYWSJe43LAcLC4sECBxYs0tdhCbRUBVYs+lZkYQm1fAVOLoyscsEDPlJVZvOMA8gZFjASPD KkaRzLyy3MTMHFO94uyMyrzMCr3k/NxNjEAfLqv9M3EH45fL7ocYBTgYlXh4L965myrEmlhW XJl7iFGCg1lJhFdGECjEm5JYWZValB9fVJqTWnyIUZqDRUmc1ys8NUFIID2xJDU7NbUgtQgm y8TBKdXAmLP43r6tf7Nj5J5XzVj3ds9chYrNaZkuUiUNcUdWnpt1vqz72c6zr99/UNhYdodl ihT3tO9Xrha8UkldwROir5z3YM+Js0dD+Liuiu0/0fM+uun3O9MtVw3+m587mHv927Rfy7l2 1q9Kq7QXSa0/c8TVwuWZ/43DxgdWhFVuPDLVSuADs/CR9UeVWIozEg21mIuKEwHr9n3w3QEA AA== X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The current way to calculate fractions for SACN_FRACT is little readable and more complicated than it should be. It also performs unnecessary division and adjustment to avoid zero operands. Prune away by multiplying the fractions by 'anon_cost * file_cost / (3 * total_cost)': where: total_cost = sc->anon_cost + sc->file_cost anon_cost = total_cost + sc->anon_cost file_cost = total_cost + sc->file_cost before: fraction[0] = swappiness * 3 * total_cost / anon_cost fraction[1] = (200 - swappiness) * 3 * total_cost / file_cost after: fraction[0] = swappiness * file_cost fraction[1] = (200 - swappiness) * anon_cost Worth noting that this patch doesn't change the formula. Signed-off-by: Byungchul Park --- mm/vmscan.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 4657440854db..7b33fcc1cbdc 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2339,7 +2339,6 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, u64 fraction[ANON_AND_FILE]; u64 denominator = 0; /* gcc */ enum scan_balance scan_balance; - unsigned long ap, fp; enum lru_list lru; /* @@ -2416,17 +2415,10 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, total_cost = sc->anon_cost + sc->file_cost; anon_cost = total_cost + sc->anon_cost; file_cost = total_cost + sc->file_cost; - total_cost = anon_cost + file_cost; - ap = swappiness * (total_cost + 1); - ap /= anon_cost + 1; - - fp = (200 - swappiness) * (total_cost + 1); - fp /= file_cost + 1; - - fraction[0] = ap; - fraction[1] = fp; - denominator = ap + fp; + fraction[0] = swappiness * file_cost; + fraction[1] = (200 - swappiness) * anon_cost; + denominator = fraction[0] + fraction[1]; out: for_each_evictable_lru(lru) { int file = is_file_lru(lru); -- 2.17.1