From patchwork Wed Jan 15 01:58:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 76824143@qq.com X-Patchwork-Id: 13939746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0352AE77188 for ; Wed, 15 Jan 2025 01:59:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E2BE6B0083; Tue, 14 Jan 2025 20:59:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 66C8D6B0085; Tue, 14 Jan 2025 20:59:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50C406B0088; Tue, 14 Jan 2025 20:59:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2C9016B0083 for ; Tue, 14 Jan 2025 20:59:29 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DB5AF160E56 for ; Wed, 15 Jan 2025 01:59:28 +0000 (UTC) X-FDA: 83008029216.25.5EB232F Received: from out203-205-221-221.mail.qq.com (out203-205-221-221.mail.qq.com [203.205.221.221]) by imf10.hostedemail.com (Postfix) with ESMTP id 4FF98C001A for ; Wed, 15 Jan 2025 01:59:25 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=wyERCYsl; spf=pass (imf10.hostedemail.com: domain of 76824143@qq.com designates 203.205.221.221 as permitted sender) smtp.mailfrom=76824143@qq.com; dmarc=pass (policy=quarantine) header.from=qq.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736906367; a=rsa-sha256; cv=none; b=yIjaHd+8GP2hOq9TbIuBvV1uspkYumyuKAYA3sYi63l+RLWDKUkUg2QILnXH1W1Yp6p4W5 g7/ifYuWdlf1PQUUNg0/equXNQSiCAuWU1F4xOpDAyFekefi2HMd4f+ssEjsiWW8LNIe58 H31WlAB98WIq0x7x2YyB/ha8z6M2dgk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=wyERCYsl; spf=pass (imf10.hostedemail.com: domain of 76824143@qq.com designates 203.205.221.221 as permitted sender) smtp.mailfrom=76824143@qq.com; dmarc=pass (policy=quarantine) header.from=qq.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736906367; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=RellcvkUHkA4sw0a58XvSlJvCTmXtBMeYC0mtcKT3ho=; b=vkIyVUogdKzmgwuWPg47JAgLUxsLlhM2CfilbC9kgXgBa3in3N/h3D34/nSzl91vN5/dYE qqtsWgzZ9O6Vyd2VQbhIOH5eM2fpNk2qBW9dhggIbLUmtrJ2h+EqJN4y2C7t9KOTHxBKOA 6d8FVMCobhotr7fhuEy5BIMCzzz/8zM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1736906351; bh=RellcvkUHkA4sw0a58XvSlJvCTmXtBMeYC0mtcKT3ho=; h=From:To:Cc:Subject:Date; b=wyERCYslXAPe7tKyrRXJtCF+cUQtXrE0BdqRNFVi28dLgrt8KwMmXnb51M0NAzsvs 7FU04BC4c4ld50lL75w9+7+V+zg7kNG/zf9RvsMVW50BZefp8x2Jcb3G1al4J9dRTw b9RyRlRT9OOKvjKzACvaaC5BDzoFjsslPDiY/0uk= Received: from localhost.localdomain ([116.128.244.169]) by newxmesmtplogicsvrszc13-0.qq.com (NewEsmtp) with SMTP id EB703C9C; Wed, 15 Jan 2025 09:58:55 +0800 X-QQ-mid: xmsmtpt1736906335tkhe5muay Message-ID: X-QQ-XMAILINFO: N/WmRbclY25GHaAGS19ejKantZYAFvWbyOQAkENy1iBScy1DmAH8suNnwmdoph 6+DseBs0hK2mfI//yoH5ra+OHM/LUXJ5CJ74nl4+QCB3e1c+qEaZiy/LKoOq0s55/iThNWoC+6rd ajbL/sQhxuZsPEx5Uf/g/6lg5nXAKTHAsuOQwcUykzVbQovvywLVGxejYxVn1ai72sCC6+dUlOLQ XS19l+xsOqTabGjNmQeY2IvTlULgw2h3OPKwDqICp71kGC1bZvdhS+2LvBG/xTt3qmTcMutEVWTe 1ANnD5XooLrldrR/aCtvyaeEAjiq4uaOyvMhhEtzsxwoeEe4DvSj+cNIERK1cAWaMnf4BzySkA5E OmlPjCgnmv7t3ZKPxBqTAQ4tYPzVy/vQlI2vyVR4/1p8k9WKW45VtE0QGajsDeGkVaqFckjiPNoC HKC2cwh8XsWkqpv5EiUsldvPYL00JLL4Z6YJ4lxiHq7gCbsb+r+tH9O3ETjoQ2htTM3AygW/jSkV kS3siwL5iEybnybEP8cK65cJYgb+gC/u7rYXljhExlnE9IJmQhfWuH+NR5I7Nt+qOgwXZOjHGXiU 3R9YE/Af3vkkloR+rwWl8/+KGrTKqTu9Elgh9Fg325oNzPY85K5lDjSmtmz6dzBbNgvnqHhHZm4G 12pbBfh+BR+FqIGT/t/JJaEHdADiJm3CLGeJbesLUR/cp88P5EAfgwjcK3idaG4OTgnXSAtuewee o0MoTGeMvrE7vmAOsSJZYWleW8KcF/vgFsD9j18CFY6+HdxweTWckCL6ua1JOqXRy8lith1qlMIQ H3N1nVn4wlEYuggq/Tzp+7fglTPmX5xt8ER5PNJQ/iwCcjoX/QT3tLAp6apMTXdStZqZfjqLGlz9 mOke9b7DnJaD4N0ZBDdd5l5fITLUbcuUXEx5FJpLVviHphluU3igBPZSLR7sTJkru5VN2gCysAKb AC0GuvIwp0WViypVwPXn2KFecn9uI3duF04RKDVfr+gSVIH1FHZw== X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: 76824143@qq.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, Hao Zhang Subject: [PATCH v2] mm/vmscan: extract calculated pressure balance as a function Date: Wed, 15 Jan 2025 09:58:29 +0800 X-OQ-MSGID: <20250115015829.27859-1-76824143@qq.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4FF98C001A X-Stat-Signature: pjuw3to5ddj1pjiajzneceg5oga3f7ye X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736906365-310204 X-HE-Meta: U2FsdGVkX1/TWtz83iDvOTOThxkv/8Nuqzw73M9JNgOESFg4mf6HKeGnSPteDgvdIprK6srLWfzhxKyHE0V10wul2cB4ytpVe6zWGxCWWha9GT6UUIcDHKujME1UwApcMC4V8cW+FNkRz3KB4mBKUYkSkauPp/WbzYVFT3fbHxgGzK+hSwOHHzoDyWDhAAf83LjdnOe78WrMxCQamo0OOBbjbMgND4eLc7xHTL1xsftCnxsOAOqhpJyUikYLmRbvqEfbyqEMOjA79Feg9RFb4t9yBofUahrVyk0RsSWIJJM78IoiF0rOH1QBZnSfkjK2sB76gYKSoiNl+al0aFN+U5SnADF5opqEDs9lnT+lV0rJtZRm4UHa9ZI5e6YU/JJO0v0rMIab7h792/iOOYSLKc7qfdDd0jMI8wRQS+CPawmDOu/tVLZFydLI7FYh2zqZZniDKtMYQ442r+LiigHKoAIQe+6Rsi/c2MH2rz9p2qEY856sko5stTks36gwdQFsdcN+shrAs3ByD39aP3+wg9nzeAWNonInpXFiieeMV5YMonWLLZsEd/ekhdOaZHWUDCnql7xp2LvKyopFyWp5Sj1ggRohVO9qVd8rQ13mCn9vkKoEJjM7dZQDB6NX35wsNiQvNEox1/f9V7GcfgDBpjjPe0aVZ4iD5qVCCWtFV1oVy6xyGL91FHCyYDVjT4FAwF2CcVEX6RcMqZNnIUR/Mcn01yiqiv5hs2PKdasosL2Ss8PUR5z2oJQpMDpA4dAVQ4H6VnslfOW3UKNhtkRu650m69uqVuAf7PYEN2tHnHNSLs0sQtYbJ2ye76S9u2F8s51CzGrEcI2HtMgzeOjk7RYjtMOyiVFWYkORzlOgMapzy5JC5cOeQ3MMV+I60WpNMMrBKpzKKUb48LGGubfxiE7Wadlf5qgStpoFJz59za4uwCNGsZGimbFr6KfKyOWlq9UK8h5tARvoR5vVvRT pwjfCXKV InNxFBTjK7CS4gmLfh8gRaLRtYJFWFLIDn4EjdMDkaHhTj+8tvBoO3jq4oGf4r1T/DXXU+6ZOAAwLbDqaJs6dFiZYCNi+p3YSsWlNxVrvAm6prheJpkFnYgdGUDzFgEoFv3xhgMcNelGAExWI7MzVsOleMb0PEha5xcpnPAyb7SbRXXW0KWTLDza5CRugTYGkCdmd1JXRz2GeG98= X-Bogosity: Ham, tests=bogofilter, spamicity=0.239949, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Hao Zhang Extract pressure balance calculation into a function.This doesn't change current behaviour. Signed-off-by: Hao Zhang --- v2: Change to a inline function and call it from the raw place mm/vmscan.c | 68 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 30 deletions(-) base-commit: eea6e4b4dfb8859446177c32961c96726d0117be diff --git a/mm/vmscan.c b/mm/vmscan.c index 9a859b7d18d7..7bd2b8fe9eda 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2367,6 +2367,43 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc) } } +static inline void calculate_pressure_balance(struct scan_control *sc, int swappiness, + u64 *fraction, u64 *denominator) +{ + unsigned long anon_cost, file_cost, total_cost; + unsigned long ap, fp; + + /* + * Calculate the pressure balance between anon and file pages. + * + * The amount of pressure we put on each LRU is inversely + * proportional to the cost of reclaiming each list, as + * determined by the share of pages that are refaulting, times + * the relative IO cost of bringing back a swapped out + * anonymous page vs reloading a filesystem page (swappiness). + * + * Although we limit that influence to ensure no list gets + * left behind completely: at least a third of the pressure is + * applied, before swappiness. + * + * With swappiness at 100, anon and file have equal IO cost. + */ + 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 = (MAX_SWAPPINESS - swappiness) * (total_cost + 1); + fp /= file_cost + 1; + + fraction[WORKINGSET_ANON] = ap; + fraction[WORKINGSET_FILE] = fp; + *denominator = ap + fp; +} + /* * Determine how aggressively the anon and file LRU lists should be * scanned. @@ -2379,12 +2416,10 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, { struct pglist_data *pgdat = lruvec_pgdat(lruvec); struct mem_cgroup *memcg = lruvec_memcg(lruvec); - unsigned long anon_cost, file_cost, total_cost; int swappiness = sc_swappiness(sc, memcg); u64 fraction[ANON_AND_FILE]; u64 denominator = 0; /* gcc */ enum scan_balance scan_balance; - unsigned long ap, fp; enum lru_list lru; /* If we have no swap space, do not bother scanning anon folios. */ @@ -2433,35 +2468,8 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, } scan_balance = SCAN_FRACT; - /* - * Calculate the pressure balance between anon and file pages. - * - * The amount of pressure we put on each LRU is inversely - * proportional to the cost of reclaiming each list, as - * determined by the share of pages that are refaulting, times - * the relative IO cost of bringing back a swapped out - * anonymous page vs reloading a filesystem page (swappiness). - * - * Although we limit that influence to ensure no list gets - * left behind completely: at least a third of the pressure is - * applied, before swappiness. - * - * With swappiness at 100, anon and file have equal IO cost. - */ - 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 = (MAX_SWAPPINESS - swappiness) * (total_cost + 1); - fp /= file_cost + 1; + calculate_pressure_balance(sc, swappiness, fraction, &denominator); - fraction[0] = ap; - fraction[1] = fp; - denominator = ap + fp; out: for_each_evictable_lru(lru) { bool file = is_file_lru(lru);