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 2FBA0C4829E for ; Thu, 15 Feb 2024 22:58:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4543A8D000E; Thu, 15 Feb 2024 17:58:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 405498D0001; Thu, 15 Feb 2024 17:58:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A3A08D000E; Thu, 15 Feb 2024 17:58:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 196B58D0001 for ; Thu, 15 Feb 2024 17:58:08 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E344C1C0F26 for ; Thu, 15 Feb 2024 22:58:07 +0000 (UTC) X-FDA: 81795553014.17.84B4BF1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id E4614160004 for ; Thu, 15 Feb 2024 22:58:05 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WCB6gHCe; spf=pass (imf08.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 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=1708037886; 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=E0QGPd89Ry/AqF8UHJgyFe5WhVXXpwEMSkENZgJsuCc=; b=cGZT/bdrEI+Lvv4Aa6PfA0Q0GGg3+ePQBe12pI7h3R5eRolPEd5hLVakUgi5lU6p96QPdm aEUGDbH/xOAIsFhQP0qFJ+wq7vm2RfiKqcOr3sHx7qIzWbG9B/hFu5dDi9Ief1Ig1OOeSn 07EMGm2gRIIWKi/6X2fvRCVZ0jawcVE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708037886; a=rsa-sha256; cv=none; b=WrYyZHiMfY8dODkWg/5ROMlC94lDtxzp1E891VZEgNd6aJn9yOYKNvz6j7ytTbDuHz8vNk IkDnrBAvSt6hzqvWbv5x6mOS8UGNJeuURcabNyzfd6NFH74+T4fDjc89Ykwbo3tuOq7+X4 cUl8Z7S1xx2f9xXFtoCoFb6ZHQnZnW4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WCB6gHCe; spf=pass (imf08.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0DD1961E99 for ; Thu, 15 Feb 2024 22:58:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD0B3C433C7 for ; Thu, 15 Feb 2024 22:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708037884; bh=hVojgddXNYGq5ilJ1BQ3DJHe6qOJaFaqPGQxuQ/fb6A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WCB6gHCexF6ieyybXSNS8Le7eifsGejHlrgxq6ctGXR/clhL7vo0s4ZN4+ULeUu29 s9f0ESxiFzEGhgN9+ABrG3jiZdoNsy3D1l0rV/rtEW83WBt1+yxCixX3r/Ky2IuRJu rOdqYPzieC3rgSbYLOqZq94FytF7uNgZ3HeVIX/jWDsKLDkqkrLq0FRAWI3zX1EYQV x++ij6l1Pzhwn11wE8fJF+ozpyFM40M8cwD9CvicV0ES2WCM6mN8/6ROfLCdo9z8P0 +YL73OX0VjBquWwB4PB07ndzWHVmhh/N1t9HySBz1kK8gS0IuX1j62A147YLJagWJw Bsopbj9pgxg5g== Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-364f791a428so3614305ab.3 for ; Thu, 15 Feb 2024 14:58:04 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXmRXBzApvKgFn112R9Zt95P7fPxqt8SWsLEpufnsEHM7VnXJ3St1gL1syTcb+B6SX3o3ZfbQYoTZabuyRSW9P4sjA= X-Gm-Message-State: AOJu0YwjHp2jFYs9w4ZTeq76g2/3EhKa7vNb20RyLXNTphYYIaV8B5Vs NTZTrsRaFnB89WXlBgxYJ+pvBOvGgM0/hdRsbRvFjEgtDLW+GXnsuoce2y2j068VU3WW+403hFZ MjjRPmDW1LQGc06msczhuAlzBl2P4MxLF4qe/ X-Google-Smtp-Source: AGHT+IGfP74GkKlVuV8Htk4dGfX+hfymzix0oMGhP4DC3onmny/GHmV4R62ZEf3W8nfKApL5C4GMSleLz7euSTLulCU= X-Received: by 2002:a05:6e02:13ca:b0:364:216f:9ce7 with SMTP id v10-20020a056e0213ca00b00364216f9ce7mr3017921ilj.15.1708037884021; Thu, 15 Feb 2024 14:58:04 -0800 (PST) MIME-Version: 1.0 References: <20240214-async-free-v4-1-6abe0d59f85f@kernel.org> <0c5431d984fe518f9f9b2f85639a6fc844115deb.camel@linux.intel.com> In-Reply-To: <0c5431d984fe518f9f9b2f85639a6fc844115deb.camel@linux.intel.com> From: Chris Li Date: Thu, 15 Feb 2024 14:57:51 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4] mm: swap: async free swap slot cache entries To: Tim Chen Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Wei Xu , Yu Zhao , Greg Thelen , Chun-Tse Shao , Yosry Ahmed , Michal Hocko , Mel Gorman , Huang Ying , Nhat Pham , Kairui Song , Barry Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E4614160004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: bjurb68p7fyjmue6gcqapdgf6oudtg9s X-HE-Tag: 1708037885-160601 X-HE-Meta: U2FsdGVkX192+5Ih0EMj8q0x8ShD1BzgufG7WKH4TIuz9vGN/i0MwuzSzeIDgI04unXHZJ/g/XtLR8vuVHQematE+2s2EikzDPh9z3ojtTkMhhL9B7KyYZFCq95ieZEKfIND5mVCZCyM8jqJG+lH6rdkWtmvX8/u2y14juv11V29N+ds7IFSOfsL2v5Kniat0PrRVzter6aMgHjT9ksDs1POPAuycDHa0nuQfvU0X2X0EuCVLj/ITWUTz8WZFN5KVfZSR+seceoh53uOlRVgB+Gb9lIC2q4SwbMu9g5cjDWW47k0tD5ZJg4zmeZbFXGd5FVtzh+lfdmeJI97Eb5ziqG8mvOrclQLNDCYYuq2ySLIvWLN79flUOpGXmEjwD8hC8bRm2x81cmFny9OmBb/Z6+RqGIELjR5qAk4aggnQ2jCMD4HzLtNwf6JCUA1m+zI1Zhmm5tFOcLdlNCZuIXT/5BQTOTvjD/yubEG01Ffe7U+0dJdQQJEHzGgRba3cq+cfjKOPGscD1UW5I6izjpBWvofwC27SWYMxh91KRIeKga3VqEkU5Jl+/pvWRCw+hJEU9doms0EnrrCD1+jovF7X/0fKvMFREpVI4e8ez0unsLnmmBuxqSuoF3Ybtg8t+q5s+A0UPCjpULO9UF7qloe/bNj4iHc9PDG7G5WyApM6EjhccLsqJFub9u5i9VokjmIYkqPfdUhCgO6/1Zk0Fj+AFmn08taLjKGM13GIB82QWmtv3wR2WJDKbLcQpmGZohk39iuFEflCrAFS1I9lnw4KxeFpe0iNMcSLZNMJ0e80xB5HwcrJ5cZ2QC1dN9Ew2ybcr/QW6c2zgaleSBrmOnXVTOeRMdqdLLgB6zbQA10hhZeZSMKJtCFRRKZp7nBM0bP6+usm0vuPKmHdPE4rd92SGgCM2NB7sohr79izDgg69L5/ZFesziodov3XZ7PyIb3cIksvRAmuB/6ZJ0wJFR /LynvEDH gPdu2cjTq8A4wHt70KSbgiegYvv4c2mNJy97EMM2NjMF1s5r2b1gZRYQ0eVs2yLUEzE3V3xZ9J1SaLDVvdrTIx07qV4crplBPh+5bbJU8WoyCRaa74vmqORsITL2OLHPPfy3kjnSMv99Wi8Sau7mwfiwzbiDYzyLqBVXFxHxOerXwSV+p7EPRwEC1AyGcshqZIlQjwHXOI0NAm5Al5bRdiVbvLz/15mwmJ7Ri36D8+Ohy86UdVadSARNCCtSk4+CCe2McDzd7D4k+hZ6u/c5Bk6Mce2yOxWzBrs2VBe2r6hFgFmw= 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 Thu, Feb 15, 2024 at 10:31=E2=80=AFAM Tim Chen wrote: > > On Wed, 2024-02-14 at 17:02 -0800, Chris Li wrote: > > We discovered that 1% swap page fault is 100us+ while 50% of > > the swap fault is under 20us. > > > > Further investigation shows 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. > > > > When the swap cache slot is full, schedule async free cached > > swap slots in a work queue, before the next swap fault comes in. > > If the next swap fault comes in very fast, before the async > > free gets a chance to run. It will directly free all the swap > > cache in the swap fault the same way as previously. > > > > Testing: > > > > Chun-Tse did some benchmark in chromebook, showing that > > zram_wait_metrics improve about 15% with 80% and 95% confidence. > > > > I recently ran some experiments on about 1000 Google production > > machines. It shows swapin latency drops in the long tail > > 100us - 500us bucket dramatically. > > > > platform (100-500us) (0-100us) > > A 1.12% -> 0.36% 98.47% -> 99.22% > > B 0.65% -> 0.15% 98.96% -> 99.46% > > C 0.61% -> 0.23% 98.96% -> 99.38% > > > > Signed-off-by: Chris Li > > Reviewed-by: Tim Chen Thank you so much for your review. Chris