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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 994C4C54FB9 for ; Thu, 16 Nov 2023 14:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345322AbjKPOwD (ORCPT ); Thu, 16 Nov 2023 09:52:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjKPOwB (ORCPT ); Thu, 16 Nov 2023 09:52:01 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D1B130 for ; Thu, 16 Nov 2023 06:51:57 -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=2ojEoDQsJbTKNbq6oPAMc3aknQ7lB4yrHDrRikIo44Y=; b=hfk9fkdc9vO0S2gBsS4PhgF/Hv xo9giUPkBJqOVc9jqbjGwEyrOzKkCmfF6hujr3hTvHFKID6f3Fq503I6juI4QqENzgjAqWGFqSsqQ q4dQSYdXySSSMpRl06w5hMDO5ZUkwD5xI7VVmtyI1iaowUFygHTOFLgNHO9yDAVPMGXeCvu9Gao8n AnFHee7FVHpCS1Vh0ANhbbsv/Xnl5+SFsBHIPSCWTyz9B10vBKv268A5/zbvNpO6p12eKsGmY9kLl WljHM9JeeL6Catj3T5Sj38GRo2nAdgOgE/5wi0tECtxXIpU+2ds9zj32B2EjBGFny5oh7RqJ4jmBP 56LNyPVQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1r3dii-003azA-ES; Thu, 16 Nov 2023 14:51:52 +0000 Date: Thu, 16 Nov 2023 14:51:52 +0000 From: Matthew Wilcox To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mike Kravetz , "Kirill A . Shutemov" , Lorenzo Stoakes , Axel Rasmussen , John Hubbard , Mike Rapoport , Hugh Dickins , David Hildenbrand , Andrea Arcangeli , Rik van Riel , James Houghton , Yang Shi , Jason Gunthorpe , Vlastimil Babka , Andrew Morton Subject: Re: [PATCH RFC 07/12] mm/gup: Refactor record_subpages() to find 1st small page Message-ID: References: <20231116012908.392077-1-peterx@redhat.com> <20231116012908.392077-8-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231116012908.392077-8-peterx@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 15, 2023 at 08:29:03PM -0500, Peter Xu wrote: > All the fast-gup functions take a tail page to operate, always need to do > page mask calculations before feeding that into record_subpages(). > > Merge that logic into record_subpages(), so that we always take a head > page, and leave the rest calculation to record_subpages(). This is a bit fragile. You're assuming that pmd_page() always returns a head page, and that's only true today because I looked at the work required vs the reward and decided to cap the large folio size at PMD size. If we allowed 2*PMD_SIZE (eg 4MB on x86), pmd_page() would not return a head page. There is a small amount of demand for > PMD size large folio support, so I suspect we will want to do this eventually. I'm not particularly trying to do these conversions, but it would be good to not add more assumptions that pmd_page() returns a head page. > +static int record_subpages(struct page *head, unsigned long sz, > + unsigned long addr, unsigned long end, > + struct page **pages) > @@ -2870,8 +2873,8 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr, > pages, nr); > } > > - page = nth_page(pmd_page(orig), (addr & ~PMD_MASK) >> PAGE_SHIFT); > - refs = record_subpages(page, addr, end, pages + *nr); > + page = pmd_page(orig); > + refs = record_subpages(page, PMD_SIZE, addr, end, pages + *nr); > > folio = try_grab_folio(page, refs, flags); > if (!folio)