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.6 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 5C5FDC4363D for ; Wed, 7 Oct 2020 22:09:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B930E2083B for ; Wed, 7 Oct 2020 22:09:23 +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="jEQFarLV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B930E2083B 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 F190F900002; Wed, 7 Oct 2020 18:09:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECAAF8E0001; Wed, 7 Oct 2020 18:09:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB8A0900002; Wed, 7 Oct 2020 18:09:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id ABA2A8E0001 for ; Wed, 7 Oct 2020 18:09:22 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3CFED181AE86B for ; Wed, 7 Oct 2020 22:09:22 +0000 (UTC) X-FDA: 77346521364.21.word36_410b725271d2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 20111180442C2 for ; Wed, 7 Oct 2020 22:09:22 +0000 (UTC) X-HE-Tag: word36_410b725271d2 X-Filterd-Recvd-Size: 4641 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 22:09:21 +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=FEyhRMHjvO7n4JR1kZOaUpAum7aLXI1/AmH/kM8Di7Q=; b=jEQFarLVGmJvJtUMk7xjGMLhHE ksIEFR5pAQc9z0QNSgqcXKyCc2ixuFlwwpafyim20TV/jPW8Rc8fYoMlVPDDzNmRe4+4Cq90ACmx4 hTm2i6ZKXEYViCRFk/1m1WZu6EyPWr27SMVKyRAQIoSfZQ5c8fy1/ZCActML71txswZbHwqsGxbog L6soLM5Tn5mDPs88ZZV3TXf+ybIUD4UVdD9ft7ABL4R1OTnBT4JyQFFj6Rmor3YdBRpmmGfgEOSrU 4mHu3/zP5mTEtQiPYTt4xHoUr6JheZYj1EhlTIj0ZD7OK8X0NWoN5lOUKxL/qGgXWRyEwWq3cKEsy BG1NyvrA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQHca-0008Qf-M0; Wed, 07 Oct 2020 22:09:16 +0000 Date: Wed, 7 Oct 2020 23:09:16 +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: <20201007220916.GX20115@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201007175419.GA3478056@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 Wed, Oct 07, 2020 at 01:54:19PM -0400, Jerome Glisse wrote: > > For other things (NUMA distribution), we can point to something which > > isn't a struct page and can be distiguished from a real struct page by a > > bit somewhere (I have ideas for at least three bits in struct page that > > could be used for this). Then use a pointer in that data structure to > > point to the real page. Or do NUMA distribution at the inode level. > > Have a way to get from (inode, node) to an address_space which contains > > just regular pages. > > How do you find all the copies ? KSM maintains a list for a reasons. > Same would be needed here because if you want to break the write prot > you need to find all the copy first. If you intend to walk page table > then how do you synchronize to avoid more copy to spawn while you > walk reverse mapping, we could lock the struct page i guess. Also how > do you walk device page table which are completely hidden from core mm. 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: +++ b/mm/filemap.c @@ -1622,6 +1622,9 @@ struct page *find_lock_entry(struct address_space *mapping , pgoff_t index) lock_page(page); /* Has the page been truncated? */ if (unlikely(page->mapping != mapping)) { + if (PageKsm(page)) { + ... + } unlock_page(page); put_page(page); goto repeat; @@ -1655,6 +1658,7 @@ struct page *find_lock_entry(struct address_space *mapping, pgoff_t index) * * %FGP_WRITE - The page will be written * * %FGP_NOFS - __GFP_FS will get cleared in gfp mask * * %FGP_NOWAIT - Don't get blocked by page lock + * * %FGP_KSM - Return KSM pages * * If %FGP_LOCK or %FGP_CREAT are specified then the function may sleep even * if the %GFP flags specified for %FGP_CREAT are atomic. @@ -1687,6 +1691,11 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, /* Has the page been truncated? */ if (unlikely(page->mapping != mapping)) { + if (PageKsm(page) { + if (fgp_flags & FGP_KSM) + return page; + ... + } unlock_page(page); put_page(page); goto repeat; I don't know what you want to do when you find a KSM page, so I just left an ellipsis.