Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1282329pxb; Fri, 21 Jan 2022 14:16:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqZinL/BEHPQewzZfcfPn/Cqc656QZICAxQZz8cve4OHWdArghsmH9WR9oLduqhMf6J5bZ X-Received: by 2002:a63:b20d:: with SMTP id x13mr4303058pge.310.1642803391114; Fri, 21 Jan 2022 14:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642803391; cv=none; d=google.com; s=arc-20160816; b=r4WBUwL4l7BMmMllJYp0aPbUQ6Jq4F4kwAJiBTiNkZqRYUnoRXhzo+ppxCTjASz1He NgbM3Wf+cFgSa7hYg87FFA/x+gT9EaQK3c6Jq87Yg8lFlvIeo7ugaTPjBLgp2TqgGia8 5E66z898QaXTcPa12mZXwOtTKJAk9o8PI3QP7cL3xot4OrFW0xa/HD5lP9EIj3YMkH1k p95VhMNgYYlDL35qeVcnITUXV6SsLbfSTRo7Hm+2V2Yw5i5pV5WnKEdVLJvThJSo2DgI h8k6pnYBH+8Uy5zno7hA6kmWJBtPTx1Z3CX+7rqsBUFlMunWkT+vxMS9AlFumEgcZnGW TCSw== 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=2LwJlstIvGsqeuZylXzQhNRQ08SoRUnluLli12GzN0Y=; b=YjekDy8fuEqvZoKGV6+M4bwbxmT+0jjr32dEIvbvANRpCkkjl9JtSGJ/q2UrvQ3GL0 RE7qxhiukwcpLfE8n1kJTM3EbmxUuDSKzoBKFDkToTnD8+OcA5MyppAYeVOP2dehgzPl 6OPozDBvZcAiF9g6JBkwl4QhioZMWNo5sMk8573TOADC8MNApEhYsU7HInoh7WM9d8vU zAY6SaaQMDVqeoGtcvUqb/3lhOGGnPn1f+DeEYawK56yTfu5SS9YrKLMX0E/9Jd+tCXj ybCIPUHvZLBL/oz54DDJA3uVXS6Dk9xGdAPLhqPFTQxmDnYF3KLDR+ylNt+f03kHVzi5 BGbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=MLOMkHVV; 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 y16si7135600pfl.75.2022.01.21.14.16.18; Fri, 21 Jan 2022 14:16:31 -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=MLOMkHVV; 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 S1353695AbiATOjd (ORCPT + 99 others); Thu, 20 Jan 2022 09:39:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242778AbiATOjO (ORCPT ); Thu, 20 Jan 2022 09:39:14 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A842C061746 for ; Thu, 20 Jan 2022 06:39:14 -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=2LwJlstIvGsqeuZylXzQhNRQ08SoRUnluLli12GzN0Y=; b=MLOMkHVV/aQF9+c0reWTugaM9U fqssnhX4hLmiOyyktv30+yx1DdcEpO8C56HNtNoAJkfzL7pedwkQvb6/YPZE0SHBFHKNJvKtcWxTs qLhm5NgGMg+GVT2CXPVNPdRfmIj+meXAlP8nMsOJvcEr9+xzFbGHAx9MqHsVnhvUsWRRswJk4ERvs tWWoPAGK11Mg5UfDAzezIGOoGg6pVTrruoNuK/6xFcD9lCTW4hvPRp4/IxKBqLg/ZG2ckpfBU0w3O RysaXNypn6JY3i4596syObCCuYBdQT2J/Dr9sycq7jv9EuQ9eRlVa1E2wPLaXfo7af8mEzp2/WpOQ brgwZ1Tg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAYab-00EKmj-9H; Thu, 20 Jan 2022 14:39:01 +0000 Date: Thu, 20 Jan 2022 14:39:01 +0000 From: Matthew Wilcox To: David Hildenbrand Cc: "zhangliang (AG)" , Andrew Morton , Linux-MM , Linux Kernel Mailing List , wangzhigang17@huawei.com, Linus Torvalds Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page Message-ID: References: <20220113140318.11117-1-zhangliang5@huawei.com> <172ccfbb-7e24-db21-7d84-8c8d8c3805fd@redhat.com> <9cd7eee2-91fd-ddb8-e47d-e8585e5baa05@redhat.com> <747ff31c-6c9e-df6c-f14d-c43aa1c77b4a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <747ff31c-6c9e-df6c-f14d-c43aa1c77b4a@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 20, 2022 at 03:15:37PM +0100, David Hildenbrand wrote: > On 17.01.22 14:31, zhangliang (AG) wrote: > > Sure, I will do that :) > > I'm polishing up / testing the patches and might send something out for discussion shortly. > Just a note that on my branch was a version with a wrong condition that should have been fixed now. > > I am still thinking about PTE mapped THP. For these, we'll always > have page_count() > 1, essentially corresponding to the number of still-mapped sub-pages. > > So if we end up with a R/O mapped part of a THP, we'll always have to COW and cannot reuse ever, > although it's really just a single process mapping the THP via PTEs. > > One approach would be to scan the currently locked page table for entries mapping > this same page. If page_count() corresponds to that value, we know that only we are > mapping the THP and there are no additional references. That would be a special case > if we find an anon THP in do_wp_page(). Hm. You're starting to optimise for some pretty weird cases at that point. Anon THP is always going to start out aligned (and can be moved by mremap()). Arguably it should be broken up if it's moved so it can be reformed into aligned THPs by khugepaged. This is completely different from file-backed THPs, where misalignment might be considered normal (if unfortunate).