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 4B6CDC46CD2 for ; Fri, 22 Dec 2023 23:16:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 976A68D0013; Fri, 22 Dec 2023 18:16:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FEC68D000D; Fri, 22 Dec 2023 18:16:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7789E8D0013; Fri, 22 Dec 2023 18:16:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 626F68D000D for ; Fri, 22 Dec 2023 18:16:49 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 33A62A24C1 for ; Fri, 22 Dec 2023 23:16:49 +0000 (UTC) X-FDA: 81596016138.29.B44E584 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf21.hostedemail.com (Postfix) with ESMTP id D99F41C0006 for ; Fri, 22 Dec 2023 23:16:45 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aerR3g1U; spf=pass (imf21.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703287006; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2sEr1AiNaFtUviujCf/L2c+hnZauxs0mM9dItjP1uhE=; b=lzbNHeNaBQiXfuSIDpKm3SerOYy+4TH5BdZq/MMl/nP/LW2KaC4rvOY1De5Mug0WmAjABE DG5pe7p+ku4qWRd73aPRNRLYjr7u+8BfrUy1LH9z/sgcBqVjjXWSvsonO/FejWgx0BPV9f h7QrqWkiLiSnOnnX8W41d1aNe0PYmNU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aerR3g1U; spf=pass (imf21.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703287006; a=rsa-sha256; cv=none; b=f7xd5PD5yi/A0y1BeMeImWeKbH9qGkLhePQE1UBeClfHtGoGeQSkKtdLtaBCMN2TSqMfWA 4JMhjS27Y4dbQdBhdMUALe1TE21B+kgsqBBvwsnjDYnFsxaAzvno3gKUscXtc5+uY7itro eG92iYCNdlyMvn9Wjy5OJr2xT1iOgJw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E3237CE22FF; Fri, 22 Dec 2023 23:16:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C65BC433C7; Fri, 22 Dec 2023 23:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703287000; bh=PuoJSH9edJoo7oeOjVNTX3jweEOc6MbjFIsvStWC698=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aerR3g1U+YyKbb3C+3gfRjRJXeoL2jnnN7yfEMpxtc2pkeGswJJCVwAvBrQJf325w hP0/s34sO2lIObDxMgZDVi7h+pjCtDJ33POD3VrEK5BNi6+hJFFwrfIbpZhUloK1ft ldxE2PkNhkeEwtAjAWfSwCuw9lzm2O7zfoAODNydNC4YIGQuL3hsHAx55Dk0FyRuxk dSHrh0EFwzBOIvljHGdywML83g6OJ/AHfs1F4hDMJSbGfgqku8qroP5TfYtDoeqyOB oGLp4yKc9zMXxVp1uoMX9S/5jKVZWbZwquHj7XwlTwqWW31h2YI46+4LsapQRc0hpE 8WkWj1uCcXL0A== Date: Fri, 22 Dec 2023 15:16:37 -0800 From: Chris Li To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Wei Xu , Yu Zhao , Greg Thelen , Chun-Tse Shao , Suren Baghdasaryan , Yosry Ahmed , Brain Geffon , Minchan Kim , Michal Hocko , Mel Gorman , Huang Ying , Nhat Pham , Johannes Weiner , Kairui Song , Zhongkun He , Kemeng Shi , Barry Song , Hugh Dickins Subject: Re: [PATCH] mm: swap: async free swap slot cache entries Message-ID: References: <20231221-async-free-v1-1-94b277992cb0@kernel.org> <20231222115208.ab4d2aeacdafa4158b14e532@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231222115208.ab4d2aeacdafa4158b14e532@linux-foundation.org> X-Rspamd-Queue-Id: D99F41C0006 X-Rspam-User: X-Stat-Signature: m5pphpu5ox5mzme6wp7pkuhewgg1y41j X-Rspamd-Server: rspam01 X-HE-Tag: 1703287005-609503 X-HE-Meta: U2FsdGVkX1/DIBfkPwRC/rb/zM+sU3uLuk5+zrsqU+6f/OJ4eNboi5gX17d6kaw88z0wZsZzIxVKT1zr9dzNcL54NgeNZzJQT13tGTd6FO1MBZT/FxAi6ve6wFXuxpO4vO1ddUwjrFff9LSTtrxvI/hTMnSA3zQq/8kqRzAXFR0gET+2XPJO+PX/4F1uOY6Bkt8cnIMQoZTjlPjueiHhGpAkLEsmK68gP3BX7svitDVmhIPdx9x07vAEcTBypmeuQlKOb5Kt5cR56mDePHB6XxGETzK1AHsqZRiULOR2Ptmgui+RaA5UYZ+MtD5JEq+iN4WFq5w7KYcAjWKzpuYvQNDkyxSSDypMXGCy6koqoQTE2PrDynybiPfHWHRLwhdvMKpO8l3wgDxVbYSpeAlY237xwZxtueq78dKkHBgYU9+CILaGiQtM9JOT9qVyCR5iS0xm33zD+kdP/3Pavx9ER0XxuRJaKGcXp48Srg4t06RCXRlJRCFk2p2xaqoPtC9mPNHoqcQ3/UEZqnMSlrRVPt8kxZyPGqmUmH7kfcpMwr4359lGVZqGEOzWxh3iOgT6vwu4OnUMbiv3RwZEaBZ98mrpkL8cPCjECH2LyydEMHVgYMdYt57V2SE5t91jIi4DjsgXyPZYp6ZMHPcFwdZArgsUf5170ihYW39gJLWsWscziSdlmDVDBBRDVWXLmphY3YJmeOFeQhDMZSdVXOGUSO1x5f7g8xZwuXor0ic6KI6mXZXu9dr0LBeM7s+pRDdagODJr6eFgMjzAal4KalUv0X/6g0Dyu4NIt5nspjz8vGs1UfJiKQU8sbwZxozKtgXGGdWNWUESy+SaXTgI3YPma6ycBOPH6mEuyLm2exjj60HaryzxR1qHGSVLTv8/qu3vkQYQ7cdNsSmAYXXL94ti4py5Un/BwWURmoYsNBIZkQQRyrNUBZHr4nIxwGMSbdMIJgN4aEBqMZFHcRpTRd zp9j4mW5 f2h8a7VT9UnZeCxZtlbQ3rtumM3sU9COb41Q3uzqXS5HYMUaIBL3To5N8irPxug6Faxl5BgjL5YTzk0GGWakeC2t8A0XxPsOGPmTD7i1ZTVSG6N7wZY6sKvVxf0Nc2iLr7wXkOTV7Cu5JFiYzstTIA8H/lcG+X9aKbDnR6lKx/kVEw1OC0S9jLehtaR/kMMygH8cosrwRWXovHcE= 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, Dec 22, 2023 at 11:52:08AM -0800, Andrew Morton wrote: > On Thu, 21 Dec 2023 22:25:39 -0800 Chris Li wrote: > > > We discovered that 1% swap page fault is 100us+ while 50% of > > the swap fault is under 20us. > > > > Further investigation show that a large portion of the time > > spent in the free_swap_slots() function for the long tail case. > > > > The percpu cache of swap slots is freed in a batch of 64 entries > > inside free_swap_slots(). These cache entries are accumulated > > from previous page faults, which may not be related to the current > > process. > > > > Doing the batch free in the page fault handler causes longer > > tail latencies and penalizes the current process. > > > > Move free_swap_slots() outside of the swapin page fault handler into an > > async work queue to avoid such long tail latencies. > > This will require a larger amount of total work than the current Yes, there will be a tiny little bit of extra overhead to schedule the job on to the other work queue. > scheme. So we're trading that off against better latency. > > Why is this a good tradeoff? That is a very good question. Both Hugh and Wei had asked me similar questions before. +Hugh. The TL;DR is that it makes the swap more palleralizedable. Because morden computers typically have more than one CPU and the CPU utilization is rarely reached to 100%. We are actually not trading the latency for some one run slower. Most of the time the real impact is that the current swapin page fault can return quicker so more work can submit to the kernel sooner, at the same time the other idle CPU can pick up the non latency critical work of freeing of the swap slot cache entries. The net effect is that we speed things up and increase the overall system utilization rather than slow things down. The test result of chromebook and Google production server should be able to show that it is beneficial to both laptop and server workloads, making them more responsive in swap related workload. Chris