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 BE6D9C3ABCE for ; Tue, 17 Sep 2024 03:55:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A0BB6B0088; Mon, 16 Sep 2024 23:55:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34F036B0089; Mon, 16 Sep 2024 23:55:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23DBB6B008A; Mon, 16 Sep 2024 23:55:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 07B076B0088 for ; Mon, 16 Sep 2024 23:55:42 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A68551A01BD for ; Tue, 17 Sep 2024 03:55:41 +0000 (UTC) X-FDA: 82572866082.25.F2AB2E0 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 8700F20004 for ; Tue, 17 Sep 2024 03:55:39 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726545309; 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; bh=7Q7OUMNwxNKHbzhg4vO+DQAWT3pXimF5rEkDJpfQkS8=; b=xqXj/7WDyZA4c9/7bsPJy6grhoKisV28UfKCNm/Pmf5KFQ+SYpOIERHrmwvOHTXJFqsrQl EmOu4jnj00waJ5JkVUQy1RHqaFiWUDivYTWnIG/1ADDH0cI53y4mzdXPDcbN707kzeDMwT sikbICa33/Toi74eLvF2KzAlz+lNsPE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726545309; a=rsa-sha256; cv=none; b=3w2mWwwjn5PvAN7S2X603ZapIaY9qPNNVJ5Zxhc6mzKq3RD/u/Lry66ghxwTHkOhkMMlhY nbsieZC8twrLZft1+YpIOAg6yqhjak7wKgcLBU3jatI9GHHHqTKZE/Y+v2VR2nbA3H0ZZJ ipvaBZFzh1Njpfd3D+DNwSpODJ17+Es= 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 BF45B106F; Mon, 16 Sep 2024 20:56:07 -0700 (PDT) Received: from [10.162.40.18] (e116581.arm.com [10.162.40.18]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 101BE3F66E; Mon, 16 Sep 2024 20:55:33 -0700 (PDT) Message-ID: <091f517d-e7dc-4c10-b1ac-39658f31f0ed@arm.com> Date: Tue, 17 Sep 2024 09:25:27 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: Compute mTHP order efficiently To: Matthew Wilcox Cc: akpm@linux-foundation.org, david@redhat.com, ryan.roberts@arm.com, anshuman.khandual@arm.com, baohua@kernel.org, hughd@google.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, baolin.wang@linux.alibaba.com, gshan@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20240913091902.1160520-1-dev.jain@arm.com> Content-Language: en-US From: Dev Jain In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: 39bkj433pbgzk7rhamj51yqinxzue8ob X-Rspamd-Queue-Id: 8700F20004 X-Rspamd-Server: rspam11 X-HE-Tag: 1726545339-321921 X-HE-Meta: U2FsdGVkX19O+0vrOTbQ017z7vo58ZUwbSzgl+EF9LKOxjMGgYT+2003DHjjQVTGMEhegI/9KhInI7z388SJhnbn2QmQhEwLELW2Ja3fND3pMyAwXyNVeyjSjBxVAoCmqRBaFGDU94YtXSZkjdm3p2Kz194mCsidv4yhIlWsipWoJ/rmIJuZtDvtFABFazBcsfdWb67KuMDa5/tTjysx707G0kWrQTqtKJQu8vIyMdswjJiaoz/eEXtdCGb4bGqKYeTkMiXQdGO+uhn3970muidl04QN2Aqpdk5RBUtXKr2yt8GAUeI5qJ3d+9yck1s8QIZYdtPJD10eCFwT2z/y1hsp3gveaAwxi2xYGpT1ptJP9b3D5JJ9E9y04wyxejxYuxbvNpv3eeJR1qPTK7IDOliYlCtQb1uOddP4ePm0RsMI66EHZQaM10QvOujSsnLaQUF60Rn8i1TI9ZUtZ/Ol5jQGv3RmcA9Ss3gRmx6Ocoo0CWP3sX5arnNBc3GD0101YoKYdC6MiOtIs4sIitpHHyJv05UCAK76l4nCGSGXVLq+YH5XptCBDCiu3XUFzoywfty05IhQI6Xd13aYYgqVQqC7Cm1BIACdkMpQudPVfv4JqExDkG9D6NeZnNcsGPwjvA84DgZYukZNKZWRiAeuecxTDZF4gBV8wjf4EVb/J4zhKJ/ZxY5RCNh14j2sD7eW4WUl5xzSRPA/+ALiWCJIaqEoNLWAsNKb39upZwQfHs4SxwWIPfh14qKa8Ucua9Lph6M+MEgWqpqdwhEIn+HFNmlx/eVmaVFP4ADy/Sp0JgOCICpyX4+MDlc2ALHTgedDbr33VMfvqUK3ZFiMK0UFh43lMOxcGg0NP3gPwKxpsJbaBt/2gy7DQR3KMujIhUJV62EM+YLqdm2MoC/wMNMSoUPnP5cqTG8rJifcwWE5B3Msp39IfZAHuOl5T336ZwWWLcoOZA9rKBdkBkGa9PB 0jaYvuVx QtLeE354zUb4IwzHrj+eZuxckwIk3RtLJ7P9KOf4PNFG1ku2OG1OM7G/VHoKRDw/SRmHVZdCVWojkFnWvHayvbWrQN3PGRKXU7Ud5+PHLX5XXlXjeVJ3QNxkkPLKMpkxAdR+0KkXYR1pNjoAoMZNXTtlu/A== 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: List-Subscribe: List-Unsubscribe: On 9/16/24 18:54, Matthew Wilcox wrote: > On Fri, Sep 13, 2024 at 02:49:02PM +0530, Dev Jain wrote: >> We use pte_range_none() to determine whether contiguous PTEs are empty >> for an mTHP allocation. Instead of iterating the while loop for every >> order, use some information, which is the first set PTE found, from the >> previous iteration, to eliminate some cases. The key to understanding >> the correctness of the patch is that the ranges we want to examine >> form a strictly decreasing sequence of nested intervals. > This is a lot more complicated. Do you have any numbers that indicate > that it's faster? Yes, it's fewer memory references, but you've gone > from a simple linear scan that's easy to prefetch to an exponential scan > that might confuse the prefetchers. I do have some numbers, I tested with a simple program, and also used ktime API, with the latter, enclosing from "order = highest_order(orders)" till "pte_unmap(pte)" (enclosing the entire while loop), a rough average estimate is that without the patch, it takes 1700 ns to execute, with the patch, on an average it takes 80 - 100ns less. I cannot think of a good testing program... For the prefetching thingy, I am still doing a linear scan, and in each iteration, with the patch, the range I am scanning is going to strictly lie inside the range I would have scanned without the patch. Won't the compiler and the CPU still do prefetching, but on a smaller range; where does the prefetcher get confused? I confess, I do not understand this very well.