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 22D81C43334 for ; Mon, 27 Jun 2022 07:30:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9263F6B0071; Mon, 27 Jun 2022 03:30:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D6946B0072; Mon, 27 Jun 2022 03:30:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79EC08E0001; Mon, 27 Jun 2022 03:30:04 -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 69A836B0071 for ; Mon, 27 Jun 2022 03:30:04 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 374AAF9D for ; Mon, 27 Jun 2022 07:30:04 +0000 (UTC) X-FDA: 79623191928.19.A95B2B4 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf13.hostedemail.com (Postfix) with ESMTP id DC24B2002A for ; Mon, 27 Jun 2022 07:30:02 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so3114218pji.4 for ; Mon, 27 Jun 2022 00:30:00 -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=T3JQxNLuvQFFoKNIfIZgs8zEjLxjZBsob8h8p5OweJg=; b=lPB+W2tSDMWq+1L6Am7ZFvdthx6ERZTQU2Tcm2Du9bBL/MpqvyM4QdD71l4J0zfZ52 J2Nc9onLnJ7TV8e6TahECtPc0WqTNoJ5fFxojTV/a0npssD6smC/aMfJXkvq/hrLh1tu M/bd8DTleLjqT33mz+eABsaPHqgQL/UZYZbahhZ2jMixHH+0eR99kqb53s9Xvra8rlBE zKmMbVtVT6WwSkO5UbZ4zETbWUi8CUgzaCsDFGh4F+Uxb9m/6KLie3+q+R+1trDk8FmK 7SKmF3vR6/OelynrUuU7gq1xwyBt3Y8EL9AyTkuYbfUdTsnM/1BpUIG3IWxYtX8fpYb8 huvg== 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=T3JQxNLuvQFFoKNIfIZgs8zEjLxjZBsob8h8p5OweJg=; b=VoZBtCPRRL+pazedB19IKiLfgCdzyNobkBwI8OEFj2SI9d8WvmlrJt9Y+arDjX9aEB X+vUF79EX2JeETen+z6Uj9UR39kgA+XYSBhzBd12gwSaFGr/D4xpv+Bj/m6bDDY56FXB wtvEdylidn/Ee8p+1LRLYktLxcinTsbTrC9WmnCXFnqgTHc6U0KtC3UE901cdBLSv5bv e0EanoEI1brQZnFIEQsEETm4MW7nwRUcQcEgs1rKlFi9RmAhJelA5pWHoeZvOnpcB3Kl Sj5zskUzmky9oXNdkIshDnTGM5/kH0io0v/F248TCgwpnjPR+kMS83BKTHoMEv9MKkC/ AMrw== X-Gm-Message-State: AJIora+Pf/l1cIrRDvE2ATdSpwmlIn0eyg00MmKEicGqJQ2cqYswjsdl +1jq8ko70EorfueYYSaWLIt6DHJyWcIKAw== X-Google-Smtp-Source: AGRyM1ux+2OWFeWi4caOV2zZI7kRbo/dHwWgixD1wm1nF7Y0pkcpszbij64LbX7hvCsWu8f9Y5EG6w== X-Received: by 2002:a17:902:c943:b0:16a:3ab8:3678 with SMTP id i3-20020a170902c94300b0016a3ab83678mr12993743pla.56.1656314999954; Mon, 27 Jun 2022 00:29:59 -0700 (PDT) Received: from [10.4.214.173] ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id q10-20020a170902f78a00b0016b80d2fac8sm874902pln.248.2022.06.27.00.29.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jun 2022 00:29:59 -0700 (PDT) Message-ID: Date: Mon, 27 Jun 2022 15:29:52 +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> <037fc8c3-9b71-cb83-8882-95d5459a494f@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lPB+W2tS; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656315003; a=rsa-sha256; cv=none; b=bfTo6xqCUT0lWj+RUEnboIl6VCNNIHoXILhTy46wl4YZ6Jgvb4f45bjYf7abAsxy4yyXM+ Z3NP1R6KJQyiAg87fu47TPiOooN/S2W63MQBJ9DdGfiVvMk14Y/yD5qFMBTQGRs0ZOYT5T n9KX61PtDyGJox3g+QpuI0dgm4eroh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656315003; 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=T3JQxNLuvQFFoKNIfIZgs8zEjLxjZBsob8h8p5OweJg=; b=VSmxpYryDlxe+oLdqOTHAwZ2rYegiw1FT4FI7kkEqIpbtkCbnlLorbu+XxoNsgKEjKVOyi AlKQFYGMhoRzY0qVCe+omyEH9XQqzPRfjny/v67brnb5Tjz76Y9AGDYOtTWS8V7PIoYsik NZvWjXiAL3mNgHW77EMeG8DzcxPOTH0= X-Stat-Signature: srsr7tkmt7hdzeof5d8x8jp5oi9h3i7y X-Rspamd-Server: rspam08 X-Rspam-User: X-Rspamd-Queue-Id: DC24B2002A Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lPB+W2tS; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com X-HE-Tag: 1656315002-3369 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 2022/6/27 15:14, 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. For the swap entry of hugetlb, we need to remember that we should call set_huge_swap_pte_at() instead of set_huge_pte_at() every time. And the difference between the two is only on arm64, other architectures should not need to pay attention to this. > Although this proposed patch is functionally correct, I dont see > a valid enough reason to increase the overall cost in the path. -- Thanks, Qi