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 165F8C4167B for ; Mon, 4 Dec 2023 12:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344005AbjLDMj5 (ORCPT ); Mon, 4 Dec 2023 07:39:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233435AbjLDMjk (ORCPT ); Mon, 4 Dec 2023 07:39:40 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B233D106 for ; Mon, 4 Dec 2023 04:39:45 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A917C1424; Mon, 4 Dec 2023 04:40:32 -0800 (PST) Received: from [10.57.73.130] (unknown [10.57.73.130]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EA8AC3F5A1; Mon, 4 Dec 2023 04:39:42 -0800 (PST) Message-ID: <52b042b9-ec95-4db0-b38a-f7f1cea0b90c@arm.com> Date: Mon, 4 Dec 2023 12:39:41 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 4/4] mm/mmu_gather: Store and process pages in contig ranges Content-Language: en-GB To: David Hildenbrand , Zi Yan , Matthew Wilcox Cc: Will Deacon , "Aneesh Kumar K.V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , Yu Zhao , "Kirill A. Shutemov" , Yin Fengwei , Yang Shi , "Huang, Ying" , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230810103332.3062143-1-ryan.roberts@arm.com> <20230810103332.3062143-5-ryan.roberts@arm.com> <800937DA-BAD0-4C60-B155-AECCA21E955E@nvidia.com> <1a0f5cb8-421c-4f28-a986-f3c381406e81@arm.com> <90EC4C0D-0254-4B93-AFD5-3C09580A77DE@nvidia.com> <6dd6164a-1dd5-46e7-bcf7-b62ff5c6e8ec@arm.com> <890f4455-bf1b-437b-a355-7895e4dd3085@redhat.com> From: Ryan Roberts In-Reply-To: <890f4455-bf1b-437b-a355-7895e4dd3085@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/12/2023 12:28, David Hildenbrand wrote: > On 04.12.23 13:26, Ryan Roberts wrote: >>>>> >>>>> Also, struct page (memmap) might not be always contiguous, using struct page >>>>> points to represent folio range might not give the result you want. >>>>> See nth_page() and folio_page_idx() in include/linux/mm.h. >>>> >>>> Is that true for pages within the same folio too? Or are all pages in a folio >>>> guarranteed contiguous? Perhaps I'm better off using pfn? >>> >>> folio_page_idx() says not all pages in a folio is guaranteed to be contiguous. >>> PFN might be a better choice. >> >> Hi Zi, Matthew, >> >> Zi made this comment a couple of months back that it is incorrect to assume that >> `struct page`s within a folio are (virtually) contiguous. I'm not sure if that's >> really the case though? I see other sites in the source that do page++ when >> iterating over a folio. e.g. smaps_account(), splice_folio_into_pipe(), >> __collapse_huge_page_copy(), etc. >> >> Any chance someone could explain the rules? > > With the vmemmap, they are contiguous. Without a vmemmap, but with sparsemem, we > might end up allocating one memmap chunk per memory section (e.g., 128 MiB). > > So, for example, a 1 GiB hugetlb page could cross multiple 128 MiB sections, and > therefore, the memmap might not be virtually consecutive. OK, is a "memory section" always 128M or is it variable? If fixed, does that mean that it's impossible for a THP to cross section boundaries? (because a THP is always smaller than a section?) Trying to figure out why my original usage in this series was wrong, but presumably the other places that I mentioned are safe. > >