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 B370FC4167B for ; Tue, 28 Nov 2023 11:15:52 +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-Transfer-Encoding:Content-Type: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=GbZedJML2+BOAAgPjLGQNd9Arj1thI9nYJnrGAXGvbo=; b=o4PHHJwgUGpyvo 5jNENCrVcv8DDjVlfB5Mnpldsxx+7DCn0dEYkM9E2evIKgmY7UVIsrU6I97DJU7EIWV6ZJr7wwZV0 SzMkH5ftRGyuCvxYjc+JBfSAkcrrGB7b2xjB4HL3TxG5RD+D5tZcZpgeV2tEsjJC3f4b9+5uylpgi QibhmCp/A38X18vde+1AYfnrPyegrH3NOOhXlwFIoZEpIb90WK5Y6DJ5g+Qmb6cKUQZb41x6CsuWv r0yLfnvacL8YuV/5/ygjTAUULFyGJXaix+0dkHmdXzefKfMat+QHEI/E2kKm3G2O/3PQpSW83ZVdW Agr9L/hm+IQMCXgRsaSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7w3u-0051cy-0m; Tue, 28 Nov 2023 11:15:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7w3r-0051bI-37 for linux-arm-kernel@lists.infradead.org; Tue, 28 Nov 2023 11:15:29 +0000 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 48454C15; Tue, 28 Nov 2023 03:16:11 -0800 (PST) Received: from [10.1.33.188] (XHFQ2J9959.cambridge.arm.com [10.1.33.188]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B4A923F73F; Tue, 28 Nov 2023 03:15:20 -0800 (PST) Message-ID: <51f57fa1-a2ca-4e3e-82cd-b0733d4f12a7@arm.com> Date: Tue, 28 Nov 2023 11:15:19 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 14/14] arm64/mm: Add ptep_get_and_clear_full() to optimize process teardown Content-Language: en-GB To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, andreyknvl@gmail.com, anshuman.khandual@arm.com, ardb@kernel.org, catalin.marinas@arm.com, david@redhat.com, dvyukov@google.com, glider@google.com, james.morse@arm.com, jhubbard@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, ryabinin.a.a@gmail.com, suzuki.poulose@arm.com, vincenzo.frascino@arm.com, wangkefeng.wang@huawei.com, will@kernel.org, willy@infradead.org, yuzenghui@huawei.com, yuzhao@google.com, ziy@nvidia.com References: <20231115163018.1303287-15-ryan.roberts@arm.com> <20231128073254.37870-1-v-songbaohua@oppo.com> From: Ryan Roberts In-Reply-To: <20231128073254.37870-1-v-songbaohua@oppo.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231128_031528_057493_FFC22BD9 X-CRM114-Status: GOOD ( 14.22 ) 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 28/11/2023 07:32, Barry Song wrote: >> +#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL >> +static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, >> + unsigned long addr, pte_t *ptep, int full) >> +{ >> + pte_t orig_pte = __ptep_get(ptep); >> + >> + if (!pte_valid_cont(orig_pte) || !full) { >> + contpte_try_unfold(mm, addr, ptep, orig_pte); >> + return __ptep_get_and_clear(mm, addr, ptep); >> + } else >> + return contpte_ptep_get_and_clear_full(mm, addr, ptep); >> +} >> + > > Hi Ryan, > > I feel quite hard to understand the code. when !pte_valid_cont(orig_pte), > we will call contpte_try_unfold(mm, addr, ptep, orig_pte); > > but in contpte_try_unfold(), we call unfold only if pte_valid_cont() > is true: > static inline void contpte_try_unfold(struct mm_struct *mm, unsigned long addr, > pte_t *ptep, pte_t pte) > { > if (contpte_is_enabled(mm) && pte_valid_cont(pte)) > __contpte_try_unfold(mm, addr, ptep, pte); > } > > so do you mean the below? > > if (!pte_valid_cont(orig_pte)) > return __ptep_get_and_clear(mm, addr, ptep); > > if (!full) { > contpte_try_unfold(mm, addr, ptep, orig_pte); > return __ptep_get_and_clear(mm, addr, ptep); > } else { > return contpte_ptep_get_and_clear_full(mm, addr, ptep); > } Yes, this is equivalent. In general, I was trying not to spray `if (pte_valid_cont(orig_pte))` checks everywhere to guard contpte_try_unfold() and instead put the checks into contpte_try_unfold() (hence the 'try'). I figured just calling it unconditionally and letting the compiler optimize as it sees fit was the cleanest approach. But in this instance I can see this is confusing. I'll modify as you suggest. Thanks! > > Thanks > Barry > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel