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 230ADC433FE for ; Fri, 18 Nov 2022 21:51:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 803498E0001; Fri, 18 Nov 2022 16:51:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B2F56B0073; Fri, 18 Nov 2022 16:51:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67A998E0001; Fri, 18 Nov 2022 16:51:39 -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 5A5366B0072 for ; Fri, 18 Nov 2022 16:51:39 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 236B01A10BF for ; Fri, 18 Nov 2022 21:51:39 +0000 (UTC) X-FDA: 80147910318.19.CE60C7A Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) by imf22.hostedemail.com (Postfix) with ESMTP id B6D61C000C for ; Fri, 18 Nov 2022 21:51:38 +0000 (UTC) Received: by mail-vs1-f48.google.com with SMTP id z189so6038120vsb.4 for ; Fri, 18 Nov 2022 13:51:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=08HxxgTebFcooUTsB+QKghjflmDNORIosXugPLRxd8E=; b=fb0Z8rqRbaefHBnNl6KrfgYmR1JetE39TbdsqSIVcRtN5HMs54lmzZybtSvP2EqEuO xG+SDXcerSZNhmUbzfuWgkgjThV4ZczX0EVxa9z/XSpC+Hwrutv3f6ozYPfIdbVYJNCa +Lfv8j6Ytfex8FvX1PN3LowfMwv59Q/mveypHp8iuFgiInG/YWAvfvpqKTljD5srY9k1 r9vMhVAqpyVFTVVwEpoYreLdv5J8233wNPjxJInr+JfFHWoDw2SLCwEjEjzSZ/Lz9yYw 6u/CdL2o3J3Wijye9w71KHowOBKWjLUtEJ7MJi74jN31oadisNGfRMcuWX3J3owto/Iy 8DRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=08HxxgTebFcooUTsB+QKghjflmDNORIosXugPLRxd8E=; b=Nu+7zSEsv4Uwu+eNu1s+ib/6/xAQn5cCK53YIVo9fXV4tsu6Q/KAL+5VH8hbqc8VDd WlauPTpV2YXD+WaYR2PVT5yPqQeA7kNfTQFZH6k/+8Ib+htxqJXie8MoRdy/RGve54AC dejPziOACZy3mUdjUplHtTbE0aFni8qQyjB3FhMEfVIy2Z6EOq9g+MNUJNM7hBIRD4k/ p9I3NIp9PaLvTz8S9KAA+YP52KHaeTos/jh6KI727yp9YRIkayX3cd/+HA6XXOjo4v0K g0W8qe0UMGE1IMX2Fl7wVE/Uh3GorIEBjHdmIrhm50ZcwYVwdRxsOGAtHo+xZhrbW/Kr cenw== X-Gm-Message-State: ANoB5pmxNOeAV5li9BRGuwYYi2JxigbbiJKrGAfRcD/zt8Grzrx1iUFz 1lCIU6ziez1uXXvtSsBAAwCaLfgvO1YlKSWmo15Vag== X-Google-Smtp-Source: AA0mqf5smDZVlFEpWOKu4+udiDfWxW1h8EFoVsAXZwh6r6GbSyDB8g4qoAoPMnsIuJQRDjPaMVGsHKs00nB9WRyRNJE= X-Received: by 2002:a67:fbd6:0:b0:3ac:38c7:1bdd with SMTP id o22-20020a67fbd6000000b003ac38c71bddmr5400781vsr.9.1668808297740; Fri, 18 Nov 2022 13:51:37 -0800 (PST) MIME-Version: 1.0 References: <20221116013808.3995280-1-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Fri, 18 Nov 2022 14:51:01 -0700 Message-ID: Subject: Re: [PATCH 1/2] mm: multi-gen LRU: retry folios written back while isolated To: Minchan Kim Cc: Andrew Morton , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668808298; a=rsa-sha256; cv=none; b=IJedxvpzAQYeV1Dara/6B+sM4nkjs6ts1ETh57ZppzVBfjZSAVt3E6Nim0piG3jtcq/nJP beEbBmS5oVyELPpJtEsXaCiWU2B07ETaVCvSt0jaOjFrullWrMRt7ZKZHiuNN9dKG52nGq rhS+bkRUSrCSPIbIYNpeirQWQllX11o= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=fb0Z8rqR; spf=pass (imf22.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668808298; 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=08HxxgTebFcooUTsB+QKghjflmDNORIosXugPLRxd8E=; b=6LD5mrvWFDhM1mPcZ49Kzk12ql8TgGU7gXYtYq+xRpU4nxUM2e8AEaf3Y3zP7qC/aj5PZd uRMj+FqvcOHZCansMm1sJ0ojnjx2qFmTL1zAn65D2CZ6Nk+RHnqFGI8LbthLPFROA7h7sk y9YdK6Aq550FWL1Y/lhwDwkkkhyEYjo= X-Stat-Signature: cg9id3izhhew6e3891ncu7xbti6im6by X-Rspamd-Queue-Id: B6D61C000C X-Rspamd-Server: rspam01 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=fb0Z8rqR; spf=pass (imf22.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1668808298-831417 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000028, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Nov 18, 2022 at 2:25 PM Minchan Kim wrote: > > On Thu, Nov 17, 2022 at 06:40:05PM -0700, Yu Zhao wrote: > > On Thu, Nov 17, 2022 at 6:26 PM Minchan Kim wrote: > > > > > > On Thu, Nov 17, 2022 at 03:22:42PM -0700, Yu Zhao wrote: > > > > On Thu, Nov 17, 2022 at 12:47 AM Minchan Kim wrote: > > > > > > > > > > On Tue, Nov 15, 2022 at 06:38:07PM -0700, Yu Zhao wrote: > > > > > > The page reclaim isolates a batch of folios from the tail of one of > > > > > > the LRU lists and works on those folios one by one. For a suitable > > > > > > swap-backed folio, if the swap device is async, it queues that folio > > > > > > for writeback. After the page reclaim finishes an entire batch, it > > > > > > puts back the folios it queued for writeback to the head of the > > > > > > original LRU list. > > > > > > > > > > > > In the meantime, the page writeback flushes the queued folios also by > > > > > > batches. Its batching logic is independent from that of the page > > > > > > reclaim. For each of the folios it writes back, the page writeback > > > > > > calls folio_rotate_reclaimable() which tries to rotate a folio to the > > > > > > tail. > > > > > > > > > > > > folio_rotate_reclaimable() only works for a folio after the page > > > > > > reclaim has put it back. If an async swap device is fast enough, the > > > > > > page writeback can finish with that folio while the page reclaim is > > > > > > still working on the rest of the batch containing it. In this case, > > > > > > that folio will remain at the head and the page reclaim will not retry > > > > > > it before reaching there. > > > > > > > > > > > > This patch adds a retry to evict_folios(). After evict_folios() has > > > > > > finished an entire batch and before it puts back folios it cannot free > > > > > > immediately, it retries those that may have missed the rotation. > > > > > > > > > > Can we make something like this? > > > > > > > > This works for both the active/inactive LRU and MGLRU. > > > > > > I hope we fix both altogether. > > > > > > > > > > > But it's not my prefered way because of these two subtle differences: > > > > 1. Folios eligible for retry take an unnecessary round trip below -- > > > > they are first added to the LRU list and then removed from there for > > > > retry. For high speed swap devices, the LRU lock contention is already > > > > quite high (>10% in CPU profile under heavy memory pressure). So I'm > > > > hoping we can avoid this round trip. > > > > 2. The number of retries of a folio on folio_wb_list is unlimited, > > > > whereas this patch limits the retry to one. So in theory, we can spin > > > > on a bunch of folios that keep failing. > > > > > > > > The most ideal solution would be to have the one-off retry logic in > > > > shrink_folio_list(). But right now, that function is very cluttered. I > > > > plan to refactor it (low priority at the moment), and probably after > > > > that, we can add a generic retry for both the active/inactive LRU and > > > > MGLRU. I'll raise its priority if you strongly prefer this. Please > > > > feel free to let me know. > > > > > > Well, my preference for *ideal solution* is writeback completion drops > > > page immediately without LRU rotating. IIRC, concern was softirq latency > > > and locking relevant in the context at that time when I tried it. > > > > Are we good for now or are there other ideas we want to try while we are at it? > > > > good for now with what solution you are thinking? The retry logic you > suggested? I personally don't like the solution relies on the timing. > > If you are concerning about unnecessary round trip, it shouldn't > happen frequency since your assumption is swap device is so fast > so second loop would see their wb done? No, the round trip that hits the LRU lock in the process. For folios written and ready to be freed, they'll have to go from being isolated to the tail of LRU list and then to getting isolated again. This requires an extra hit on the LRU lock, which is highly contended for fast swap devices under heavy memory pressure. > Anyway, I am strongly push my preference. Feel free to go with way > you want if the solution can fix both LRU schemes. There is another concern I listed previously: > > > > 2. The number of retries of a folio on folio_wb_list is unlimited, > > > > whereas this patch limits the retry to one. So in theory, we can spin > > > > on a bunch of folios that keep failing. If this can happen, it'd be really hard to track it down. Any thoughts on this? I share your desire to fix both. But I don't think we can just dismiss the two points I listed above. They are reasonable, aren't they?