Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5598005ioo; Wed, 1 Jun 2022 08:38:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDmZrpUbhwvpb8/6731l0av7rbTKr+2N2WOnosXoy7YvJldsD1mtj/pivP4Xj7h52LgLq+ X-Received: by 2002:a17:90b:1809:b0:1df:de43:e56 with SMTP id lw9-20020a17090b180900b001dfde430e56mr35315412pjb.135.1654097882971; Wed, 01 Jun 2022 08:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654097882; cv=none; d=google.com; s=arc-20160816; b=iRl1miO7W4VAUTyZjguVbTa18AnFA4vOt9oPn1CkjUSHMrIhwR+M3Up5Kv2jcJTYOT SS3ygcnSUygj+cKjdHhoBGN+n3i38BQB2B98BhiGFCMUbGqTJlGwcx896NlwAIxi0X0e 19/Eq7b91OUIbDTdDLRG2yxZuK6LAQ78Lr8D0Lz7loDPCddVsM5q0vF7uruWqAm0oSML kagxQfdxosvJ9Yp5VdWRNnvv7+mB4mSjV3JF9ObIxkEUUVLy/ysbDc00HrBcOZqDj2WE tKko+1ERZnW6eMn8ludP7a3dQxEq+cVAetrleRUzieg05JzuxMtf+si52Bql4Nj8ySoz w5Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=ACwcEKMNSA2i/HJfLJypgp2CnGIojxqACt6tx6ZGyac=; b=OTu9kwB6IcfhIqqSDUqpzdxg5l0GwLh0uUs6MJF62bNzWny1IaDiqtcBAtX+eMlobx 5SvrH1NsYWuRISUIFnwFvsX7ChDW/qhj2cpvVv6FRicFeCds7RYMWqfoVbaRQ9t4wO6F a4FTYrpJS0VK+3LSljDQl0zl6MMlHXkOt9IjrznroTzfU/DgrGZSPT2LjDjgE/FvWhVU vZ0NiKLv0JhPEC3KrusWM8ErJH2/caSAHgcUggQSp606FtEt0t/gPqBmWlpKfPuCtxT3 ktWSq7vmfO4FsqEu/CXw8dXUed+F0ErTcc8Nh+rvGkJKbNAtwI1EXAW1v3BvVv1lfaWd 3blQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170903244c00b00158da867027si3088302pls.624.2022.06.01.08.37.47; Wed, 01 Jun 2022 08:38:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346238AbiFAG7E (ORCPT + 99 others); Wed, 1 Jun 2022 02:59:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350055AbiFAG6x (ORCPT ); Wed, 1 Jun 2022 02:58:53 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F341C2AC4A for ; Tue, 31 May 2022 23:58:51 -0700 (PDT) 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-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.