Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4470928rdh; Wed, 29 Nov 2023 02:22:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxoQrlXAl2tzNrW15V0UOQ8A5Sro64kNjXTSuxyGHT8g8txKwqdaWBY+lCPcQ3w7ml07ii X-Received: by 2002:a05:6a20:9384:b0:18b:94c5:24c2 with SMTP id x4-20020a056a20938400b0018b94c524c2mr17549602pzh.60.1701253369183; Wed, 29 Nov 2023 02:22:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701253369; cv=none; d=google.com; s=arc-20160816; b=Iio1OdKNje6phlKhZqIsSXu/sj6pNT+aVToB98X2nprUZW0piCqBwzqlv6+IvRPvS8 oaVCyfPVnZhyGBw2lRWrZ9LPYun35ai28YGUIWBqb6acR9C+wmllgYI9Ab1k5GGLTkqb 8Hp1pdnNXQUCngU3T+sFwJj0SI89lQ6WLaa2RMi/l9iM1yH0mVdJpbq3Qtw8A2L+QFa1 ifbSVHjvaQZZO1kNJ+bgzciUxYMksVexHygWoBdrPISMUVIMRPcHD7P5URE9yfMDc6on kykpWiBbwv2G6gQyhQN4jujiyVdOvRm/7w32YdtbjcP9ZQMPKzWY6I3Nh/ixsQblvMn4 EjUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=z08E1oEubgUv18/fMFXjEfb/IXlpOAqyFntT1non7IA=; fh=jQUiOy3a/k70k5jQ10/GvEyHYjSqhccU30lBoXIyL5k=; b=JNIGJq3JxGVal+5W5WjaPs1kWaxaBGS2lreDpYYRs6DwY26uMjVX8LGXrbWKCjLHJG Su5FfyTnj78926aq/cG9JlZDUOZHSVqptYbfHRS7ZAJZmfVSRgNndHzEe1ocMj3t5Clw zVK5vFVze4rHHAAWzanp06TH831ke7zP2nFvPSGrfc+3T7wwrkBmG1yfHN7vrs68xZG7 g1XkDdAiQkqc0xli2KWUQAWe9B5iAqUZTKYFJH30Cg+WYk/KzYVqa6ZkY0RNtVk4nAWa kyszJIPJjR7gg80rLYR32NXnti6IkjWN06Dp9lCC3trKYuQqGoKVdCCk1zE/RI87aWbF Y7cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fw7zhBX7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id pf11-20020a17090b1d8b00b00285a910661esi1073392pjb.10.2023.11.29.02.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 02:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fw7zhBX7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 810788049D37; Wed, 29 Nov 2023 02:22:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjK2KWX (ORCPT + 99 others); Wed, 29 Nov 2023 05:22:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbjK2KWW (ORCPT ); Wed, 29 Nov 2023 05:22:22 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2774CAF for ; Wed, 29 Nov 2023 02:22:28 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CB6A1219A5; Wed, 29 Nov 2023 10:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1701253344; h=from:from:reply-to: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; bh=z08E1oEubgUv18/fMFXjEfb/IXlpOAqyFntT1non7IA=; b=fw7zhBX7eOmcGkrdZ86sQUuiVE99SemfBFiF3BNh/pHjmN1El1YTV7KOpRVDZ/O6hGvy56 tWlVmQekrdcoCuX4E1Mjg81jXrLZRFNmREm+kG6PZf85QShj7lGahvImsyYp2ONYQ2s2EO AF95U0zEhedpTXObsPo2kFOey3TqbYs= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 947431388B; Wed, 29 Nov 2023 10:22:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8CgWIOAQZ2V+BwAAD6G6ig (envelope-from ); Wed, 29 Nov 2023 10:22:24 +0000 Date: Wed, 29 Nov 2023 11:22:23 +0100 From: Michal Hocko To: "Huang, Ying" Cc: Yosry Ahmed , Minchan Kim , Chris Li , Liu Shixin , Yu Zhao , Andrew Morton , Sachin Sant , Johannes Weiner , Kefeng Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10] mm: vmscan: try to reclaim swapcache pages if no swap space Message-ID: References: <87msv58068.fsf@yhuang6-desk2.ccr.corp.intel.com> <87h6l77wl5.fsf@yhuang6-desk2.ccr.corp.intel.com> <87bkbf7gz6.fsf@yhuang6-desk2.ccr.corp.intel.com> <87msuy5zuv.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87msuy5zuv.fsf@yhuang6-desk2.ccr.corp.intel.com> Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spamd-Result: default: False [-3.77 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.17)[-0.864]; RCPT_COUNT_TWELVE(0.00)[12]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -3.77 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 29 Nov 2023 02:22:46 -0800 (PST) On Tue 28-11-23 11:19:20, Huang, Ying wrote: > Yosry Ahmed writes: > > > On Mon, Nov 27, 2023 at 1:32 PM Minchan Kim wrote: > >> > >> On Mon, Nov 27, 2023 at 12:22:59AM -0800, Chris Li wrote: > >> > On Mon, Nov 27, 2023 at 12:14 AM Huang, Ying wrote: > >> > > > I agree with Ying that anonymous pages typically have different page > >> > > > access patterns than file pages, so we might want to treat them > >> > > > differently to reclaim them effectively. > >> > > > One random idea: > >> > > > How about we put the anonymous page in a swap cache in a different LRU > >> > > > than the rest of the anonymous pages. Then shrinking against those > >> > > > pages in the swap cache would be more effective.Instead of having > >> > > > [anon, file] LRU, now we have [anon not in swap cache, anon in swap > >> > > > cache, file] LRU > >> > > > >> > > I don't think that it is necessary. The patch is only for a special use > >> > > case. Where the swap device is used up while some pages are in swap > >> > > cache. The patch will kill performance, but it is used to avoid OOM > >> > > only, not to improve performance. Per my understanding, we will not use > >> > > up swap device space in most cases. This may be true for ZRAM, but will > >> > > we keep pages in swap cache for long when we use ZRAM? > >> > > >> > I ask the question regarding how many pages can be freed by this patch > >> > in this email thread as well, but haven't got the answer from the > >> > author yet. That is one important aspect to evaluate how valuable is > >> > that patch. > >> > >> Exactly. Since swap cache has different life time with page cache, they > >> would be usually dropped when pages are unmapped(unless they are shared > >> with others but anon is usually exclusive private) so I wonder how much > >> memory we can save. > > > > I think the point of this patch is not saving memory, but rather > > avoiding an OOM condition that will happen if we have no swap space > > left, but some pages left in the swap cache. Of course, the OOM > > avoidance will come at the cost of extra work in reclaim to swap those > > pages out. > > > > The only case where I think this might be harmful is if there's plenty > > of pages to reclaim on the file LRU, and instead we opt to chase down > > the few swap cache pages. So perhaps we can add a check to only set > > sc->swapcache_only if the number of pages in the swap cache is more > > than the number of pages on the file LRU or similar? Just make sure we > > don't chase the swapcache pages down if there's plenty to scan on the > > file LRU? > > The swap cache pages can be divided to 3 groups. > > - group 1: pages have been written out, at the tail of inactive LRU, but > not reclaimed yet. > > - group 2: pages have been written out, but were failed to be reclaimed > (e.g., were accessed before reclaiming) > > - group 3: pages have been swapped in, but were kept in swap cache. The > pages may be in active LRU. > > The main target of the original patch should be group 1. And the pages > may be cheaper to reclaim than file pages. Thanks this is really useful summary. And it begs question. How are we telling those different types from each other? vmstat counter is certainly not sufficient and that means we might be scanning a lot without actually making any progress. And doing that repeatedly. -- Michal Hocko SUSE Labs