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 EB955C433FE for ; Fri, 18 Nov 2022 01:26:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 841518E0001; Thu, 17 Nov 2022 20:26:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F1C36B0075; Thu, 17 Nov 2022 20:26:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B90C8E0001; Thu, 17 Nov 2022 20:26:57 -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 5C1596B0073 for ; Thu, 17 Nov 2022 20:26:57 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1BB6C1C2F61 for ; Fri, 18 Nov 2022 01:26:57 +0000 (UTC) X-FDA: 80144824074.04.5EE88E1 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf18.hostedemail.com (Postfix) with ESMTP id C50A31C000B for ; Fri, 18 Nov 2022 01:26:56 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id k2-20020a17090a4c8200b002187cce2f92so1770702pjh.2 for ; Thu, 17 Nov 2022 17:26:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=sWhCEZH/tjkOkTYsWgYtjiCZGH0Det9xuS2Ssk2oLoQ=; b=Xn2+JcB905P7M/iMvWWk4OxHFxKiEPzShWHK/DuzJUIJU3lJy8sBYG5MbEognWugdi 1sCrrjrAPzgJfRn7xlcyhieNG7YxdM37LoRVFfbiuSIoEZew6cJS/UYfIJrfRApWntAI CtqPVsTTaKKeJH2X7gvw1d9YrCj138lGquR+z2Um/IfIhW0RNvjDDUbupz+1nDAgWQUW N7Z+VeSUZm+Uk8BcwKiQAeFC6W6u6KAeZ3EKT8FR6BZ2UTlf3ZZUDGXAn+JRCQkU/Nw5 T+tgtZqfciRLrySmT59qUOZcjK/5yHnya7ZRZUr3LkYFtkbSsJGL+LvMOVTaDc2XrW7y oP/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sWhCEZH/tjkOkTYsWgYtjiCZGH0Det9xuS2Ssk2oLoQ=; b=i+21D13qCaZrGBMJLJ/LXvRA7GknOWEUNR4JrxZN3vxX94fUqIQEl/mHQkZUZpWLr6 L2FihCz31Vfz/b1sToNbwmnmvSF+yZA+e+tdbCxKpWF6JQPUL7KHTRB0iR4ONgvreHXm lex/fIKcfrNUwO5DAOv8NcLxKk0VVhR64LB+Zbqx2ZHorRyibkqHOvZDB9ctGIXuXPFm ZWY+5vjT6gYrNyCcaBSVXUctF4zEuLPl8NU3i6tihgYaIxsRDAYK9fEBSD9U3SgrrA+9 hyNalEDpXnTmD+BXr+Mep53KOwho6y8D3VqZdVWS7IZNPAYDFsWzGZhF45z1/eBe24sC 9hkA== X-Gm-Message-State: ANoB5plnzT6KXwMGEtx+YqtzEuFpfa0sO10RwGwVL6NfThrspIRhSF9h vpHSrO4Od4x9XwJsEIK6FY32xDaU4OI= X-Google-Smtp-Source: AA0mqf5PjjDFtDdXBtHPS747o/oUDs4sZ7hG0CdXLEZqn7dM4IOHAGDfaZHFKw2vQM5rENbFFD0aGQ== X-Received: by 2002:a17:90b:1bc6:b0:218:4d16:cecf with SMTP id oa6-20020a17090b1bc600b002184d16cecfmr5308559pjb.96.1668734815680; Thu, 17 Nov 2022 17:26:55 -0800 (PST) Received: from google.com ([2620:15c:211:201:6bbc:b70a:8f80:710d]) by smtp.gmail.com with ESMTPSA id u15-20020a170902e5cf00b00185402cfedesm2053457plf.246.2022.11.17.17.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 17:26:55 -0800 (PST) Date: Thu, 17 Nov 2022 17:26:53 -0800 From: Minchan Kim To: Yu Zhao Cc: Andrew Morton , linux-mm@kvack.org Subject: Re: [PATCH 1/2] mm: multi-gen LRU: retry folios written back while isolated Message-ID: References: <20221116013808.3995280-1-yuzhao@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668734816; a=rsa-sha256; cv=none; b=mxnPb3lKgf2xka5J/Ye2CRE9YXEViI/nkEpDMCMhwsmTzWnOh9WmEMvw04Wu7Tl0j6wjn+ XIGvHWLA5LnPe0gpJKjRuhZ1bQH0rCmpc0ROg+TxuSDXluAaYjyrcAHyJiyn82yAqfXlws MjDQuMoYOHEI/d517g/y/UdIDZJIvuA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Xn2+JcB9; spf=pass (imf18.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668734816; h=from:from:sender: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=sWhCEZH/tjkOkTYsWgYtjiCZGH0Det9xuS2Ssk2oLoQ=; b=M8HUWF2cOLolhOVAsfXe8hs/XwmtqgvhB4LLw7cQUHb7pU1oSXWksVbytwiWNlib74dpZF ZWj7OS0mnYgDFiXToTPdOhyQWsiF9asi0BjIQ3lo9wLCXslX6ZSTvIdW2wEZa9TZd9kQky k23CMmRc/KIKxs5S/p2y/KZGZ4bZDbg= X-Stat-Signature: mhuxrzd87q4awxzsg55ucfuwbemdcoy6 X-Rspamd-Queue-Id: C50A31C000B Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Xn2+JcB9; spf=pass (imf18.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1668734816-64879 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.