From mboxrd@z Thu Jan 1 00:00:00 1970 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 DF107C0218D for ; Wed, 29 Jan 2025 04:15:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1529628002D; Tue, 28 Jan 2025 23:15:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1042228002C; Tue, 28 Jan 2025 23:15:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0CB628002D; Tue, 28 Jan 2025 23:15:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D44AE28002C for ; Tue, 28 Jan 2025 23:15:33 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2BEE8C08C2 for ; Wed, 29 Jan 2025 04:15:32 +0000 (UTC) X-FDA: 83059175304.20.53BE0B0 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf01.hostedemail.com (Postfix) with ESMTP id 66BD640004 for ; Wed, 29 Jan 2025 04:15:30 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=VSFMqxih; spf=pass (imf01.hostedemail.com: domain of akpm@linux-foundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738124130; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sSom5vzTaFCmKZVM5rY/glfIhrYcZb4z5jtYjAhtRHQ=; b=lzRwzTu2C7tXOpqmOWaYF2lD2hxxUymzB8jXHM+5oE7YHlZwuJRKGaXGo6KyMXreoCNQIX ayInqlnM8bXYeZ4E00ERGMXa2H/hly1EcOXDDnVNrQUxC196C/smkGYSb+bnhwgL29D2TE JcchxRcndhx6kyldZX835kgc+Z8zB20= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738124130; a=rsa-sha256; cv=none; b=xqMtCLkpfmzJNmW86mZ7Rko1R3VGuhOMzI60j5K8+nYzdevzWr4pZR2shg7IOyrlujOYnX NtuKJXWLTLlrfjcqNL7cIMUj1Vd24oaTawC8i5+OBRIR5ZAkMEgePELAmg9Mnegj0dT1WY ufqpL48FdYPPA64ccpo0SJ0VVCph6K8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=VSFMqxih; spf=pass (imf01.hostedemail.com: domain of akpm@linux-foundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id AC6E8A41311; Wed, 29 Jan 2025 04:13:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DADFC4CED3; Wed, 29 Jan 2025 04:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1738124129; bh=1TXe+LdPJbS1UGR3K5lG5Agbsf8wycTffWM/oPvSho8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VSFMqxihSJGTVZpu6YOPQkCoFC65YWfPlASzytQxrjL3+smQTI4xiHPDEamM8mMiO RzSKdm54aYyd2Wl8R/EUx2XJhFjJrveGs5vftS1jMAHrZIQ3kovBCH/noC3lid3fPc 0e9N72RVNpBV09WfwEjTCgZAiPXqx54MI169bAUg= Date: Tue, 28 Jan 2025 20:15:28 -0800 From: Andrew Morton To: 76824143@qq.com Cc: linux-mm@kvack.org, Hao Zhang Subject: Re: [PATCH v2] mm/vmscan: extract calculated pressure balance as a function Message-Id: <20250128201528.5bf3f9226057f4ea0e12d18a@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: x5s1rjzyw5z45diup1oyrkkwfbdqydnt X-Rspamd-Queue-Id: 66BD640004 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738124130-336547 X-HE-Meta: U2FsdGVkX1+t5vV5e/S/ecarGUkUOnN++QlzHyScRLd4Lq4AU2eqfEuWBZs2M47YVSRba4/wcdYz9D9a+nbaYPPoeBLLZhOHSu36FJXagFeBl72VyeAGBeHa7sc5PrjDqgZIsf0hI06DYz00ttsqUCPye9tkfyGGj3eGdIoU4rn9y4+kNSoxPGxr9i65dkIDLOPSXKafH5YtI4FcSBcpHqaP98oAwX3TYBthbi5kNUTb9SGpzK1csg8wsQCrtIBNWT0M+y3rV85bVJsL8QcONpIbG30GBn/BUQW/1HXe+O6M1xKTycINEv60wyCy0+F6TAT+qZyioBerAPvrxK66Gb6VUdSPiWHY0qT/xQsEvOw8JBTqBJL1J2JUCghygHv3B+2C+eZgpqBwgEfrvtsgfLI6gWri05uwser8UDeOiEgVQo87F9QscYVGXLC/wqGyLnMduEUr3KPRstX5x8+zfJh0DyV0se2w5+YbjeOTvCMrvcBrMrU/7x5/i1lYZuieg/2WDOfik43OAoh8yMOCSNNIiZayDiVOTpyVfpQ8nBgxIU8MdNZIrABXWzFRF8mqTK0/dhoDONLO6b3aaC1xifQOzE0FQ+bRvj4NOmNqBoz2VkUb/Hzey7mnEalONZPdF7seBGTcUMgnBt+A4bhgi84rvv1aXuc1+nJUR7rOyD0aBTuyipv5KmLVL/SDlRVYs9d/8vIzH5X836QIABNxKrSt0r46DHUkKpvxZZJqBdiG5g5ZR6Jw5CkjIXEIiBH0hAMjvfRl4+Zf77ba6HiBtAAE01GLrpTc4FW8pqsNidwM/pGWpQuS+4EJzq/spuXBjqAsAhblNGPLA2/nTJqTS0Xwm8XVs6mCc+aXSF3LgL8GOefeqkYbui0PHKsLvJ9HL8Rap0lLHvwck1M5fk4OYRhJLp/fmk4EF1o/QEroi6Gx8OMQKpE7R03fmKbXJG2uiD/1DgyYqqmq2PjDh// pjs6Vckr XZi3fb/Fs2dahRP5VVQuyksl6G2aSaOvlq9T9pTbLZUctuALFuSuutVa9jU2ZPynrIVeNaeZAqgMBgUMjCxkZFPr05k3+UYF/Lz0Vzd1BCYP3ED21dFmoOHhElEX1uHMHn2be9svCU4pVo5H7k6Evik8F3TQfs55zsGvOJSoSmIA4uLe22WznUd9TcFXOa8+t6wmESLp1sHsQyuGpG8Or2nG6DW+rtr9txf4B8ZGOHJlHpyigLqPtkKvq0wC7aPRzLxe7di72eG0JJEo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000951, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, 15 Jan 2025 09:58:29 +0800 76824143@qq.com wrote: > From: Hao Zhang > > Extract pressure balance calculation into a function.This > doesn't change current behaviour. OK, I guess it's a slight improvement and the size of my vmscan.o is unaltered. > --- 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) As we're wrapping, we may as well wrap within 80 cols: --- a/mm/vmscan.c~mm-vmscan-extract-calculated-pressure-balance-as-a-function-fix +++ a/mm/vmscan.c @@ -2400,8 +2400,8 @@ static void prepare_scan_control(pg_data } } -static inline void calculate_pressure_balance(struct scan_control *sc, int swappiness, - u64 *fraction, u64 *denominator) +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; _ _ > +{ > + 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); > > base-commit: eea6e4b4dfb8859446177c32961c96726d0117be > -- > 2.25.1