Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2751571iog; Mon, 27 Jun 2022 02:05:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbcz+okNqng6BiRzkj+TdDrOPdHdGoYZO4SaZRp2h1zJ1hGUV8ektlG223pvvP3aNmonXT X-Received: by 2002:a05:6402:1a4f:b0:435:7d32:e62e with SMTP id bf15-20020a0564021a4f00b004357d32e62emr15051589edb.270.1656320739112; Mon, 27 Jun 2022 02:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656320739; cv=none; d=google.com; s=arc-20160816; b=lQ2TH71vRI0WKZtNPxtFq8+ULlqplra4lMXlmMUvQeFd2a0GgF1vW9UnKqtRCKiZHc cIVGdc0Q4E9SHWGgwv+ih2xxsDpcz2+4sYFDDYJJhvT2GWxu/PulQENYF+BniegB/VRe CcYio2T4LYmCvb6mzryYekvjERACeUo1Z5qbadOn6ri+KXeUX4A508NwP6fyJ2arP2NW Qhyq3IBVZHYdrEi8X2tRZMZTu9M7u4tUpOFAc7C95fswdKDb9d/FaWb1O3ezxr+Afj3b PKj/wNjG6Tw3717jC7eaF58Rn2mdyWCLZKKUiAnF88N/B2hhF3uhF9pSM7YL+aDIPfdp 17jg== 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=tjyG2sgTlVAF0sQgMJFShLkeK9o5o5IUUGKdyarpPjQ=; b=Spwkrs9YV4jEnrDGrBJxIAIYDqofb+EKC0hUE5WmOAIytSh/A3+Pwo+1Ph5MU41s8a vMFMda0eM2lK3R2bx3ufrfj6j8L2VngPNMYCWhDQz2Qh0cja1uR1KRh+p3GJiAvxJ6bN hStFDQ4IZp1pKwXdu2+ekCa9MBZegGAOQ8r8oX1BatPDxWBFJN5lJhgQ/IecOcZhJ4HN ysFyr+0vZpD2Wd7ezWwF2dFxjDRoVSBcc2Lt18o/oC3s6CCszulflbviLQdhTDLguXUz j0ued0MbrXGBmUn8y1DjPOCErSfy91dPF5RceFFSWWhwAtMkX9K+FQA+ION+061j43k8 cJnQ== 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 j15-20020a50ed0f000000b00435828bf0f8si11319008eds.116.2022.06.27.02.05.14; Mon, 27 Jun 2022 02:05:39 -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 S233591AbiF0I2E (ORCPT + 99 others); Mon, 27 Jun 2022 04:28:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233173AbiF0I17 (ORCPT ); Mon, 27 Jun 2022 04:27:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D6FA632E for ; Mon, 27 Jun 2022 01:27:50 -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 319C71758; Mon, 27 Jun 2022 01:27:50 -0700 (PDT) Received: from [10.162.42.6] (unknown [10.162.42.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F401B3F5A1; Mon, 27 Jun 2022 01:27:46 -0700 (PDT) Message-ID: Date: Mon, 27 Jun 2022 13:57:44 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] mm: hugetlb: kill set_huge_swap_pte_at() Content-Language: en-US To: Muchun Song Cc: Qi Zheng , mike.kravetz@oracle.com, akpm@linux-foundation.org, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20220626145717.53572-1-zhengqi.arch@bytedance.com> <037fc8c3-9b71-cb83-8882-95d5459a494f@bytedance.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,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 6/27/22 13:14, Muchun Song wrote: > On Mon, Jun 27, 2022 at 12:44:19PM +0530, Anshuman Khandual wrote: >> >> >> On 6/27/22 12:25, Qi Zheng wrote: >>> >>> >>> On 2022/6/27 14:18, Anshuman Khandual wrote: >>>> >>>> >>>> On 6/26/22 20:27, Qi Zheng wrote: >>>>> The commit e5251fd43007 ("mm/hugetlb: introduce set_huge_swap_pte_at() >>>>> helper") add set_huge_swap_pte_at() to handle swap entries on >>>>> architectures that support hugepages consisting of contiguous ptes. >>>>> And currently the set_huge_swap_pte_at() is only overridden by arm64. >>>>> >>>>> The set_huge_swap_pte_at() provide a sz parameter to help determine >>>>> the number of entries to be updated. But in fact, all hugetlb swap >>>>> entries contain pfn information, so we can find the corresponding >>>>> folio through the pfn recorded in the swap entry, then the folio_size() >>>>> is the number of entries that need to be updated. >>>>> >>>>> And considering that users will easily cause bugs by ignoring the >>>>> difference between set_huge_swap_pte_at() and set_huge_pte_at(). >>>>> Let's handle swap entries in set_huge_pte_at() and remove the >>>>> set_huge_swap_pte_at(), then we can call set_huge_pte_at() >>>>> anywhere, which simplifies our coding. >>>>> >>>>> Signed-off-by: Qi Zheng >>>>> --- >>>>> � arch/arm64/include/asm/hugetlb.h |� 3 --- >>>>> � arch/arm64/mm/hugetlbpage.c����� | 34 ++++++++++++++++---------------- >>>>> � include/linux/hugetlb.h��������� | 13 ------------ >>>>> � mm/hugetlb.c�������������������� |� 8 +++----- >>>>> � mm/rmap.c����������������������� | 11 +++-------- >>>>> � 5 files changed, 23 insertions(+), 46 deletions(-) >>>>> >>>>> diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h >>>>> index 1fd2846dbefe..d20f5da2d76f 100644 >>>>> --- a/arch/arm64/include/asm/hugetlb.h >>>>> +++ b/arch/arm64/include/asm/hugetlb.h >>>>> @@ -46,9 +46,6 @@ extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr, >>>>> ���������������� pte_t *ptep, unsigned long sz); >>>>> � #define __HAVE_ARCH_HUGE_PTEP_GET >>>>> � extern pte_t huge_ptep_get(pte_t *ptep); >>>>> -extern void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr, >>>>> -���������������� pte_t *ptep, pte_t pte, unsigned long sz); >>>>> -#define set_huge_swap_pte_at set_huge_swap_pte_at >>>>> � � void __init arm64_hugetlb_cma_reserve(void); >>>>> � diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c >>>>> index c9e076683e5d..58b89b9d13e0 100644 >>>>> --- a/arch/arm64/mm/hugetlbpage.c >>>>> +++ b/arch/arm64/mm/hugetlbpage.c >>>>> @@ -238,6 +238,13 @@ static void clear_flush(struct mm_struct *mm, >>>>> ����� flush_tlb_range(&vma, saddr, addr); >>>>> � } >>>>> � +static inline struct folio *hugetlb_swap_entry_to_folio(swp_entry_t entry) >>>>> +{ >>>>> +��� VM_BUG_ON(!is_migration_entry(entry) && !is_hwpoison_entry(entry)); >>>>> + >>>>> +��� return page_folio(pfn_to_page(swp_offset(entry))); >>>>> +} >>>> >>>> Extracting this huge page size from swap entry is an additional operation which >>>> will increase the over all cost for set_huge_swap_pte_at(). At present the size >>> >>> Hmm, I think this cost is very small. And replacing >>> set_huge_swap_pte_at() by transparently handling swap entries helps >>> reduce possible bugs, which is worthwhile. >> >> Possible bugs ? There are just six call sites for this function. > > I think it is easy to make mistakes (see commit 5d4af6195c87). > I usually think of why the swap entry is special for HugeTLB pages > compared to normal pages (why we do not have set_swap_pte_at?). > set_huge_swap_pte_at() make HugeTLB more special, killing it > can make HugeTLB more consistent with normal page. From the point > of view of code maintenance, I think it is better to kill it. What > do you think? Okay, alright. Lets drop set_huge_swap_pte_at() which helps make HugeTLB less special. > > Thanks. > >> Although this proposed patch is functionally correct, I dont see >> a valid enough reason to increase the overall cost in the path. >> > >