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 X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3066AC47089 for ; Thu, 27 May 2021 16:53:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9A3A8613B6 for ; Thu, 27 May 2021 16:53:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A3A8613B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E24FD6B006C; Thu, 27 May 2021 12:53:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFA6D6B006E; Thu, 27 May 2021 12:53:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC3008D0001; Thu, 27 May 2021 12:53:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 9877B6B006C for ; Thu, 27 May 2021 12:53:00 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2CC36B9E9 for ; Thu, 27 May 2021 16:53:00 +0000 (UTC) X-FDA: 78187605720.07.48462E7 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 58F02200099D for ; Thu, 27 May 2021 16:52:49 +0000 (UTC) Received: by mail-qt1-f176.google.com with SMTP id i12so685594qtr.7 for ; Thu, 27 May 2021 09:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tW8aVIUgOS3ZLnQ4gtbVHOeCP2dupOYTeHOn+YcgsqU=; b=ATsfEW9uBHQ1lJfvp9JfTAX8Fs6pyiQCOirMRd1RT15806+L0T4hKneKMlxa9ExuSB l1Z7q+E6zWEGQ3IK3zAV9uEoaMc/Sr3ANqW84lDzLrtxP6hmY2rFVTIUItqj+Ah/GISX YeRJ1HUfUyJ4lpZfQfZPNYrhsWYZROkB8WnYI9lXSub50fLe8PzZY/UelFDQ+hHPoXIz hl90Iw/BeMXTozJa+06tDNgwMCR7l0l68WqhBCW1wgao1YvD3g1WY0vnwBAYYIoBjvcc MtScb0fdbPD3rDHLOZylaniwQKmtvQpMrbfdaCwohAs2F5gEgu6oF8clsNYJC1sFjOs6 YC8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tW8aVIUgOS3ZLnQ4gtbVHOeCP2dupOYTeHOn+YcgsqU=; b=gLMjnLPa5fqmtCzC2QUzkbPD8Llz1d3W0S+x2u2EpHjzX//FwCmcmt4zOUL7nbg2x4 o0yH+0S3EobFu2hcwObZy2bhjcdRVdxZ6aeql5MGSpwQIIu9b+WfV+z4197y/OBxFMYq b5ZALJ0NjaE6jDVXWclg2Cm5mc+DPKMHoIC7HQqWmd1od+f0lD61Ubm/yyVMfIuxgQ2A gKQwvEmSsfBixK6Und3/Nq9BDIO2abvus6CPlqZyHNlLKEjftywYcd+ZSz7qAsHCMLPs yz7VG7F527PD8hg/7hc/KGGVUOijtW3r7djZOa2rhoQwjIFxOF95iD7XDE7My7JN97yv +XRw== X-Gm-Message-State: AOAM5310iVYk68Jopb2STbdVeIZNcYz+n4IIufeKYDVxv0Op25zG1DAU x/Y/vciaGElQzgv+Wizk061PyQ== X-Google-Smtp-Source: ABdhPJznhir0qZTsiDkeQ5vEx1jVCVaUERWECV17Sem7uftFd4thCN6fIn+s/lZK2hc6bTlqlhi2qg== X-Received: by 2002:ac8:5751:: with SMTP id 17mr3970984qtx.389.1622134378469; Thu, 27 May 2021 09:52:58 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:a6a3]) by smtp.gmail.com with ESMTPSA id h8sm1639554qtp.46.2021.05.27.09.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 09:52:57 -0700 (PDT) Date: Thu, 27 May 2021 12:52:56 -0400 From: Johannes Weiner To: Huang Ying Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox , Linus Torvalds , Peter Xu , Hugh Dickins , Mel Gorman , Rik van Riel , Andrea Arcangeli , Michal Hocko , Dave Hansen , Tim Chen Subject: Re: [PATCH -V2] mm: move idle swap cache pages to the tail of LRU after COW Message-ID: References: <20210527084953.573788-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210527084953.573788-1-ying.huang@intel.com> Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=ATsfEW9u; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf11.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.176 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 58F02200099D X-Stat-Signature: 6y8u6u8cexjkacn6a3mesq4bmk491jsw X-HE-Tag: 1622134369-891785 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: On Thu, May 27, 2021 at 04:49:53PM +0800, Huang Ying wrote: > With commit 09854ba94c6a ("mm: do_wp_page() simplification"), after > COW, the idle swap cache (neither the page nor the corresponding swap > entry is mapped by any process) will be left at the original position > in the LRU list. While it may be in the active list or the head of > the inactive list, so that vmscan may take more overhead or time to > reclaim these actually unused pages. > > To help the page reclaiming, in this patch, after COW, the idle swap > cache will be tried to be moved to the tail of the inactive LRU list. > To avoid to introduce much overhead to the hot COW code path, all > locks are acquired with try locking. > > To test the patch, we used pmbench memory accessing benchmark with > working-set larger than available memory on a 2-socket Intel server > with a NVMe SSD as swap device. Test results shows that the pmbench > score increases up to 21.8% with the decreased size of swap cache and > swapin throughput. > > Signed-off-by: "Huang, Ying" > Suggested-by: Matthew Wilcox > Cc: Linus Torvalds > Cc: Peter Xu > Cc: Hugh Dickins > Cc: Johannes Weiner > Cc: Mel Gorman > Cc: Rik van Riel > Cc: Andrea Arcangeli > Cc: Michal Hocko > Cc: Dave Hansen > Cc: Tim Chen > > V2: > > - Move trylock_page() to try_to_free_idle_swapcache() per Rik and > Linus' comments. > - Fix PageLRU() checking. > - Fix THP processing. > - Rename the function. > --- > include/linux/memcontrol.h | 10 ++++++++++ > include/linux/swap.h | 3 +++ > mm/memcontrol.c | 12 ++++++++++++ > mm/memory.c | 2 ++ > mm/swapfile.c | 39 ++++++++++++++++++++++++++++++++++++++ > 5 files changed, 66 insertions(+) Sorry the discussion fizzled out on the last patch. Let me try to recap this series: on your first submission you directly freed the old page if we copied. Linus was worried about overhead in the COW path that wouldn't pay off in a real workload. Before getting numbers, it was then suggested to move the pages to the tail of the LRU and leaving them to reclaim - which was also met with skepticism. V2 presented the LRU moving version with pmbench numbers that indeed show it pays off. However, much simpler direct freeing produces even better numbers in the same benchmark. We don't have numbers showing if the LRU shuffling would significantly fare better in other workloads. Purely looking at the code: whether we defer or free, we need to lock the page, take the LRU spinlock for this page, and touch the LRU linkage. If we free, we add the swapcache deletion and the page allocator, but it's most likely the percpu-cached fastpath. If we defer, reclaim needs to re-establish information about the page that we already had in the COW context, do another LRU operation, do the swapcache deletion and go through the allocator, but on cold caches. Personally, I'm a bit skeptical the extra code complexity and reclaim overhead in paging workloads will definitely pay off in intermittently paging loads (non-paging wouldn't have swap pages). As far as code goes, the point of 09854ba94c6a (+17, -42) was simplification, and this adds more lines back in another place. In particular it adds another lifetime variant to swap pages which are already somewhat unwieldy. OTOH, freeing is a two-liner reusing the swap unmap code: if (page_copied) free_swap_cache(old_page); Linus, what do you think?