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 DBBD6E77188 for ; Sat, 11 Jan 2025 01:42:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 698A36B0083; Fri, 10 Jan 2025 20:42:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 648586B0088; Fri, 10 Jan 2025 20:42:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E9A76B00A3; Fri, 10 Jan 2025 20:42:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 30D1E6B0083 for ; Fri, 10 Jan 2025 20:42:33 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E1E271A0FFD for ; Sat, 11 Jan 2025 01:42:32 +0000 (UTC) X-FDA: 82993471344.25.B962FF0 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf06.hostedemail.com (Postfix) with ESMTP id 3C29F180006 for ; Sat, 11 Jan 2025 01:42:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=LKBMllvb; spf=pass (imf06.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=1736559751; 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=2Csnz0H3OiaEm3BUbEuE3FzYQnQRE649Mta+ZSY9lhQ=; b=WdpzeQlbOKJZPrV1uoojAaiBYit9Vx4tJlcFu1FomvHleQlgCmQUNO8CA5oT0+Ym9fddlG LGSf1zWRyvb5AaC65dePzLsx5Zd3PXbeNM97fd5Ej3xgKpC0wLetIBcH0LA6EcPy9RUP2a Ep1IkYc/AkeLdjp7/GbZLlcl89/gkuw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=LKBMllvb; spf=pass (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736559751; a=rsa-sha256; cv=none; b=gG3F6g/ewsLw6LMMWBB1aVHsjYGEhpUVkc734aJ6wYUcC4v0nmd7PPwi9Mn7y/48LlxCBU AoGdpcQNupV8ZvdVYGGHj7dSmqt1NPVKdEHRizpzH0G9IRcSMaZcx5CSfUaZ2TZnwqN89K 85ZwNMx0SgAg2TvVYZHQKAg8UVLTjdk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1D2E9A42854; Sat, 11 Jan 2025 01:40:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11CF6C4CED6; Sat, 11 Jan 2025 01:42:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1736559750; bh=voSFGedGnmEkAHQ51YCNDRWQkoN1SJiGtrBN7Ic5VMw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LKBMllvbkMbFTw/oFJXen3sZ5cSIEz3pd7buSVfJg7Znr11+0cXjX0X4X4/Ax0/pA JOD4TaPsa0xKqo4/HDDx9fBezIrZEIdodC9sri3Oi/VFb2KJES2O9pZzK3yDYuKisA 4a9oQGmiY/eQjg1g99IaKk2HSa85Wuqh5kHhvsGs= Date: Fri, 10 Jan 2025 17:42:29 -0800 From: Andrew Morton To: 76824143@qq.com Cc: linux-mm@kvack.org, Hao Zhang Subject: Re: [PATCH] mm/vmscan: extract calculated pressure balance as a function Message-Id: <20250110174229.34cba2485e41d988ec37b4f5@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-Rspamd-Queue-Id: 3C29F180006 X-Stat-Signature: 4whmi17384u1ydrsseuigswxhncnnsy4 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1736559751-38214 X-HE-Meta: U2FsdGVkX1/p+0lBUaBiz9q8TITi0b1aDBBkac/a26u1BxEt0cQsWIb4xBddXx1HDREPFiXCir2U1SSCl5G5dzQd4DgHeAPeDlrlZ8uQjqT92+2UAc+U2/hSSCX7dS+tEFcitqGQLWKBXWOkRRdrVYOBNMC0cwGmqgtMlA8JLhEHva6kcS2GJ3Khz0a4gptz04mnFF9AtCFFe9axhTWtBlLIlleX3wXqdrpiRQUtTg9uB9WbUweeuVlPQkke9OUxHm7CPdXbou58rX/jM/BKZ5CQosQrXoj/FdaW8uCi3Okk7PtO5ySfH1E+dlitHvI109fUvRS/5T0Tvyjs4krEBLBFrK862fVb3IWflnPXBNXZ9/YA/c4lP+sS5Njo+Njax51oI99b93f9D8ZeErH1lg5ZFb9DO+k//nWq/1wEQcrqtQXP4ASVUA3phK8tY3JYUqSxTqns8lILzuDprizv5LmGcRsDMEslYlfbaMDzOgc3YzKlerFJOL2UYtoBzVsLcno8t78mk/fqraQ6x/CtAK2HcMfIYE66cHD/GSj3v7bIDpdNwlXA7W6ao2wA8xin9iS2PM1nUyQMYrF5Zdkt8u/23+So4Y+FFuG65NPWhGEfs4D3EZbBsI4VGHysPrOMgvjdIn9gACQS3pWqaf7WLxyARHx3RvSt1Swws3BfGBGhL8s4POqbyD4LYoUBfrI95CKCx3S90ZJ54GwmntKWpdwCR+2amcl66VWeyRh+RCGMs1Dc2o3Ajo0HvTWFH30SgGIyTd374EgYxNFCvXjpMGSmb+OQxlljUbrEY3tiiHTAfJ4wDluLUvvSbDcMvC+PsG3nsF5VVPhq4PLhfC09qcXDzmZTTzJYPYrY4baJjqgordEJ8sIPof65RawjtC7JVbzGXdWHu8luy//Lt96uEkqh66FNM3/FYpoRdy14cc/BkU95M/62yjeO3Z1SkyQK0ENSMmcFkOF5BmrUd3t 7o4CYuWg xOpwJ6uKnTR0PU1wmRrScJ7Ub2hBOp8cJ0WBZP9vRldGEMXYW0+Y9YaXqzAPf+GbkbmOEJ4OkYTBgvA29CWAMr2BpRcrklyDRrUwzeZGTkiBg9Z2fsR6jxDsqelWkqbKtUVMjfTFdVsDNfQT/keCO5iRoH3WHoxShIqROwttfX3l6lwTpVYx5Z5H8ivymi/NIRblmmtv8RbF5Fq14hyJ6h4EGAoln7mfKo73rFWjBja3ityvUynKgRIUo6viscPnE46Y5PvVA3Q8amZ5jCS/i6oq98A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 Fri, 10 Jan 2025 11:17:47 +0800 76824143@qq.com wrote: > From: Hao Zhang > > The pressure balance calculation is only used in the > fraction scenario. Extract into functions to avoid > unnecessary calculations. This doesn't change current > behaviour. The code which has been moved was only executed after setting `scan_balance = SCAN_FRACT', so there are presently no "unnecessary calculations", unless I'm missing something. And the new `bool calculated' had to be added to avoid creating "unnecessary calculations". So I'm not seeing any benefit here. I guess as a little cleanup we could move all that code into the new calculate_pressure_balance() and call calculate_pressure_balance() in the same place (just after `scan_balance = SCAN_FRACT;'). The compiler should inline calculate_pressure_balance() so no runtime effect. > --- 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 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. > + */ And this comment could perhaps be moved into the introductory comment above the calculate_pressure_balance() site. I don't know if the end result would represent much improvement though. > + 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; > +} > +