Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3410090pxj; Tue, 1 Jun 2021 04:50:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzDcUFafiwX2bf+I/WJg1IIPR90vjEKN2I2WQfylYHL+mcQ+0yqdNhsH25T73bsdF0YBrJ X-Received: by 2002:aa7:c41a:: with SMTP id j26mr11765778edq.133.1622548210110; Tue, 01 Jun 2021 04:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622548210; cv=none; d=google.com; s=arc-20160816; b=EtEjGi5i/hCyXBaNn/Ztf8pmoER33QSAKAV8t8prkOadwO7nykjrRYkckjP1fiQ4tE f5C1LUQEox6P6n3Nakg5g3Rk4FYcXuM4EjdYmBlcEi17WsyBLgOkIejOV1pFnLP9SUCu jtyg5KSRXdvKstBG8qgti+Bd7MOjSqeYvqmVR+naPgEnz6Uq9sPQLOY/pE0+jNpjPskx sPniKVDX8CtiUYuaqxOb8J8jWnDyFsY9W5aE9h6wuKMy1i0mN5/opHHC/XC+7+tjnyCg Kbcszo2og3uIodowedGxfTk6oi10Zc0BfP0yQks9yKs7yAq82K5WKpr26miOZ1cMvRxB vP5Q== 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=FG8QsXBT9RwonVdLjIFuZXWFVzP4Jy7oyS+/HVeFnwk=; b=HNNm1WU1ZthxtRlmiO7tXsOfH+t5DH59yTL/ne6xcM7jiRh9TnMb2CATRJomciLp0a 9VmlMO3z+bqDcmPD6j9R7hMZJI3LlfXw2+bZaTcpPB49az3BINaHIYYMVGgku4GPVwqd sgHN7l9L+zgmUIfzoMmDxTLCYE7eaCucsZCkUEmNSEg6Qp7K5TNqIgL0Pk9ZfEedm23a eeaK5Vx/95o8DbKJ9gZYGlpPoHkHBR17rpAMYbIxbgZTM4FuDvnNipQdSgSpocy5IGIJ 1jyla1XPzek/H/uYCYXwQybABco7WB5hkaFPSrSs+0LfFx5mKGave9eXZr9omKqH2hOa lHLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=U8zo4BcN; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si17290697ejp.321.2021.06.01.04.49.46; Tue, 01 Jun 2021 04:50:10 -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=@infradead.org header.s=casper.20170209 header.b=U8zo4BcN; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbhFALu3 (ORCPT + 99 others); Tue, 1 Jun 2021 07:50:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbhFALu2 (ORCPT ); Tue, 1 Jun 2021 07:50:28 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88781C061574 for ; Tue, 1 Jun 2021 04:48:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FG8QsXBT9RwonVdLjIFuZXWFVzP4Jy7oyS+/HVeFnwk=; b=U8zo4BcNXFspX345/GEHZU/xcq O1pN3s1GYhzCNlGlH7kB+2/c/YQys3SXLbhl7xrZBY8y5cPTpOKbfdARhdOxdQn8nWMpWNSlc5k8y yq9rl3VuvQdiI9nyJMMyx/pMovjihUJRfTvRRVQc3hYjUn/BucuiqrAh7WDsj5rryy8ayhNrr2wIg XtD2nv5CI/bzn0BLPc8lVsY91HXtWuFCeq0c74iFJeYL+Ezf55KnazeRgoXLmRzKxG07bNeL+nYJa x4D27m85R0mEJ4PbSyn+7gtBDG7DeWVtHrNQ5Il4BlE/hcREg0yn25CgnMgp9escsGZ4tvt30m+2A XPFZI+1w==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lo2sZ-009zEi-JF; Tue, 01 Jun 2021 11:48:19 +0000 Date: Tue, 1 Jun 2021 12:48:15 +0100 From: Matthew Wilcox To: Huang Ying Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , 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: <20210601053143.1380078-1-ying.huang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?