Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4189232rdh; Tue, 28 Nov 2023 14:38:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXcODnUOwKbBq3AYWEecT7GBoFLHG9J9pyj5dbVVPJg/5DK/wsBS4m4dstwRHTC69ZMxqS X-Received: by 2002:a17:902:a3c3:b0:1cc:29ef:df81 with SMTP id q3-20020a170902a3c300b001cc29efdf81mr14495902plb.41.1701211094565; Tue, 28 Nov 2023 14:38:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701211094; cv=none; d=google.com; s=arc-20160816; b=IaRVo+6NgVZM95kCQzpDtkhDo5H3kDJ6Rbhumtx+qWI9guWtxpYuPBHMfl1WQKJ440 iVbJ5g7m9TDPzDjWsOjvrsKjhl1FYEpHBaEfD9FJEdkUBo0JZqRRtjSYPk3vutNV4Kst tZJlYZlJscT94Y0HHxlHQSHcvWIQ+1nAY8b0Q/nu1See37P5VZFxdkJ436C9Yvi9V7O4 FuGOVIgOjO44Hum9KBsPGiIS5kIV1YHznXkAHt+PAOtINGWZXxYHKhWjfymPC8MGoj7b ko0jyP2M2koJqYsEUys2V3t5lnS8aH4Cat8cDVOeL7n50JrGnBOnglNyUnx87HbqCFo/ bOng== 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:sender:dkim-signature; bh=A2AafIo5QVv/abJyPMu6Yqz0MbRVWfdchikKuUJez54=; fh=Suz1cw/4xmIovzEzRvWt5OGbI4WolrONb62fY8Gq1pI=; b=pnJs6+nyNFNmB/WKr7uFDBDT6KffNqd6sg33KSOC5KD98G/kr29oi63FlM2BwRGeYR gHbtvyxYROl4CI5a4nx9fbdNgEMBWNguphQtMQoLUtgrwmnLsx1izCmxr1ncJGRrGj5A u+sr3sp5J/IPhuHrZIOuFAQqu/pwZuduMbDXmW5ApuGK1rcFYlAEGa2k0QBZO/5s+Gp6 VSxm2jnsVNjXIolqOqwwxBKO0hToBiT8JWT9s+KUwhOKCy8ObHM0aMgN+AJL/lt2x6A1 i9S4DQoB6rGBydxW5czixAiXDHDIxNCLqfK4zF8QbTfCJ12mGbMhlFKktHI2ewpuVX4r vZZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RP3zeivu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o4-20020a170902d4c400b001cfee3a03b8si3224044plg.472.2023.11.28.14.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 14:38:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RP3zeivu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 908DD807A58D; Tue, 28 Nov 2023 14:37:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346690AbjK1Wh3 (ORCPT + 99 others); Tue, 28 Nov 2023 17:37:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344653AbjK1Wh2 (ORCPT ); Tue, 28 Nov 2023 17:37:28 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 925B91998 for ; Tue, 28 Nov 2023 14:37:33 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6c398717726so5138842b3a.2 for ; Tue, 28 Nov 2023 14:37:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701211053; x=1701815853; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :from:to:cc:subject:date:message-id:reply-to; bh=A2AafIo5QVv/abJyPMu6Yqz0MbRVWfdchikKuUJez54=; b=RP3zeivu/gmiDVIvkcCDfyAJNHmYr/+5LYfLHUSPk5NHvtkxJpGZ9tC8zFGZdV50nP zD14LYVW2jd8iqEgHhsUDQ7hFDFZ29OzZl5bB4Plw4Ou9fUUi2Coskpsla7PYCahV6SM R2Fl9aTsM28psnNjPsjDGzVDnyApOzzyi2H55ch+U0YoUKLffwcOpOzrXyGAmrEqNNmb hoNXpbs+tuytg7L5AdcDbKnfs10aBILqaUU6mW564TObQfXhuGWwfF/fx43g6Isimcd8 v0iKATzLzuZ+Ly//rJSDaH3JEVWPd2snhy5DYPK48N86BHWgSVYOCAP6agtcCQqi9sNe mG1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701211053; x=1701815853; h=in-reply-to:content-transfer-encoding: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=A2AafIo5QVv/abJyPMu6Yqz0MbRVWfdchikKuUJez54=; b=ezSeaFy/BqdIYT6hayPn1ciIDLHUFynkRONqXUaz5qooqnt2XjbfJ4cBLwiaYzXQMu 3+E8Wtd9kI8zFyW49L436sgJdUlLCoiWfeK6MRws49gRAGYPNeHeffteDtGGHE72yz5p yPbFSn4A+1GFN4s1eRDfDIFM9GYz+GvbBew6uSgSO+yDe+7wkO81s08Qrnmlmx1QsLLM yrkKUnXvkndS77e2sjJvYtfVhpewa7M7UgAGdU/6VGqfz+cRQzO6+IDBgynsc/BPhPrH qquuac08M9Xx6Wc7gzSG8EaTY6Qdlkn2NGbvNGjCNvJWF13BHRleKACEUR88wDuPBFGG xKdw== X-Gm-Message-State: AOJu0YzoTBrRHzL/AbhivGoMjcqSQpndFa9ciMgNhdpp+7sPeWQdHtCJ EHeLqRkXG4A7S/v4dgOT1kI= X-Received: by 2002:a05:6a00:3989:b0:6c3:1b90:8552 with SMTP id fi9-20020a056a00398900b006c31b908552mr17819915pfb.17.1701211052890; Tue, 28 Nov 2023 14:37:32 -0800 (PST) Received: from google.com ([2620:0:1000:8411:8fd0:78d2:c604:3ac8]) by smtp.gmail.com with ESMTPSA id t20-20020aa79394000000b006cdc6b9f0ecsm263540pfe.81.2023.11.28.14.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 14:37:31 -0800 (PST) Sender: Minchan Kim Date: Tue, 28 Nov 2023 14:37:28 -0800 From: Minchan Kim To: "Huang, Ying" Cc: Yosry Ahmed , Chris Li , Michal Hocko , 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> X-Spam-Status: No, score=0.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, FSL_HELO_FAKE,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 28 Nov 2023 14:37:47 -0800 (PST) On Tue, Nov 28, 2023 at 11:19:20AM +0800, 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. Yeah, that's common for asynchronous swap devices and that's popular. Then, How about freeing those memory as soon as the writeback is done instead of keep adding more tricks to solve the issue? https://lkml.kernel.org/linux-mm/1368411048-3753-1-git-send-email-minchan@kernel.org/ I remember it's under softIRQ context so there were some issues to change locking rules for memcg and swap. And there was some concern to increase softirq latency due to page freeing but both were not the main obstacle to be fixed. > > Group 2 are hard to be reclaimed if swap_count() isn't 0. "were accessed before reclaiming" would be rare. > > Group 3 should be reclaimed in theory, but the overhead may be high. > And we may need to reclaim the swap entries instead of pages if the pages > are hot. But we can start to reclaim the swap entries before the swap > space is run out. I thought the swap-in path will reclaim the swap slots once it detects swapspace wasn't enough(e.g., vm_swap_full or mem_cgroup_swap-full)? > > So, if we can count group 1, we may use that as indicator to scan anon > pages. And we may add code to reclaim group 3 earlier.