Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5501413pxb; Wed, 26 Jan 2022 13:32:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLtJoH2rdQHgKw5y+wcTpp5vNyRD+gfhocYjHMtsTNX253HpV8iwYKAccsOmSQvgNkMeh+ X-Received: by 2002:aa7:9682:: with SMTP id f2mr278647pfk.56.1643232744297; Wed, 26 Jan 2022 13:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643232744; cv=none; d=google.com; s=arc-20160816; b=WVN/9JjpcsFWw75p2nLRNKm4uyz7syFwuQdb/kGxz/ap0uQL3gbADyPXEU7tMzpg4G CwXA/3FKakqG9gI8p2fpbPzaeMSCCnH9zGM2vcKBQxBJgxSstPGpSxTXmLPZBD7OZ/rV XBmpyni+lDdBTh31MtvFGwgKwh8jyDH8fZNRr5A6OzNH9eQtKHteQm75fW3c5Nt74p6O 8oOYgp0K+yVy9ked9oVIm0T6xMzgPyWlcnYmG7+vINPFthWZVln2wyz+xgBc3qeCcxJJ NtYhjFYpZ1q6nYFnSK6KoIy8BrEhGRzUsvQ+1BdMh7syAJj/o809qFXWLtLqmONCcGr7 rbbQ== 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=LiOUw0BmLOCV5aXkbkiAQ3Ht3cRjDO/swK3bGS2AZxs=; b=i4iw580sy6fK0grCi6jpYyAW8xbb6cED9XN1zq+y+FJ5QXAtHeDY3P7ftBGNZxeJgO VaCO2gnJjXv9rXKPPQ5KgIsuam4ZScB2vN7MobNY2v25BsK3x0DRH8eHCn76bBaQGoKd y7PhOLMrmZgo6dP2MVgd3fwVWACRX508bcWczn8yQdjz3bXbw17I76IAUgYgQqvUKa9P LdNjm4fXYzS409Nab+b0zHwqyNloQIlGx+ge6knSHLKOjtOy+BHcZA+tKnvZ+enuUSIT L5cLvJSOtA8LsAC8CebR06aO0zSDkcqEZf3hpgc5T//g5w6dPK8WjXuckpyV20EdawK3 y48g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=oItQVVFf; 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 c18si313626plh.243.2022.01.26.13.32.12; Wed, 26 Jan 2022 13:32:24 -0800 (PST) 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=oItQVVFf; 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 S242101AbiAZOZe (ORCPT + 99 others); Wed, 26 Jan 2022 09:25:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235227AbiAZOZd (ORCPT ); Wed, 26 Jan 2022 09:25:33 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90BAEC06161C for ; Wed, 26 Jan 2022 06:25:32 -0800 (PST) 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=LiOUw0BmLOCV5aXkbkiAQ3Ht3cRjDO/swK3bGS2AZxs=; b=oItQVVFfHwr0aOvBCsF7zp4OOi RFvfZJkzhP/JdBpwYViRO401Z2hBTt55jxtY0F2cslTDw6q2mG0oyGyu7iOM1jx1/WEQ0Xgh7jdA4 rWMMGVggmGVjGDX9Aua0BQqGKZZnJlhHs+kmhvPXV98ap+1Rrmo3/5MwrSiJjsMDjx19u3l4RoKcn 2MRT+3t6Sp5FeFR6X+O4aPj9y0eekKjlz5KV9uauRg3/ubAMubGjDzEZzESs0oZUAg9zadZvAqhME FPh6YqRM3qqH6QFsA+Ebb8xNtA5oaRmpcOSELzy4WV7bX+BFwI3C9ULl58xtmhnk7EXPzBoTuRzeo aBgzAS0g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nCjEj-0047J8-Qd; Wed, 26 Jan 2022 14:25:25 +0000 Date: Wed, 26 Jan 2022 14:25:25 +0000 From: Matthew Wilcox To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Vlastimil Babka , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Liang Zhang , linux-mm@kvack.org, Nadav Amit Subject: Re: [PATCH RFC v2 1/9] mm: optimize do_wp_page() for exclusive pages in the swapcache Message-ID: References: <20220126095557.32392-1-david@redhat.com> <20220126095557.32392-2-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220126095557.32392-2-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 26, 2022 at 10:55:49AM +0100, David Hildenbrand wrote: > Liang Zhang reported [1] that the current COW logic in do_wp_page() is > sub-optimal when it comes to swap+read fault+write fault of anonymous > pages that have a single user, visible via a performance degradation in > the redis benchmark. Something similar was previously reported [2] by > Nadav with a simple reproducer. > > Let's optimize for pages that have been added to the swapcache but only > have an exclusive owner. Try removing the swapcache reference if there is > hope that we're the exclusive user. > > We will fail removing the swapcache reference in two scenarios: > (1) There are additional swap entries referencing the page: copying > instead of reusing is the right thing to do. > (2) The page is under writeback: theoretically we might be able to reuse > in some cases, however, we cannot remove the additional reference > and will have to copy. > > Further, we might have additional references from the LRU pagevecs, > which will force us to copy instead of being able to reuse. We'll try > handling such references for some scenarios next. Concurrent writeback > cannot be handled easily and we'll always have to copy. > > While at it, remove the superfluous page_mapcount() check: it's > implicitly covered by the page_count() for ordinary anon pages. > > [1] https://lkml.kernel.org/r/20220113140318.11117-1-zhangliang5@huawei.com > [2] https://lkml.kernel.org/r/0480D692-D9B2-429A-9A88-9BBA1331AC3A@gmail.com > > Reported-by: Liang Zhang > Reported-by: Nadav Amit > Signed-off-by: David Hildenbrand Reviewed-by: Matthew Wilcox (Oracle)