Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3330064rdb; Thu, 16 Nov 2023 06:52:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcUjWT0EoyzEx5LEVQwXT4Mou2nkMEKj/aqq4ipKzAUFEeohCoeN0wQympjFXUosx6OrFr X-Received: by 2002:a17:902:f688:b0:1c5:d8a3:8789 with SMTP id l8-20020a170902f68800b001c5d8a38789mr10262663plg.4.1700146337892; Thu, 16 Nov 2023 06:52:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700146337; cv=none; d=google.com; s=arc-20160816; b=WSqc4QH+man9DroVDlIVjZpkSRC32Wlr9N6+GlwZAmyYi1novaJHsMeXHuiUxrGcM7 DJuLZ1sdDztx2m1b0Bx0z7vDW79uKr3ZctXc7RUUCrzdtbe8ELWfYIxYrq90RtwsLMB3 jyGUJSgjEMaBeNn3jeBgzUfoAsg2bXfdb9TGA6hOw7nvCmKwO4dykSiI1tbxIq/tsjjr GUprAGv7OOKOXbvb3kOz4CHtTBgqPkTZigT/IDKCTK++3O/id8a+R8ew4HwfdUxEpXgo kilhgp3VzGDiL4rWflZYCSw5GBdGMUFXEcUITnuvi35WAJukjrHg7EYEMzEY+rJFS2WY PWCg== 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=2ojEoDQsJbTKNbq6oPAMc3aknQ7lB4yrHDrRikIo44Y=; fh=rDR6uQTqWpPmO4DS/GwgrKElb15Kny2Oz8UTckqjuDk=; b=LlBXb5lxnXfbrAykyE6yZL0l1s5ntn5m557BYp+JHdCqHdOoyqGzZM+7Phdx7SbteJ 7WB4+K9ULV6VWx2yoAF1O8HAgyUakcMr0CgbTOXHY9PYGNZCoYYLLOYdUSwxmZQCLC4i 7cPW8YyyiW90n+/KhOiZDMyQPHeJl7UQJeUhLkb6CBhxbw8+vU3lePGS3Yxsazy0xvq6 52EgetZ2utwdz73HlGR4wtprH1EmFUTzIDgJz+1Mcc3rPxF8+INw2Yu6wE7tZXZWREpM 0s2RF7MdJd0T7DfvXEvHLIl5LNW6Zb/5lp4APNoFURuP3lWq4bnQKKoUO1lHECIqiguc yQrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hfk9fkdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id i3-20020a1709026ac300b001c470e70cf7si12153855plt.273.2023.11.16.06.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 06:52:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hfk9fkdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 696498183F0A; Thu, 16 Nov 2023 06:52:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343893AbjKPOwC (ORCPT + 99 others); Thu, 16 Nov 2023 09:52:02 -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> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 16 Nov 2023 06:52:15 -0800 (PST) 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)