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=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 74675C433E2 for ; Wed, 9 Sep 2020 14:50:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E59D220768 for ; Wed, 9 Sep 2020 14:50:42 +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="pzVsW3zM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E59D220768 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 83B7E8E0001; Wed, 9 Sep 2020 10:50:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C5066B0088; Wed, 9 Sep 2020 10:50:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B3FF8E0001; Wed, 9 Sep 2020 10:50:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id 51C196B0087 for ; Wed, 9 Sep 2020 10:50:42 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1A86F181AC9CC for ; Wed, 9 Sep 2020 14:50:42 +0000 (UTC) X-FDA: 77243809524.15.salt39_3f062e2270de Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id D8A101814B0C7 for ; Wed, 9 Sep 2020 14:50:41 +0000 (UTC) X-HE-Tag: salt39_3f062e2270de X-Filterd-Recvd-Size: 4658 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 9 Sep 2020 14:50:39 +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=HErYX8jkf8BZ1UwZV6j/iEpNV4Lr17baRQUw1yLMG14=; b=pzVsW3zM1I3WsCGykQHAkhuysd 8ZFcuiR5PJaID8J7IZVMxCwZunGIGKshP0cQ8vl6EYu5RXMKfufyQWPwLOuyqs00UKDKexRS80sOm fhhzraoe7OKvexP/1QDPvRnkh5fG7po+nbWJpJAztTm3nVwbDJCKuPYu8H2b/8kMvzDSnJijxlKys 995KhNy9o48uLx/qn/j80Ir4DRy1g4ePMGBAlWR3hhJd177UUDaDTVQE7MA6Hky55Ha3pMOlgrAPS 3lKMH43xpJQ/Z1jgWYLVX+b9UUhuACWDIo+heXWkBSscD4tvejjyVbo+7hlPp0f+Ps7xvSqSmEnyS G1Zxi8LQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kG1Qh-0007OK-9t; Wed, 09 Sep 2020 14:50:35 +0000 Date: Wed, 9 Sep 2020 15:50:35 +0100 From: Matthew Wilcox To: "Kirill A. Shutemov" Cc: linux-mm@kvack.org, Andrew Morton , Huang Ying Subject: Re: [PATCH 02/11] mm/memory: Remove page fault assumption of compound page size Message-ID: <20200909145035.GH6583@casper.infradead.org> References: <20200908195539.25896-1-willy@infradead.org> <20200908195539.25896-3-willy@infradead.org> <20200909142904.acca6gthbffk3jwq@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200909142904.acca6gthbffk3jwq@box> X-Rspamd-Queue-Id: D8A101814B0C7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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, Sep 09, 2020 at 05:29:04PM +0300, Kirill A. Shutemov wrote: > On Tue, Sep 08, 2020 at 08:55:29PM +0100, Matthew Wilcox (Oracle) wrote: > > A compound page in the page cache will not necessarily be of PMD size, > > so check explicitly. > > > > Signed-off-by: Matthew Wilcox (Oracle) > > --- > > mm/memory.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 602f4283122f..4b35b4e71e64 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -3562,13 +3562,14 @@ static vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) > > unsigned long haddr = vmf->address & HPAGE_PMD_MASK; > > pmd_t entry; > > int i; > > - vm_fault_t ret; > > + vm_fault_t ret = VM_FAULT_FALLBACK; > > > > if (!transhuge_vma_suitable(vma, haddr)) > > - return VM_FAULT_FALLBACK; > > + return ret; > > > > - ret = VM_FAULT_FALLBACK; > > page = compound_head(page); > > + if (page_order(page) != HPAGE_PMD_ORDER) > > + return ret; > > Maybe also VM_BUG_ON_PAGE(page_order(page) > HPAGE_PMD_ORDER, page)? > Just in case. In the patch where I actually start creating THPs, I limit the order to HPAGE_PMD_ORDER, so we're not going to see this today. At some point in the future, I can imagine that we allow THPs larger than PMD size, and what we'd want alloc_set_pte() to look like is: if (pud_none(*vmf->pud) && PageTransCompound(page)) { ret = do_set_pud(vmf, page); if (ret != VM_FAULT_FALLBACK) return ret; } if (pmd_none(*vmf->pmd) && PageTransCompound(page)) { ret = do_set_pmd(vmf, page); if (ret != VM_FAULT_FALLBACK) return ret; } Once we're in that situation, in do_set_pmd(), we'd want to figure out which sub-page of the >PMD-sized page to insert. But I don't want to write code for that now. So, what's the right approach if somebody does call alloc_set_pte() with a >PMD sized page? It's not exported, so the only two ways to get it called with a >PMD sized page is to (1) persuade filemap_map_pages() to call it, which means putting it in the page cache or (2) return it from vm_ops->fault. If someone actually does that (an interesting device driver, perhaps), I don't think hitting it with a BUG is the right response. I think it should actually be to map the right PMD-sized chunk of the page, but we don't even do that today -- we map the first PMD-sized chunk of the page. With this patch, we'll simply map the appropriate PAGE_SIZE chunk at the requested address. So this would be a bugfix for such a demented driver. At some point, it'd be nice to handle this with a PMD, but I don't want to write that code without a test-case. We could probably simulate it with the page cache THP code and be super-aggressive about creating order-10 pages ... but this is feeling more and more out of scope for this patch set, which today hit 99 patches.