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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFE89C433EF for ; Wed, 1 Jun 2022 06:58:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47C476B007B; Wed, 1 Jun 2022 02:58:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 42FD96B007D; Wed, 1 Jun 2022 02:58:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 340706B007E; Wed, 1 Jun 2022 02:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 267586B007B for ; Wed, 1 Jun 2022 02:58:53 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 04C3B6049D for ; Wed, 1 Jun 2022 06:58:52 +0000 (UTC) X-FDA: 79528764546.14.0824ABC Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 58D54180007 for ; Wed, 1 Jun 2022 06:58:37 +0000 (UTC) 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 81F9023A; Tue, 31 May 2022 23:58:51 -0700 (PDT) Received: from [10.162.40.45] (unknown [10.162.40.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4B29C3F73D; Tue, 31 May 2022 23:58:47 -0700 (PDT) Message-ID: <294314f1-d306-0eb9-059c-f10cb79b9e76@arm.com> Date: Wed, 1 Jun 2022 12:28:44 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [RFC PATCH 1/3] hugetlb: skip to end of PT page mapping when pte not present Content-Language: en-US To: Mike Kravetz , Muchun Song , Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Paul Walmsley , Christian Borntraeger , Andrew Morton References: <20220527225849.284839-1-mike.kravetz@oracle.com> <20220527225849.284839-2-mike.kravetz@oracle.com> <95bd9375-36d2-7e34-83a8-d9eedfe70956@oracle.com> From: Anshuman Khandual In-Reply-To: <95bd9375-36d2-7e34-83a8-d9eedfe70956@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: 9hjutu38aqwt763cgcyima9rwksdzqmg X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 58D54180007 X-HE-Tag: 1654066717-722145 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 5/31/22 22:35, Mike Kravetz wrote: > On 5/30/22 19:04, Muchun Song wrote: >> On Mon, May 30, 2022 at 03:56:43PM -0400, Peter Xu wrote: >>> Hi, Mike, >>> >>> On Fri, May 27, 2022 at 03:58:47PM -0700, Mike Kravetz wrote: >>>> +unsigned long hugetlb_mask_last_hp(struct hstate *h) >>>> +{ >>>> + unsigned long hp_size = huge_page_size(h); >>>> + >>>> + if (hp_size == P4D_SIZE) >>>> + return PGDIR_SIZE - P4D_SIZE; >>>> + else if (hp_size == PUD_SIZE) >>>> + return P4D_SIZE - PUD_SIZE; >>>> + else if (hp_size == PMD_SIZE) >>>> + return PUD_SIZE - PMD_SIZE; >>>> + >>>> + return ~(0); >>>> +} >>> >>> How about: >>> >>> unsigned long hugetlb_mask_last_hp(struct hstate *h) >>> { >>> unsigned long hp_size = huge_page_size(h); >>> >>> return hp_size * (PTRS_PER_PTE - 1); >>> } >>> >> >> +1 >> > > > I like this as well, but I wonder if we should put something like the > following in just to be safe. > > BUILD_BUG_ON(PTRS_PER_PTE != PTRS_PER_PMD); > BUILD_BUG_ON(PTRS_PER_PTE != PTRS_PER_PUD); > BUILD_BUG_ON(PTRS_PER_PTE != PTRS_PER_P4D); Exactly, assuming that PTRS_PER_PTE entries are present per page table page for all supported HugeTLB levels might be bit risky, particularly for the top level. Hence rather than all these additional BUILD_BUG_ON() checks for using standard page table page entries i.e PTRS_PER_PTE, it might be better to just stick with the original check either via 'if else' as proposed or better with a switch case.