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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 F3885C4363A for ; Thu, 8 Oct 2020 15:43:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 473E320739 for ; Thu, 8 Oct 2020 15:43:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IwmwO/rX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 473E320739 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B01376B005D; Thu, 8 Oct 2020 11:43:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB14D6B0062; Thu, 8 Oct 2020 11:43:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C6616B006C; Thu, 8 Oct 2020 11:43:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 73E836B005D for ; Thu, 8 Oct 2020 11:43:55 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0A4C8362A for ; Thu, 8 Oct 2020 15:43:55 +0000 (UTC) X-FDA: 77349178830.16.car19_1b020f0271d9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id C3A6310188AEB for ; Thu, 8 Oct 2020 15:43:54 +0000 (UTC) X-HE-Tag: car19_1b020f0271d9 X-Filterd-Recvd-Size: 4532 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 8 Oct 2020 15:43:52 +0000 (UTC) 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=FjknbtecctPRg6UGd8CgS2F3TAJYIRTYsOwlNQaT3TI=; b=IwmwO/rXmuZjUGrgUEhwRzEaQf NsCbD5Js7XLNi+EJgIYwF2AQEafsd+o8aNq+MPyDL4o516/9TCoiyiE+huoDPgaLqcjTEM2IYgGtw 7Pw6/5c3cxivhu8KBsC0WFaLd7DnlrBdk0Ida8e8KaaMRPX7wHkQ2SdhJmipqt6aZLNML7T6V1RIr TrwXTqWXkuA7p2A4gYfOcLagcgAhLdfPKAlTT7f7NT5AptrvUDV070qmzpX0ZOTYoKT0STh+JOMTL tfXIBvFcxWbVjpp4Pdv5Cm7HR3PCCLk0phC7L8mCoWWGauBULeS4pvpXtBqfariXUSQOvNFCiqFLl T/k3GD7g==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQY4z-0001CH-4a; Thu, 08 Oct 2020 15:43:41 +0000 Date: Thu, 8 Oct 2020 16:43:41 +0100 From: Matthew Wilcox To: Jerome Glisse Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Alexander Viro , Tejun Heo , Jan Kara , Josef Bacik Subject: Re: [PATCH 00/14] Small step toward KSM for file back page. Message-ID: <20201008154341.GJ20115@casper.infradead.org> References: <20201007010603.3452458-1-jglisse@redhat.com> <20201007032013.GS20115@casper.infradead.org> <20201007144835.GA3471400@redhat.com> <20201007170558.GU20115@casper.infradead.org> <20201007175419.GA3478056@redhat.com> <20201007220916.GX20115@casper.infradead.org> <20201008153028.GA3508856@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201008153028.GA3508856@redhat.com> 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, Oct 08, 2020 at 11:30:28AM -0400, Jerome Glisse wrote: > On Wed, Oct 07, 2020 at 11:09:16PM +0100, Matthew Wilcox wrote: > > So ... why don't you put a PageKsm page in the page cache? That way you > > can share code with the current KSM implementation. You'd need > > something like this: > > I do just that but there is no need to change anything in page cache. That's clearly untrue. If you just put a PageKsm page in the page cache today, here's what will happen on a truncate: void truncate_inode_pages_range(struct address_space *mapping, loff_t lstart, loff_t lend) { ... struct page *page = find_lock_page(mapping, start - 1); find_lock_page() does this: return pagecache_get_page(mapping, offset, FGP_LOCK, 0); pagecache_get_page(): repeat: page = find_get_entry(mapping, index); ... if (fgp_flags & FGP_LOCK) { ... if (unlikely(compound_head(page)->mapping != mapping)) { unlock_page(page); put_page(page); goto repeat; so it's just going to spin. There are plenty of other codepaths that would need to be checked. If you haven't found them, that shows you don't understand the problem deeply enough yet. I believe we should solve this problem, but I don't think you're going about it the right way. > So flow is: > > Same as before: > 1 - write fault (address, vma) > 2 - regular write fault handler -> find page in page cache > > New to common page fault code: > 3 - ksm check in write fault common code (same as ksm today > for anonymous page fault code path). > 4 - break ksm (address, vma) -> (file offset, mapping) > 4.a - use mapping and file offset to lookup the proper > fs specific information that were save when the > page was made ksm. > 4.b - allocate new page and initialize it with that > information (and page content), update page cache > and mappings ie all the pte who where pointing to > the ksm for that mapping at that offset to now use > the new page (like KSM for anonymous page today). But by putting that logic in the page fault path, you've missed the truncate path. And maybe other places. Putting the logic down in pagecache_get_page() means you _don't_ need to find all the places that call pagecache_get_page().