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 E3A6AC77B7A for ; Fri, 19 May 2023 17:03:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ECAA280001; Fri, 19 May 2023 13:03:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09CD6900003; Fri, 19 May 2023 13:03:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA70B280001; Fri, 19 May 2023 13:03:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D6C60900003 for ; Fri, 19 May 2023 13:03:23 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6ADD4140520 for ; Fri, 19 May 2023 17:03:23 +0000 (UTC) X-FDA: 80807625486.05.7C9FAF8 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf29.hostedemail.com (Postfix) with ESMTP id 9EBA512012A for ; Fri, 19 May 2023 17:02:54 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=fIlCc7Km; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684515774; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/5gWWnU6rWDEqQdM4br3GFqSxtcuOPR/FtdJtjJJ2uw=; b=xaCzrdE++P892NK1hy+k1NN2rpPX/53MNRhwhbEWcQYpEby6kZ8dt+gtJzQyr/djQKRjwU K01EOyjJZrEDSVo8SUzb/00/4uJKTdy2g+iVrDHlPu++YOn4g7MFCOvU4X/i5N/cwZS4ZS F5PzDKwQUbI06V+SW0rg/BJND0R6VyA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=fIlCc7Km; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684515774; a=rsa-sha256; cv=none; b=a4h9C55oA8KMHtIQ7cAtuBW/R0gYfoOo2TXLeYE1gk+t9qyqSLZ7ZvaMu6c2aU6slMNeX4 HlF2CVuoCNdkBJbY20vMrUbY/PV+slyraLdSe09RDICDtDiNcfhpmxryVzh0Dj30dlAgJ2 DAiiS4iTDwhoxauImvo+evrm4qjXx5A= Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-4f27b65bbf9so3942309e87.0 for ; Fri, 19 May 2023 10:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684515773; x=1687107773; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=/5gWWnU6rWDEqQdM4br3GFqSxtcuOPR/FtdJtjJJ2uw=; b=fIlCc7KmT73/bJUnVx2lsl8//G9pquk/8PdZb0Sz4NHUvUgszaGaH/tjP8dLMcPkWd xCWMPPKlOfLcWtKnzi7XTn7MxgbQSneHrhmLePusAIoaoLyqxQq4dbLOuLLJt5HwoEWR jzQRmUUOhKrXUkIwlOoVl7sMqpWvo5yzgfHDRY3NbHGHy+WQCtDHdhgF5BOVpDrnzaET CAqx5s/ocslqk6xOLERLI3BHDijySgJvGBlb30tFLT8ZcYV7cUT5GcTBolNjIKctbgKr BrR6qU1oHl0issmXHvq7xJspCzeLA2IsgQMjOYFQPqUs9rD3ExwvjgWy3QlZze8h5DDB S4PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515773; x=1687107773; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/5gWWnU6rWDEqQdM4br3GFqSxtcuOPR/FtdJtjJJ2uw=; b=RjxeOF3bog6+YcyfNiYBrNJ8HmEj9iNduT2f3VEDgZq94qv1nD6JA6Du09jxEKFEAx 20g1CbuT9MKh+ROWjnVEdPR+s4E6fRrwbrmC5iS3+tHkY2OfdZ9h/ZFNjKDgsxcq/UwU f7lffKo3e35UR+yb/z0DCzNk2A7cCpspqtZeYCrBVTGuf0+rZD191Q37ULEud0zdxNqG NDJWB9lo2ZlwiP1zPvibi5avvXRVmME9UDeNVE45T/r8deRORt5AgTpvUk++4t9D59xg ifvbcd9Rvjeilu507acQYJTmnbQOcsh+eZTi6ZbEWcKZXu215ToZGyuo+qz2odpBR/f9 wT0w== X-Gm-Message-State: AC+VfDwDpM9wYpzClbVOYpMzVa6gSq7R0kUAyQwd/GPCQdDg/a/nxh6f X2cC0hoycJhuwr4ooD4P10M= X-Google-Smtp-Source: ACHHUZ4xNNENafdqB6Nyo0fUbPbeRaAC5IKI7JtUd1m6Vn1vf5HZVFWpWnc1BLK7tODJ66j4zbGtbQ== X-Received: by 2002:ac2:511a:0:b0:4ec:844e:7b85 with SMTP id q26-20020ac2511a000000b004ec844e7b85mr1101667lfb.25.1684515772481; Fri, 19 May 2023 10:02:52 -0700 (PDT) Received: from pc636 (host-90-235-19-70.mobileonline.telia.com. [90.235.19.70]) by smtp.gmail.com with ESMTPSA id f5-20020ac251a5000000b004f2532cfbc1sm660938lfk.81.2023.05.19.10.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:02:52 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Fri, 19 May 2023 19:02:49 +0200 To: Thomas Gleixner Cc: Uladzislau Rezki , "Russell King (Oracle)" , Andrew Morton , linux-mm@kvack.org, Christoph Hellwig , Lorenzo Stoakes , Peter Zijlstra , Baoquan He , John Ogness , linux-arm-kernel@lists.infradead.org, Mark Rutland , Marc Zyngier , x86@kernel.org, Nadav Amit Subject: Re: Excessive TLB flush ranges Message-ID: References: <87leho6wd9.ffs@tglx> <87o7mj5fuz.ffs@tglx> <87edne6hra.ffs@tglx> <87lehk4bey.ffs@tglx> <87fs7s46z9.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87fs7s46z9.ffs@tglx> X-Rspamd-Queue-Id: 9EBA512012A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jhfxnbtiydoc37mjpf5fmntinqasyxty X-HE-Tag: 1684515774-618287 X-HE-Meta: U2FsdGVkX18tTqoa8UsIf9sQU1W1sRdUUy3ikKjm8eKtABlVuh0/veZ38ku7k73rLMCW1pAmaluHLQKNWVYGg79O6Hzuot90mgEWXh2WEQpU82d/MUMzKVcrxzShhoCMU9gJm6mTjrQuvmHuPyQhEswlKGDf9ZPUKV2jRkjsL5hTOFLn+f9CPZ9b02pwkIwxzg14hJ8L8H0e9DbwpW/B9BVsfChZvmzNvWtmuJ5j+3xqgb88Vrpdckpq1MVgE+SgOMDFCtM47bMfx9mt3QJHjJwuGFgsFim8xGtSjfCwuBU/WljprfXX+h6Eco3bk1/azEwQuSPhbsBYYwNnJiHg4ygnS4ndrTUYfnWUB+KPvCsGxI6+6vrJqDbHhkggW0aOmB33B7bMKMMzEe7ZDtuW4coXtD8MSXN1q2LJXWpl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-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 Fri, May 19, 2023 at 06:32:42PM +0200, Thomas Gleixner wrote: > On Fri, May 19 2023 at 17:14, Uladzislau Rezki wrote: > > On Fri, May 19, 2023 at 04:56:53PM +0200, Thomas Gleixner wrote: > >> > + /* Flush per-VA. */ > >> > + list_for_each_entry(va, &local_purge_list, list) > >> > + flush_tlb_kernel_range(va->va_start, va->va_end); > >> > > >> > - flush_tlb_kernel_range(start, end); > >> > resched_threshold = lazy_max_pages() << 1; > >> > >> That's completely wrong, really. > >> > > Absolutely. That is why we do not flush a range per-VA ;-) I provided the > > data just to show what happens if we do it! > > Seriously, you think you need to demonstrate that to me? Did you > actually read what I wrote? > > "I understand why you want to batch and coalesce and rather do a rare > full tlb flush than sending gazillions of IPIs." > Yes i read it. Since i also mentioned about IPI and did not provide any data, i did it later, just in case. I shared my observation and that is it. > > A per-VA flushing works when a system is not capable of doing a full > > flush, so it has to do it page by page. In this scenario we should > > bypass ranges(not mapped) which are between VAs in a purge-list. > > ARM32 has a full flush as does x86. Just ARM32 does not have a cutoff > for a full flush in flush_tlb_kernel_range(). That's easily fixable, but > the underlying problem remains. > > The point is that coalescing the VA ranges blindly is also fundamentally > wrong: > > > start1 = 0x95c8d000 end1 = 0x95c8e000 > start2 = 0xf08a1000 end2 = 0xf08a5000 > > --> start = 0x95c8d000 end = 0xf08a5000 > > So this ends up with: > > if (end - start > flush_all_threshold) > ipi_flush_all(); > else > ipi_flush_range(); > > So with the above example this ends up with flush_all(), but a > flush_vas() as I demonstrated with the list approach (ignore the storage > problem which is fixable) this results in > > if (total_nr_pages > flush_all_threshold) > ipi_flush_all(); > else > ipi_flush_vas(); > > and that ipi flushes 3 pages instead of taking out the whole TLB, which > results in a 1% gain on that machine. Not massive, but still. > > The blind coalescing is also wrong if the resulting range is not giantic > but below the flush_all_threshold. Lets assume a threshold of 32 pages. > > start1 = 0xf0800000 end1 = 0xf0802000 2 pages > start2 = 0xf081e000 end2 = 0xf0820000 2 pages > > --> start = 0xf0800000 end = 0xf0820000 > > So because this does not qualify for a full flush and it should not, > this ends up flushing 32 pages one by one instead of flushing exactly > four. > > IOW, the existing code is fully biased towards full flushes which is > wrong. > > Just because this does not show up in your performance numbers on some > enterprise workload does not make it more correct. > Usually we do a flush of lazy-areas once the lazy_max_pages() threshold is reached. There are exceptions. When an allocation fails, we drain the areas(if there are any), second is a per-cpu allocator and last one is vm_reset_perms() when "vm" is marked as VM_FLUSH_RESET_PERMS. As for your description i totally see the problem. -- Uladzislau Rezki