From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3962443C054 for ; Wed, 12 Aug 2026 12:18:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537101; cv=none; b=e2LwY0rLRgiwKflqNKZGfRQsglgGg88e3uM773eUE6YmTWfs5vI7QwUi9GmwwrH3hjWjeapE8GIgrbRMLSVJY+RUpTVn560ALfPfuiyoIMohYDK5lXknLUvRfhTZXN655QKkVlF6aE4wH5myIeZsPRpapeifYiRvM+Po5GwX1AE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537101; c=relaxed/simple; bh=tyeXHomLNM40QC+mTekcVRiaWV4us5wp5V5r5jrWOxQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qvMs1bHqGBYDEFOlTgSeh62AG4G0oh6zjmoHYPVtVv8F1G1QUYUQXkViR8AvDEU83o2r3McC/QalcxmZSCQCfz3fKjTsH4MTXSId9BI04EH5P30+Tc+gUfFuyje/Jwe70NHCM9JmmzctoYfhI5C2mqjqOvnnrI2LYyuszuL2IvY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yeol5q/2; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yeol5q/2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 759FD1F000E9; Wed, 12 Aug 2026 12:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786537100; bh=8SPnYkw1Tpm0RdC6K4fEpBajDKizXkw5kF84LatlXqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Yeol5q/25N+xnu1SXOdyiCkZybpJAjBsoTTDhfAYWyjY9mCkLZ/5oJczeJoI9uuWK AonvvY6ikwAM7pWjaw009NzdXeUKBSVAg1uqAp2JpFSQ3dFZwZWK0vb3hnJxyOt4wy 4b3eYJwBF9l/LJqGetsBymGuqJEllDg7uKjG1blNYo9vBYdIrm8q8wNstwZdDW9+Dk zJs4Y1mnlnmt+T43CaOzHcgwuF3hUVCYnvhIAJ7NSlrzAF5G2Xak3LmVCRcJoY8Cw4 QZWlIgZ5+B0+gHvlC4D5RQu02T4qP2hrhjGiBt2qRxIs5HMezylYX6kf5CXQ+zR3Jm yfuATH/+e7d0A== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, chenridong@xiaomi.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.com, lianux.mm@gmail.com, linux-kernel@vger.kernel.org, ljs@kernel.org, lyugaofei@xiaomi.com, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, stevensd@chromium.org, wangzicheng@honor.com, weixugc@google.com, yuanchu@google.com, zhangbo56@xiaomi.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, "Barry Song (Xiaomi)" Subject: [RFC PATCH v4 04/16] mm/mglru: boost swappiness responsiveness in get_type_to_scan() Date: Wed, 12 Aug 2026 20:16:46 +0800 Message-Id: <20260812121658.69965-5-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260812121658.69965-1-baohua@kernel.org> References: <20260812121658.69965-1-baohua@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The linear weight in get_type_to_scan() can easily be overwhelmed by historical refault costs when swappiness deviates from neutral (100). As a result, user-configured swappiness often feels unresponsive under memory pressure. Apply a smooth quadratic boost based on the distance from the neutral balance point (MAX_SWAPPINESS / 2). This amplifies the weight of the preferred scanning type (anon vs file) while avoiding hardware division via bitwise shift. Assisted-by: gemini:gemini-3.6-flash Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index dddd2ecf970a..2fd1e06eb192 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4838,18 +4838,42 @@ static int get_tier_idx(struct lruvec *lruvec, int type) static int get_type_to_scan(struct lruvec *lruvec, int swappiness) { struct ctrl_pos sp, pv = {}; + int anon_gain, file_gain; if (swappiness <= MIN_SWAPPINESS + 1) return LRU_GEN_FILE; if (swappiness >= MAX_SWAPPINESS) return LRU_GEN_ANON; + + /* + * Apply a quadratic boost based on the distance from the neutral + * balance point (swappiness = MAX_SWAPPINESS / 2). + * + * A linear weight is easily overwhelmed by historical refault cost + * when swappiness deviates from neutral. The quadratic scaling + * amplifies the weight of the preferred type smoothly. + */ + if (swappiness < MAX_SWAPPINESS / 2) { + int delta = (MAX_SWAPPINESS / 2) - swappiness; + int boost = (delta * delta) >> 4; + + anon_gain = swappiness; + file_gain = (MAX_SWAPPINESS - swappiness) + boost; + } else { + int delta = swappiness - (MAX_SWAPPINESS / 2); + int boost = (delta * delta) >> 4; + + anon_gain = swappiness + boost; + file_gain = MAX_SWAPPINESS - swappiness; + } + /* * Compare the sum of all tiers of anon with that of file to determine * which type to scan. */ - read_ctrl_pos(lruvec, LRU_GEN_ANON, MAX_NR_TIERS, swappiness, &sp); - read_ctrl_pos(lruvec, LRU_GEN_FILE, MAX_NR_TIERS, MAX_SWAPPINESS - swappiness, &pv); + read_ctrl_pos(lruvec, LRU_GEN_ANON, MAX_NR_TIERS, anon_gain, &sp); + read_ctrl_pos(lruvec, LRU_GEN_FILE, MAX_NR_TIERS, file_gain, &pv); return positive_ctrl_err(&sp, &pv); } -- 2.34.1