Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3558266pxj; Tue, 1 Jun 2021 08:02:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiR6jzUlJLxXNs4OqblbPP2lUZWifThA0XSOctWk8cCD82yn7khWmLwLTOQC4C5JLsDclN X-Received: by 2002:a2e:b892:: with SMTP id r18mr20927274ljp.402.1622559751192; Tue, 01 Jun 2021 08:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622559751; cv=none; d=google.com; s=arc-20160816; b=npkvaF2ZMm9uXu3G53G3MCqZTB9HHRue+bTjBLvIPnw6XDBYzKzKBljekYmB6XVVpm SpB5c9JSTmJFtr0s64MkRu+rQVwYvF3msfmpHO8lj5BXeCvX1638MAE41JWTpg8ici28 lK8g/oeDjd8nIEmYmsfUmdnt0M3yK4hYVCGRaZktrPOmhC2ULa34BQBnEYWfj5QjdWqi eQ3BmPhuC0IjcEJi5xZGaZjf8V1qVqmFLnMAdKihsFy5whGCjivK2J2NrIG8txnBGZIa 9fwkQZFKnNdxxEPjOKOmfGXF0eQyvpWbSshAvzwle7c610pD1/CYF155eehBOFKxcYAD 6u3Q== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=glTCffzNZAga2gxixmoJ9kxSIEZt1XeVm/h8KhaD35s=; b=cOYcreOcRe9biUius0Z3USQn7iz6AQZRPh6v5UhaORh9DM2Sr+9mfv0ysCSNDNkcZJ xowVxSZb0iP8Ii7WJCFA8xIbsEcPUeQfl+8zDC4OY7elTCrGuEaRKTcHEg+WlHVRZRfx Hkwz2tkQWfOZCIUflRl5+ZPNsIsSfvpNwc3c8+AQUQ2QEAMOB9OoGZ0JHoUd+UT9Alme VwY9PCahb1dWLa0QcUPhEF0LvGcW8VGT+8DeHsVbTTWYUoF/AE7dAo48QUmaK/CsOgsC ITAUN2BzvXrd9XzPOC6bbykHu57RFy+/ZRZLPOkiQfZgL+sGTE3TLOIMeIW69uGg3xxZ 0Esw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=UYiCvDbH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc37si16405847ejc.354.2021.06.01.08.02.05; Tue, 01 Jun 2021 08:02:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=UYiCvDbH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234492AbhFAPCB (ORCPT + 99 others); Tue, 1 Jun 2021 11:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234495AbhFAPB7 (ORCPT ); Tue, 1 Jun 2021 11:01:59 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2445C061574 for ; Tue, 1 Jun 2021 08:00:17 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id d12so4725049qtq.4 for ; Tue, 01 Jun 2021 08:00:17 -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=glTCffzNZAga2gxixmoJ9kxSIEZt1XeVm/h8KhaD35s=; b=UYiCvDbHIuC2W4incbsaJsHUTvAD/ZmPNsxsEKzh29W4tQ1q0bN5L2fD1hY+iZTN9m 99iS85WHOaDHaJSJzfBIXR3GnsMbniJ9EuPrViJq3zF2Z63mhFeCBbHxayBh9E+x1CiH YNWt0U/PgEXyTyzU5ZOA1QeTSLROtng/AswQAbViuGUcoP8tV6bmIl1Q0Zu2Amj1vUSo 5uRJWA+lJlmRwZ5ZPJ9cFbBZxyGVmJM8ijZNSNvSfW4XBOa9n1puMbCwVxILwrG7MUUC ajw6J3n8RkT8UrQ0iVpWJiOA3+y8O23Ggg2kLnRqrPXgqjdJFlaEtlxsyC2QfpD3qceb AOMw== 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=glTCffzNZAga2gxixmoJ9kxSIEZt1XeVm/h8KhaD35s=; b=QyD6mMfHJSO9q9hcbvJtsuno4SpOeNPmQH/UfUgVK0IqMB7BTDmNPIspJPLn1cbIrA WwALPGzlDqXL24ECQVe1+E4dZTzLX9zoAx0kU1ipvOJDHz7PwQrfBoQ94094lmWBxQIu hJVujzpyDrDtOwSRtKvbq8FqHUJiDME9VnrnKtQXWI39hL8aR8yCMdOmXL9rncHW15Bj B9fTV1sbe/K5a61VbSaCRyckmN/il7ebHzQ0A3mFVn1lG4oAuNJUpjsrB2XRUE7aGk0C Afr9RrBXmNnLGeO7wqKxQZ0ZGZBbL2vaGppFO82vqSuKeGPpq3FDFWxaMcKM4E5HY51s LYCQ== X-Gm-Message-State: AOAM5338NFHkxk91XCm4ZPwjJvlbWm6Lc5cngd2sWZ+8TYKhjwVP75OW xb3w+Jn2ckRE+QEmOyTf1MEW/A== X-Received: by 2002:ac8:5392:: with SMTP id x18mr19923103qtp.381.1622559616950; Tue, 01 Jun 2021 08:00:16 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id d21sm2208111qke.29.2021.06.01.08.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 08:00:16 -0700 (PDT) Date: Tue, 1 Jun 2021 11:00:15 -0400 From: Johannes Weiner To: Matthew Wilcox Cc: Huang Ying , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Linus Torvalds , Peter Xu , Hugh Dickins , Mel Gorman , Rik van Riel , Andrea Arcangeli , Michal Hocko , Dave Hansen , Tim Chen Subject: Re: [PATCH] mm: free idle swap cache page after COW Message-ID: References: <20210601053143.1380078-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 01, 2021 at 12:48:15PM +0100, Matthew Wilcox wrote: > On Tue, Jun 01, 2021 at 01:31:43PM +0800, Huang Ying wrote: > > With commit 09854ba94c6a ("mm: do_wp_page() simplification"), after > > COW, the idle swap cache page (neither the page nor the corresponding > > swap entry is mapped by any process) will be left in the LRU list, > > even if it's in the active list or the head of the inactive list. So, > > the page reclaimer may take quite some overhead to reclaim these > > actually unused pages. > > > > To help the page reclaiming, in this patch, after COW, the idle swap > > cache page will be tried to be freed. To avoid to introduce much > > overhead to the hot COW code path, > > > > a) there's almost zero overhead for non-swap case via checking > > PageSwapCache() firstly. > > > > b) the page lock is acquired via trylock only. > > > > 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 23.8% with the decreased size of swap cache and > > swapin throughput. > > So 2 percentage points better than my original idea? Sweet. > > > diff --git a/mm/memory.c b/mm/memory.c > > index 2b7ffcbca175..d44425820240 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -3104,6 +3104,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) > > munlock_vma_page(old_page); > > unlock_page(old_page); > > } > > + if (page_copied) > > + free_swap_cache(old_page); > > put_page(old_page); > > } > > return page_copied ? VM_FAULT_WRITE : 0; > > Why not ... > > if (page_copied) > free_page_and_swap_cache(old_page); > else > put_page(old_page); > > then you don't need to expose free_swap_cache(). Or does the test for > huge_zero_page mess this up? It's free_page[s]_and_swap_cache() we should reconsider, IMO. free_swap_cache() makes for a clean API function that does one thing, and does it right. free_page_and_swap_cache() combines two independent operations, which has the habit of accumulating special case-handling for some callers that is unncessary overhead for others (Abstraction Inversion anti-pattern). For example, free_page_and_swap_cache() adds an is_huge_zero_page() check around the put_page() for the tlb batching code. This isn't needed here. AFAICS it is also unnecessary for the other callsite, __collapse_huge_page_copy(), where context rules out zero pages. The common put_page() in Huang's version also makes it slighly easier to follow the lifetime of old_page. So I'd say exposing free_swap_cache() is a good move, for this patch and in general.