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 7509AC433EF for ; Mon, 27 Jun 2022 07:44:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 053D96B0071; Mon, 27 Jun 2022 03:44:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1D516B0072; Mon, 27 Jun 2022 03:44:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE5138E0001; Mon, 27 Jun 2022 03:44:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CEE676B0071 for ; Mon, 27 Jun 2022 03:44:28 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id A221C80731 for ; Mon, 27 Jun 2022 07:44:28 +0000 (UTC) X-FDA: 79623228216.25.B2CFC98 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf26.hostedemail.com (Postfix) with ESMTP id 8B0ED140021 for ; Mon, 27 Jun 2022 07:44:27 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id t21so8241377pfq.1 for ; Mon, 27 Jun 2022 00:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=ODWv5Qp+v1wLWRTVLVYAHP3LMEfiNE4P/O0zE55mdbE=; b=mzlbzZg+72CC06sy+TUkyVi2J1n0aKJWUeNMQd6lzJAxsFplgL5vLiQdpJpa09rMqw jTMVqc4UFP+qr1mylXnB9VypMRnaeD4cHuqqsFz+Q83qyXkV2VKTQz4Gz2lLucC2uhjY cDhlyTXMX0XH1AqMVCiP/qAxDScGS+Fa9+gI1zudGJSBaA0PxLKfroQVfqH8fEBJJLCg WHEAH1FlkeM5+G2jLeHpIYaOMQvpWA5u1j4pDzuDHI0J7K5LHiS0/KEMGKv5vo9z1CPT 92bwatipHtAuZtfLpbnZR5HkMHYadAcIOqwRsM8MK6CLJjUNfWRtB7FJALRErOEJ8UCX U0aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=ODWv5Qp+v1wLWRTVLVYAHP3LMEfiNE4P/O0zE55mdbE=; b=loH3LPuskScW8ESy2qOGwXUrehEjYf7lNvZ12TutYVJs6/fv9guyLT5gP4cmuoOiPD bomQluoEsMtKW0h3gj6UaoaqM0Nne9EdcUc8AhgHJThB0LeBNtilNjtfCgQZ+tFNuIws QIGWKxkJwfSDYXxd0anK2NmLEkvTGz8ZvbkYhaWVtrFv+VTXMr6msPX4HMyZhKxEaLGr TH4LT/XM3vOR6v1v0nR+XdFQmeLluNt8HkncFunloolVevsrQiX7p6JWEv3SneOMCGoV XuSn6JZF+BJ3f5te0JZmL1xOCVBUfA+oX9XggKkXH1ie/5AzpGUxeUgiHasBIEzQg2uH XYQg== X-Gm-Message-State: AJIora8UttHfPhjW71tsCWNFONdLqd2NKWjySxkk5aR/g8igdFQXE8S/ 8LsiY92LrzFsm0vG5u5VHmXkIjvKQpzyvYiu X-Google-Smtp-Source: AGRyM1v35fx4BBtlSljUBRrN450QiFtQMRb1BaPEg/Oc7f4EypF6xlz+nJGnCOzfiwJejkdQ5+jPWA== X-Received: by 2002:a63:af56:0:b0:40d:2430:8fa3 with SMTP id s22-20020a63af56000000b0040d24308fa3mr11987469pgo.376.1656315866287; Mon, 27 Jun 2022 00:44:26 -0700 (PDT) Received: from localhost ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id p20-20020a170903249400b00168f329b282sm6395367plw.155.2022.06.27.00.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 00:44:25 -0700 (PDT) Date: Mon, 27 Jun 2022 15:44:22 +0800 From: Muchun Song To: Anshuman Khandual 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 Subject: Re: [PATCH] mm: hugetlb: kill set_huge_swap_pte_at() Message-ID: References: <20220626145717.53572-1-zhengqi.arch@bytedance.com> <037fc8c3-9b71-cb83-8882-95d5459a494f@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656315868; a=rsa-sha256; cv=none; b=1TTCHYRNQhrdqoB52HDrDD8lbRABEAT+806tUo+XQLmh8dntiAsJd+DsKJ4E5EoG2Fiop7 B6qbkr8f/KHGi1/gR7JbNzlRHGZoc8c+GvfBm27BkzWdxNebXDtjiRJ1lOpc158ZIUxF+i vM6kdutHf1Eoq5OkcNyFAdBXtlNgzPg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=mzlbzZg+; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656315868; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ODWv5Qp+v1wLWRTVLVYAHP3LMEfiNE4P/O0zE55mdbE=; b=DAuOKBagKdVrflpMsFNJVCr/7lVKCHiGLnOajrVtueYDKQ6oC1CpryRwJ4axCK0ASCZtIR Fonyh7VjVL3Kg3BpEBzbb+6bRlUFOwCXb90LOmm8PgulWvpdQG88ao/a6W6Y20tmfIRdLY asI8rCx87lYwfbjS/MrZ7nydJRXFLJc= X-Stat-Signature: ip4iksq4wgsf53iu7rfapdg78xurh5wi X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8B0ED140021 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=mzlbzZg+; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1656315867-72514 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 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? Thanks. > Although this proposed patch is functionally correct, I dont see > a valid enough reason to increase the overall cost in the path. >