Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3762336rdh; Tue, 28 Nov 2023 03:16:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0QcoPiVF+SHVpDrXsrnHiUMugprbPOzVY1aVULmG2uukOTUm89uH2Sj24KqPYPFDK81Rg X-Received: by 2002:a17:90b:1c85:b0:285:8d5c:9114 with SMTP id oo5-20020a17090b1c8500b002858d5c9114mr15084033pjb.19.1701170191132; Tue, 28 Nov 2023 03:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701170191; cv=none; d=google.com; s=arc-20160816; b=yZkiJzeaGgXAT1HYfQFjLF0NnTNVb/rLVgKF83nFT4CjTQIwSUXammdzVCiMTcFu20 Wdo7cT0lqdhMGdmAz0AFnV5cjF4WtZOPeGV219VVjDyOtLtiYMbnUeD71enlOH9Qzjx+ PWOw3ZtKfOQ1pUtl9ZYyBXiNzbIc9Tx73MjhT+5lMQyJ2n5NRlGjI3h3KUa2FHnBgLz/ 9h1O3f2BagTw7RnCkZwqzXlpw6h19aVyJT8/8SDTyQQA+ibEWw3X4ZVWWWLVsVcS23uZ 5uxk6GNoKJWEai3Ck/9Es3szu/yIZq5Rm8m/TREHXHlKqNONBVI/oeRhw2L8yx/T24yD UxgA== 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=PSHTLRWTBRByqx+RBE3QPpdb1F/km8gCrKrVl65t59k=; fh=Iq90pYtK3oOdLRS6wcOYtCi0+G8Np5/ZJK5ks93k25I=; b=0j66/EtMbo5Ds0Ki7KYP5Sq1N7uqeyu8wr3StMpiHuUtaL3glFODt5jNNxvAeCs0tV lOUaarQawgJ3oWW18hNt5YqNzMM1kR+MpNsoz3QjAdUAEAAauiuSoIspMzgX7xXBDpVV WXNLeeS57N95admXgFEXhjBIDvCIg0RinpaZ+sqKQQX95koEv5ibxXWErx6aO5NZAMzM vIObXup4OSExPkX48Mr8W3FeOaF6K3G8rJ69471TqbYGTZjWJ2UAXwZublkdxSIrIWgJ zguCgMgtHvUCIJXJyHWzpC4RgvkuUyXh3oV8O4y56QzBz/Z/rhLNVqI/6rx4uLPdkio8 ucIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m8-20020a17090ade0800b002839a6e8812si12225239pjv.36.2023.11.28.03.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 03:16:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4EE518078CAB; Tue, 28 Nov 2023 03:15:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344495AbjK1LPS (ORCPT + 99 others); Tue, 28 Nov 2023 06:15:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344124AbjK1LPR (ORCPT ); Tue, 28 Nov 2023 06:15:17 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 14E45D60 for ; Tue, 28 Nov 2023 03:15:24 -0800 (PST) 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> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=1.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 28 Nov 2023 03:15:45 -0800 (PST) X-Spam-Level: * 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 > >