Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1679486rdb; Wed, 31 Jan 2024 06:08:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IERzt/HErOLLkPMmGvnscamRmlwXELAwmrdTIQ/DY/VacCKj/8BeXmuFO+/9o11dnTGtT9i X-Received: by 2002:a17:902:ee8c:b0:1d8:ce58:f4ad with SMTP id a12-20020a170902ee8c00b001d8ce58f4admr1795378pld.1.1706710139505; Wed, 31 Jan 2024 06:08:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706710139; cv=pass; d=google.com; s=arc-20160816; b=KRopKmB6KI2LsXuVWpghgrVGwcHCuV3WArtxMquvP+n9A/slt6yn5e6I+8BKAURnqf jdH/Feu8370QrMFUT+Lg8E0QX9eXKu+7ooZY7PTieZE2bhhHYUCYWPBkw82B/CPp+3J+ ytOurhskn1cidqdmzlb1789l9bTRjOEpfqmZJYkhzX7M77SAHWdFbRNmpqDFDVIBzS3o Q3pyiYrfJ21no/f6EWzNUIc0x7Wvapy6sY96lFGlFwKSJjOcq7fNLy7zCCI9ZhlBXcJj oXU8m2q086INAJbdCzdi5M+3RP2NZvXQmOl0Rrz4CqCn5PSFNz2NzzqRR1aP0HXTZYAH ZKUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=vNnp/Z0S7DqUPASGq4M26R4kayT9Cyd518Jol1/4wN4=; fh=BmmuTGs32Je8vIXeRmtkwOgeixnOfUwakPB3HDR8hf4=; b=qtLq3IBsJdzuAF9RR1Sl74KXLrp372ZpzPVE7U7mYPoAy+H75I+0rSzwy4zQmLCzua mwDRn1rzLmUeKx+yQCSxVDjePXQ539XbzE7bSgu2uBUewfs7xYbOkuGNlfFDSGmJMtBr yMlD1iAgEg4dSKsTpaAiCeowQgIUCgIvRzeE5HsWWh0FtVbla2OmFjpZffQFSDcZI705 hhfz/oKoieD0C/At3FC0pDrSApaD6GPA1niSRdvpJfN07VxxtnWOhgeIbWqrmWX2Jq6n CmIoPKz3e08VhQ0GbzAvNVFcivPrxUkd5UtvekmvuNR2EyzJfPJB0MXQ0a2DxqE8+SdF vhiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JXs8VltE; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-46509-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCW/rr+O5H180QyqeYQUkriPr8v9+sUqVYm7idUCE1unI2FMLK7NQMrOsH4eVt3nvpRW9m6r0tiBaMTjWhu5aakffizmZ1pu9QM8rkGdFg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u6-20020a170902e80600b001d92215f363si2307007plg.438.2024.01.31.06.08.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 06:08:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46509-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JXs8VltE; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-46509-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A851BB2A6D0 for ; Wed, 31 Jan 2024 13:38:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C592C80C06; Wed, 31 Jan 2024 13:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JXs8VltE" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8A8A7FBBC for ; Wed, 31 Jan 2024 13:38:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706708296; cv=none; b=KyQ+hVtszDdawFhCHMD61NoVoVpQMEAETQr7vTx59eDLvCSxaz/vrAAW67G9tY7RCPSZocaGqs0URP6Jt7G12xe7kY94WBXO+FzHAulkQjM6uWdLwirgBjAjGORxF/EU4237ajzzaWEFPf5Swc5Boa1sKJH5Tpn4USMw/jA5Mo4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706708296; c=relaxed/simple; bh=EP/VOkvRrFbuplhNL+kIPj0fhAj0V0gvW1a0Gsl/Y28=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Pnc2TvvnIKTfRm1npCiG0fsM+sziHfLj0mwwi9qxz1wlAIlgtByMY+bGjmRWJC3gUTgjV4xNvJEWOjN+os4Goxb5Qckb/cFulpc/r7dWK5xgHVgf+ZL0Izosa5bBmft74MHFMXMo1KcDjwNHKLG/EgB2g2hkt3nTW3xkjPa4Yk8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JXs8VltE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706708293; h=from:from: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:autocrypt:autocrypt; bh=vNnp/Z0S7DqUPASGq4M26R4kayT9Cyd518Jol1/4wN4=; b=JXs8VltEDDI38sWcW2ltl865d9+Jd80OQC1ZXQvy8COslFEkJsgp0wtzQWYgDVcelPXK9Q O+/DnxUbiRD4x6z1hLvnc/9O/FIulnjUeYFIwuFOHWYhNo58qtSg/stBje48/87FOQ5LOh mBjZiypSLtq7yX6nlZWEazCnrBecHVo= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-OPhQpnqqN3yRmhK5GPpB6Q-1; Wed, 31 Jan 2024 08:38:12 -0500 X-MC-Unique: OPhQpnqqN3yRmhK5GPpB6Q-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40fb64f802dso1590475e9.1 for ; Wed, 31 Jan 2024 05:38:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706708291; x=1707313091; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vNnp/Z0S7DqUPASGq4M26R4kayT9Cyd518Jol1/4wN4=; b=Q7s64H0FN+WzO20OfD33qjxgHC5fENjuy6Z3DGlVE+Sa52S7CuTs2GcJxdZnqE4lE7 BedxNKmN0QTiIV6PThTg03/sIXe4o6qqftu8F38HBFgnYAEB5qF670x5yIDL8E9bDbcV uZY31YHWdsWAjH7uh0sKc5KKyWBjwdHglehvqXduXPqfwN7sRA5phOqvJWD1bKDlPSC3 hFKyJCuENErkY1p5wlCW8V3u7nQzTBrJboNeS3KrzcyANPL31DARCONvIVcow6vByFkj U4eGXQSVO0OaE/mWiaOoN+OajeEoNRYVCYlkDGEAcYPAO4YJtEF7pjUuHoUD8fvHYCau YAmw== X-Gm-Message-State: AOJu0YxvDtzpxFmV/oZRUAiggCapcoySaYI3Nm0LhmR/4UqppjtDCkt7 J0xAw9zGcW21gLSVRI80SOgKK/eLKBl6ZrCBz/SCb+UQ0c8vvySCBIahz56zg3VOtWLdOYw8y0Y 6RSLLeZf5CMdd7IFlNxRPMkxJ7sdnAZ4iueXZc1jfoZNdvseJjat4KcgfzOJ7qg== X-Received: by 2002:a05:600c:6551:b0:40e:b93e:4a0f with SMTP id dn17-20020a05600c655100b0040eb93e4a0fmr1406584wmb.19.1706708291169; Wed, 31 Jan 2024 05:38:11 -0800 (PST) X-Received: by 2002:a05:600c:6551:b0:40e:b93e:4a0f with SMTP id dn17-20020a05600c655100b0040eb93e4a0fmr1406543wmb.19.1706708290739; Wed, 31 Jan 2024 05:38:10 -0800 (PST) Received: from [10.32.64.237] (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id h9-20020a05600016c900b0033aedb71269sm8183465wrf.88.2024.01.31.05.38.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jan 2024 05:38:10 -0800 (PST) Message-ID: Date: Wed, 31 Jan 2024 14:38:09 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 00/15] mm/memory: optimize fork() with PTE-mapped THP Content-Language: en-US To: Ryan Roberts , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org References: <20240129124649.189745-1-david@redhat.com> <57eb82c7-4816-42a2-b5ab-cc221e289b21@arm.com> <714d0930-2202-48b6-9728-d248f820325e@arm.com> <30718fc8-15cf-41e4-922c-5cdbf00a0840@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91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x2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit >>> Nope: looks the same. I've taken my test harness out of the picture and done >>> everything manually from the ground up, with the old tests and the new. Headline >>> is that I see similar numbers from both. >> >> I took me a while to get really reproducible numbers on Intel. Most importantly: >> * Set a fixed CPU frequency, disabling any boost and avoiding any >>   thermal throttling. >> * Pin the test to CPUs and set a nice level. > > I'm already pinning the test to cpu 0. But for M2, at least, I'm running in a VM > on top of macos, and I don't have a mechanism to pin the QEMU threads to the > physical CPUs. Anyway, I don't think these are problems because for a given > kernel build I can accurately repro numbers. Oh, you do have a layer of virtualization in there. I *suspect* that might amplify some odd things regarding code layout, caching effects, etc. I guess especially the fork() benchmark is too sensible (fast) for things like that, so I would just focus on bare metal results where you can control the environment completely. Note that regarding NUMA effects, I mean when some memory access within the same socket is faster/slower even with only a single node. On AMD EPYC that's possible, depending on which core you are running and on which memory controller the memory you want to access is located. If both are in different quadrants IIUC, the access latency will be different. >> But yes: I was observing something similar on AMD EPYC, where you get >> consecutive pages from the buddy, but once you allocate from the PCP it might no >> longer be consecutive. >> >>>   - test is 5-10% slower when output is printed to terminal vs when redirected to >>>     file. I've always effectively been redirecting. Not sure if this overhead >>>     could start to dominate the regression and that's why you don't see it? >> >> That's weird, because we don't print while measuring? Anyhow, 5/10% variance on >> some system is not the end of the world. > > I imagine its cache effects? More work to do to print the output could be > evicting some code that's in the benchmark path? Maybe. Do you also see these oddities on the bare metal system? > >> >>> >>> I'm inclined to run this test for the last N kernel releases and if the number >>> moves around significantly, conclude that these tests don't really matter. >>> Otherwise its an exercise in randomly refactoring code until it works well, but >>> that's just overfitting to the compiler and hw. What do you think? >> >> Personally, I wouldn't lose sleep if you see weird, unexplainable behavior on >> some system (not even architecture!). Trying to optimize for that would indeed >> be random refactorings. >> >> But I would not be so fast to say that "these tests don't really matter" and >> then go wild and degrade them as much as you want. There are use cases that care >> about fork performance especially with order-0 pages -- such as Redis. > > Indeed. But also remember that my fork baseline time is ~2.5ms, and I think you > said yours was 14ms :) Yes, no idea why M2 is that fast (BTW, which page size? 4k or 16k? ) :) > > I'll continue to mess around with it until the end of the day. But I'm not > making any headway, then I'll change tack; I'll just measure the performance of > my contpte changes using your fork/zap stuff as the baseline and post based on that. You should likely not focus on M2 results. Just pick a representative bare metal machine where you get consistent, explainable results. Nothing in the code is fine-tuned for a particular architecture so far, only order-0 handling is kept separate. BTW: I see the exact same speedups for dontneed that I see for munmap. For example, for order-9, it goes from 0.023412s -> 0.009785, so -58%. So I'm curious why you see a speedup for munmap but not for dontneed. -- Cheers, David / dhildenb