From mboxrd@z Thu Jan 1 00:00:00 1970 From: Baolin Wang Date: Sat, 18 Jun 2022 03:27:59 +0000 Subject: Re: [PATCH 1/4] hugetlb: skip to end of PT page mapping when pte not present Message-Id: List-Id: References: <20220616210518.125287-1-mike.kravetz@oracle.com> <20220616210518.125287-2-mike.kravetz@oracle.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Mike Kravetz , Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Muchun Song , Michal Hocko , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Anshuman Khandual , Paul Walmsley , Christian Borntraeger , catalin.marinas@arm.com, will@kernel.org, Andrew Morton On 6/18/2022 1:17 AM, Mike Kravetz wrote: > On 06/17/22 10:15, Peter Xu wrote: >> Hi, Mike, >> >> On Thu, Jun 16, 2022 at 02:05:15PM -0700, Mike Kravetz wrote: >>> @@ -6877,6 +6896,39 @@ pte_t *huge_pte_offset(struct mm_struct *mm, >>> return (pte_t *)pmd; >>> } >>> >>> +/* >>> + * Return a mask that can be used to update an address to the last huge >>> + * page in a page table page mapping size. Used to skip non-present >>> + * page table entries when linearly scanning address ranges. Architectures >>> + * with unique huge page to page table relationships can define their own >>> + * version of this routine. >>> + */ >>> +unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + unsigned long hp_size = huge_page_size(h); >>> + >>> + switch (hp_size) { >>> + case P4D_SIZE: >>> + return PGDIR_SIZE - P4D_SIZE; >>> + case PUD_SIZE: >>> + return P4D_SIZE - PUD_SIZE; >>> + case PMD_SIZE: >>> + return PUD_SIZE - PMD_SIZE; >>> + default: >> >> Should we add a WARN_ON_ONCE() if it should never trigger? >> > > Sure. I will add this. > >>> + break; /* Should never happen */ >>> + } >>> + >>> + return ~(0UL); >>> +} >>> + >>> +#else >>> + >>> +/* See description above. Architectures can provide their own version. */ >>> +__weak unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + return ~(0UL); >> >> I'm wondering whether it's better to return 0 rather than ~0 by default. >> Could an arch with !CONFIG_ARCH_WANT_GENERAL_HUGETLB wrongly skip some >> valid address ranges with ~0, or perhaps I misread? > > Thank you, thank you, thank you Peter! > > Yes, the 'default' return for hugetlb_mask_last_page() should be 0. If > there is no 'optimization', we do not want to modify the address so we > want to OR with 0 not ~0. My bad, I must have been thinking AND instead > of OR. > > I will change here as well as in Baolin's patch. Ah, I also overlooked this. Thanks Peter, and thanks Mike for updating. 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 D2104C433EF for ; Sat, 18 Jun 2022 03:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235542AbiFRD2E (ORCPT ); Fri, 17 Jun 2022 23:28:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383842AbiFRD2D (ORCPT ); Fri, 17 Jun 2022 23:28:03 -0400 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 948B011827; Fri, 17 Jun 2022 20:27:57 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=24;SR=0;TI=SMTPD_---0VGi1ydh_1655522870; Received: from 30.13.184.185(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VGi1ydh_1655522870) by smtp.aliyun-inc.com; Sat, 18 Jun 2022 11:27:51 +0800 Message-ID: Date: Sat, 18 Jun 2022 11:27:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 1/4] hugetlb: skip to end of PT page mapping when pte not present To: Mike Kravetz , Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Muchun Song , Michal Hocko , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Anshuman Khandual , Paul Walmsley , Christian Borntraeger , catalin.marinas@arm.com, will@kernel.org, Andrew Morton References: <20220616210518.125287-1-mike.kravetz@oracle.com> <20220616210518.125287-2-mike.kravetz@oracle.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On 6/18/2022 1:17 AM, Mike Kravetz wrote: > On 06/17/22 10:15, Peter Xu wrote: >> Hi, Mike, >> >> On Thu, Jun 16, 2022 at 02:05:15PM -0700, Mike Kravetz wrote: >>> @@ -6877,6 +6896,39 @@ pte_t *huge_pte_offset(struct mm_struct *mm, >>> return (pte_t *)pmd; >>> } >>> >>> +/* >>> + * Return a mask that can be used to update an address to the last huge >>> + * page in a page table page mapping size. Used to skip non-present >>> + * page table entries when linearly scanning address ranges. Architectures >>> + * with unique huge page to page table relationships can define their own >>> + * version of this routine. >>> + */ >>> +unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + unsigned long hp_size = huge_page_size(h); >>> + >>> + switch (hp_size) { >>> + case P4D_SIZE: >>> + return PGDIR_SIZE - P4D_SIZE; >>> + case PUD_SIZE: >>> + return P4D_SIZE - PUD_SIZE; >>> + case PMD_SIZE: >>> + return PUD_SIZE - PMD_SIZE; >>> + default: >> >> Should we add a WARN_ON_ONCE() if it should never trigger? >> > > Sure. I will add this. > >>> + break; /* Should never happen */ >>> + } >>> + >>> + return ~(0UL); >>> +} >>> + >>> +#else >>> + >>> +/* See description above. Architectures can provide their own version. */ >>> +__weak unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + return ~(0UL); >> >> I'm wondering whether it's better to return 0 rather than ~0 by default. >> Could an arch with !CONFIG_ARCH_WANT_GENERAL_HUGETLB wrongly skip some >> valid address ranges with ~0, or perhaps I misread? > > Thank you, thank you, thank you Peter! > > Yes, the 'default' return for hugetlb_mask_last_page() should be 0. If > there is no 'optimization', we do not want to modify the address so we > want to OR with 0 not ~0. My bad, I must have been thinking AND instead > of OR. > > I will change here as well as in Baolin's patch. Ah, I also overlooked this. Thanks Peter, and thanks Mike for updating. 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25CE4C43334 for ; Sat, 18 Jun 2022 03:33:47 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LQ1j54Pn1z3dpC for ; Sat, 18 Jun 2022 13:33:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.43; helo=out30-43.freemail.mail.aliyun.com; envelope-from=baolin.wang@linux.alibaba.com; receiver=) X-Greylist: delayed 305 seconds by postgrey-1.36 at boromir; Sat, 18 Jun 2022 13:33:09 AEST Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4LQ1hP3Mnxz3cCP for ; Sat, 18 Jun 2022 13:33:08 +1000 (AEST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=24;SR=0;TI=SMTPD_---0VGi1ydh_1655522870; Received: from 30.13.184.185(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VGi1ydh_1655522870) by smtp.aliyun-inc.com; Sat, 18 Jun 2022 11:27:51 +0800 Message-ID: Date: Sat, 18 Jun 2022 11:27:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 1/4] hugetlb: skip to end of PT page mapping when pte not present To: Mike Kravetz , Peter Xu References: <20220616210518.125287-1-mike.kravetz@oracle.com> <20220616210518.125287-2-mike.kravetz@oracle.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Hocko , linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org, catalin.marinas@arm.com, Muchun Song , linux-mips@vger.kernel.org, linux-mm@kvack.org, James Houghton , sparclinux@vger.kernel.org, will@kernel.org, Mina Almasry , linux-s390@vger.kernel.org, Christian Borntraeger , Anshuman Khandual , Paul Walmsley , Naoya Horiguchi , linux-arm-kernel@lists.infradead.org, linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, "Aneesh Kumar K . V" , Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 6/18/2022 1:17 AM, Mike Kravetz wrote: > On 06/17/22 10:15, Peter Xu wrote: >> Hi, Mike, >> >> On Thu, Jun 16, 2022 at 02:05:15PM -0700, Mike Kravetz wrote: >>> @@ -6877,6 +6896,39 @@ pte_t *huge_pte_offset(struct mm_struct *mm, >>> return (pte_t *)pmd; >>> } >>> >>> +/* >>> + * Return a mask that can be used to update an address to the last huge >>> + * page in a page table page mapping size. Used to skip non-present >>> + * page table entries when linearly scanning address ranges. Architectures >>> + * with unique huge page to page table relationships can define their own >>> + * version of this routine. >>> + */ >>> +unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + unsigned long hp_size = huge_page_size(h); >>> + >>> + switch (hp_size) { >>> + case P4D_SIZE: >>> + return PGDIR_SIZE - P4D_SIZE; >>> + case PUD_SIZE: >>> + return P4D_SIZE - PUD_SIZE; >>> + case PMD_SIZE: >>> + return PUD_SIZE - PMD_SIZE; >>> + default: >> >> Should we add a WARN_ON_ONCE() if it should never trigger? >> > > Sure. I will add this. > >>> + break; /* Should never happen */ >>> + } >>> + >>> + return ~(0UL); >>> +} >>> + >>> +#else >>> + >>> +/* See description above. Architectures can provide their own version. */ >>> +__weak unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + return ~(0UL); >> >> I'm wondering whether it's better to return 0 rather than ~0 by default. >> Could an arch with !CONFIG_ARCH_WANT_GENERAL_HUGETLB wrongly skip some >> valid address ranges with ~0, or perhaps I misread? > > Thank you, thank you, thank you Peter! > > Yes, the 'default' return for hugetlb_mask_last_page() should be 0. If > there is no 'optimization', we do not want to modify the address so we > want to OR with 0 not ~0. My bad, I must have been thinking AND instead > of OR. > > I will change here as well as in Baolin's patch. Ah, I also overlooked this. Thanks Peter, and thanks Mike for updating. 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C637C433EF for ; Sat, 18 Jun 2022 03:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WvfS4UleXdoHTPQCyrfVHZ9fvnYkcWRzVFkh/FyvNiY=; b=tYG7OhkGY2WqBi yQJrCrWsJl1cR8s+UFugrzjqVk0oLkRoKogNm4aeas3s55WD+UI60pTCA/svOU5mW2MKw7ZUj+W7p UrvlUBlzIEGwemYzmH3U+fPKZ8Qa+n/y9eqNZhIjr32zdneXXzFevCori2wMnrDBek20A64Fa+/cv BuOk03HgY29nYALe9DeV/hS5CHMSUaaGmxHIDd4XxqO1iK3ctszOYGRNYZJP9Yn4qrW/RNJGEQvrd jjfm3FJFYlGcntkrX6UJE9uxnppVLHXGPjCxudo9jbUdOCKfCgT/B75oATIMBrNUm9wxEhOep2Xe8 9r5buyP1+AfYDWv2jTAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o2P7y-00AEES-Am; Sat, 18 Jun 2022 03:28:02 +0000 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o2P7u-00AECj-Jl for linux-arm-kernel@lists.infradead.org; Sat, 18 Jun 2022 03:28:00 +0000 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=24;SR=0;TI=SMTPD_---0VGi1ydh_1655522870; Received: from 30.13.184.185(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VGi1ydh_1655522870) by smtp.aliyun-inc.com; Sat, 18 Jun 2022 11:27:51 +0800 Message-ID: Date: Sat, 18 Jun 2022 11:27:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 1/4] hugetlb: skip to end of PT page mapping when pte not present To: Mike Kravetz , Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Muchun Song , Michal Hocko , Naoya Horiguchi , James Houghton , Mina Almasry , "Aneesh Kumar K . V" , Anshuman Khandual , Paul Walmsley , Christian Borntraeger , catalin.marinas@arm.com, will@kernel.org, Andrew Morton References: <20220616210518.125287-1-mike.kravetz@oracle.com> <20220616210518.125287-2-mike.kravetz@oracle.com> From: Baolin Wang In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220617_202758_864432_BCF64D66 X-CRM114-Status: GOOD ( 14.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 6/18/2022 1:17 AM, Mike Kravetz wrote: > On 06/17/22 10:15, Peter Xu wrote: >> Hi, Mike, >> >> On Thu, Jun 16, 2022 at 02:05:15PM -0700, Mike Kravetz wrote: >>> @@ -6877,6 +6896,39 @@ pte_t *huge_pte_offset(struct mm_struct *mm, >>> return (pte_t *)pmd; >>> } >>> >>> +/* >>> + * Return a mask that can be used to update an address to the last huge >>> + * page in a page table page mapping size. Used to skip non-present >>> + * page table entries when linearly scanning address ranges. Architectures >>> + * with unique huge page to page table relationships can define their own >>> + * version of this routine. >>> + */ >>> +unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + unsigned long hp_size = huge_page_size(h); >>> + >>> + switch (hp_size) { >>> + case P4D_SIZE: >>> + return PGDIR_SIZE - P4D_SIZE; >>> + case PUD_SIZE: >>> + return P4D_SIZE - PUD_SIZE; >>> + case PMD_SIZE: >>> + return PUD_SIZE - PMD_SIZE; >>> + default: >> >> Should we add a WARN_ON_ONCE() if it should never trigger? >> > > Sure. I will add this. > >>> + break; /* Should never happen */ >>> + } >>> + >>> + return ~(0UL); >>> +} >>> + >>> +#else >>> + >>> +/* See description above. Architectures can provide their own version. */ >>> +__weak unsigned long hugetlb_mask_last_page(struct hstate *h) >>> +{ >>> + return ~(0UL); >> >> I'm wondering whether it's better to return 0 rather than ~0 by default. >> Could an arch with !CONFIG_ARCH_WANT_GENERAL_HUGETLB wrongly skip some >> valid address ranges with ~0, or perhaps I misread? > > Thank you, thank you, thank you Peter! > > Yes, the 'default' return for hugetlb_mask_last_page() should be 0. If > there is no 'optimization', we do not want to modify the address so we > want to OR with 0 not ~0. My bad, I must have been thinking AND instead > of OR. > > I will change here as well as in Baolin's patch. Ah, I also overlooked this. Thanks Peter, and thanks Mike for updating. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel