Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2684267iog; Mon, 27 Jun 2022 00:11:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uqLUI+e19M2yNdIAgA31E1cf94zn7tlJpfMJF4Z3z8JjPmZoWXnmYjuom7dc/ODd7IaPhs X-Received: by 2002:a17:903:1108:b0:168:d2ba:70fd with SMTP id n8-20020a170903110800b00168d2ba70fdmr13114688plh.136.1656313880557; Mon, 27 Jun 2022 00:11:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656313880; cv=none; d=google.com; s=arc-20160816; b=gLA6fz9Z8AOHNSY9EmWABk3scqhtNsIQVWNMt6iQrXzLitS2CuF956j+D8qGyFR9d/ AhEXuiV7Jw3MTtnZXzKd2elzVNj3KxdyVFqiwmxjN75/cUEqkkuQaDE3V3Ol/HGNL38k dUI68yIyn0W9c4XVHy4xwkZlx9UoWdVJHF7+TlHSOFQKPZKJE8IKabZ5qdXL4AQCJ20O LsORKKBmS3jVVoJbtX2jgYg17dJkqHsDve2kfr3/reyeA97fl5i3gJZXupxilq+fxVKC CeaHNaJ6FJX+GfnJrJUyzH+FsKpe8RFk0tWfqY/+mdCnNKSK8adGxVqwwfRcOEdGtufH ZsdQ== 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:dkim-signature; bh=s6YskhKblBTp6d670n0jUd5N1jVCJFrPSjByo6zg+n4=; b=nPRYnB7vscGWFClN1rdn57REjweU74YPzsP9cfBbYzsxw3RZWw3GaUVf9pyUr/10z0 0O8guKwudjFDdzeCjNi//yXYnx7lA9P7j9t8Z6ojB8250ShZvHQ6UGq9Mrx2TXZOn/KV Iw3/qqFNKFeaIzl8Vi42UowgSEXT/MdoOzFBKqDUgYhOinxG/T+D9+zmnLeF/WRFmoLB dhcGuL/RVUSASfVZvg9sm58JrGJ08VvzZF2BL0nyq0oyzgM1upDye1zZvvkAhtuPWoXz NNA41Kme/y4Vms/TOpML5trqV+qlhaVsAgz6OJPAQHB4eJeMy/LBzXfPWpTGR7hGN9us 3RJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="iSYaiX/d"; 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=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t36-20020a634624000000b0040d7ac04fafsi12857125pga.36.2022.06.27.00.11.02; Mon, 27 Jun 2022 00:11:20 -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; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="iSYaiX/d"; 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=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229634AbiF0Gz7 (ORCPT + 99 others); Mon, 27 Jun 2022 02:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbiF0Gz5 (ORCPT ); Mon, 27 Jun 2022 02:55:57 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E2BA2DE0 for ; Sun, 26 Jun 2022 23:55:57 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id i8-20020a17090aee8800b001ecc929d14dso9636486pjz.0 for ; Sun, 26 Jun 2022 23:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=s6YskhKblBTp6d670n0jUd5N1jVCJFrPSjByo6zg+n4=; b=iSYaiX/dx41GqEc0XwQdpzKEEbHBUo9kx8Vgzp9oZKa00sHUJh62oNgysgOzrmkJDZ +oCrpo19mNHhUz7L/tjW4p3PLH8+eIsWY1Xt4VIVulxeZJWdS6XJKHHeZAzpTsgggpoq X+YPxjaAe7YB31/TJsLpXN6WYsSx15i8hR1rNWz5TyntA1jmAgEKdztNsfay9vh5gY0e KlnXNKKV/Hqc+8rAULiQlB0cxozLlBRuPqxRO8zNIGx8Iu36PTLDYToBCgRrMhi0Z8gO hcqnEEPfRNztvyJtdGp8WWNC2sElnhLGjmp4aowBJgDqMkN/CeIbqhkONZOP1Pl+mk1t 2XUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=s6YskhKblBTp6d670n0jUd5N1jVCJFrPSjByo6zg+n4=; b=ABuL0BeQaf+cxqPXl5TcpcHXE4ihJKYupiOoFYiZXyhw47Z2DBLSFjo5MDN02EYvR5 FpXZtYttnqvcyGLtNyAM4N5ERPrcHh18dINFuJ+Sjwil66JLoP262L26rgOGlzSxSMoa 8dmWwVsfgfxkztqdBp7WCgVyme5SUdMREQuhXNysRuQsbdPOzNl+VYc1q91oVjsLezOa 4FX+n0BtUhW9FQNxd5gHotLKES2DpY+Bng1j6IYKgheqnqsQSb5ENmGi4ndbb+llysM0 V+Wy8F6ZHZw2aa9au3H//A54qDYDLmNXEyPrXuZDWIC2RzOeQZXbrgi7IL0ZHsLjLH2G f4vg== X-Gm-Message-State: AJIora+tB/oP3SxHNiNMjNayIHGtVfyEBGyzBvbWE58OEb/ojeDQiFnT Km1eVjBzLsXsvbzJwF4JdS7Pqw== X-Received: by 2002:a17:90a:1c09:b0:1ea:91d4:5a7f with SMTP id s9-20020a17090a1c0900b001ea91d45a7fmr19569048pjs.232.1656312956629; Sun, 26 Jun 2022 23:55:56 -0700 (PDT) Received: from [10.4.214.173] ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id y27-20020a634b1b000000b0040cff9def93sm6224491pga.66.2022.06.26.23.55.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jun 2022 23:55:56 -0700 (PDT) Message-ID: <037fc8c3-9b71-cb83-8882-95d5459a494f@bytedance.com> Date: Mon, 27 Jun 2022 14:55:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] mm: hugetlb: kill set_huge_swap_pte_at() Content-Language: en-US To: Anshuman Khandual , mike.kravetz@oracle.com, songmuchun@bytedance.com, akpm@linux-foundation.org, catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20220626145717.53572-1-zhengqi.arch@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 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. > value is readily available near set_huge_swap_pte_at() call sites. -- Thanks, Qi