From patchwork Thu May 25 12:57:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 13255207 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 97B30C77B7E for ; Thu, 25 May 2023 12:57:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD7F3280001; Thu, 25 May 2023 08:57:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC371900005; Thu, 25 May 2023 08:57:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C49B280001; Thu, 25 May 2023 08:57:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7C09C900005 for ; Thu, 25 May 2023 08:57:09 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 584BA80AB8 for ; Thu, 25 May 2023 12:57:09 +0000 (UTC) X-FDA: 80828777778.03.DEF723F Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 85B9B14001F for ; Thu, 25 May 2023 12:57:07 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=rlO2m6VM; dkim=pass header.d=linutronix.de header.s=2020e header.b="/ufsKLoB"; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf26.hostedemail.com: domain of tglx@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=tglx@linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685019427; 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: references:references:dkim-signature; bh=T9X04eIuoMWJVvm2fkVnAhHMuhnbMVSYQ3LmFepsGxw=; b=WtV1VGmcmPHFLYG4vvR9ozokIHWaT3XD5CHhIKfkOwXnNFvApj6NMNYwC2yOca5uNs77pJ SJHMwwkETaB9PhFlorL7GZXbC6oKYtlVCIYpRKyHEl9yxFRZD2CO4JyHOcoTJV61sDrZVI 6yGJVpBEv+K+QWoxtedFF7Xlz9ECvd8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=rlO2m6VM; dkim=pass header.d=linutronix.de header.s=2020e header.b="/ufsKLoB"; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf26.hostedemail.com: domain of tglx@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=tglx@linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685019427; a=rsa-sha256; cv=none; b=1lDDGnysC6JKmhtqVDiEyZgTLBZ7C9tME2UJAWJ2YuQMQta9Gn3nIRDJ6S6b4mvpYb7fI1 eji94fYr3ObSOnvpz8OIgcGTuAj/bt0o8Ugc7s0o03OanJ3PwAneTXvX0yl/0I2rKNd7me 9/EdX9EeFSu9iRP64Q4nTkpbRQa8jdQ= Message-ID: <20230525124504.692056496@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685019426; 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: references:references; bh=T9X04eIuoMWJVvm2fkVnAhHMuhnbMVSYQ3LmFepsGxw=; b=rlO2m6VM6GQ0LI379hJTVFYgZzzQdDZ7VzV5EGpvjClhuEUnBCt2aKPM5nzvWOXkjtzjbu 5AOegWNPAgH7GTKccUr74Se/7m/NRQMiDmtWQYxSCITL2tmSNy8nYJ/UuHmOww72/v7mAl TeeluOsUzmPo53RBGKbKlFdTJH7ll1nbNAGeWz7Q0BeSEtVZ0Xn/lpeLxO+SJK93mRgDZW 0rxdmUBqy2DDl2dDlTUwCyPA/tu4HaJf8q/QC42lBqtYnzHIwoerfceVN6OdAoWac5+5zT 7s/6D7x6x4BdjWk041ja3VoqBMTjzrEyN/sik0uh4PF8GWmMNNt8J1u7ZTbTZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685019426; 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: references:references; bh=T9X04eIuoMWJVvm2fkVnAhHMuhnbMVSYQ3LmFepsGxw=; b=/ufsKLoBHId/Ag0HD+JC4AbWAwwhTHkkoacO9h9MiCzx10bPuQq7NTrSITwcFIhP3iV3gC 6CkBGss0psOEQwDg== From: Thomas Gleixner To: linux-mm@kvack.org Cc: Andrew Morton , Christoph Hellwig , Uladzislau Rezki , Lorenzo Stoakes , Peter Zijlstra , Baoquan He Subject: [V2 patch 3/6] mm/vmalloc: Prevent flushing dirty space over and over References: <20230525122342.109672430@linutronix.de> MIME-Version: 1.0 Date: Thu, 25 May 2023 14:57:05 +0200 (CEST) X-Rspamd-Queue-Id: 85B9B14001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 7uq6ydhmpshkhyx1yj6ftegjoyq4iqmu X-HE-Tag: 1685019427-746783 X-HE-Meta: U2FsdGVkX1/4HECkvuuuIjmqcNMc8MjnhZoxhPSHxTe0mVEthu8ODNzNeqj/Dpcm8V7yHIIHXCnRHy81nYoOKd2XQ9mqmziHslbmM9SuimgVcvkl6yiSPrULeULwHPTeobWYEE5EY9gNjIfMjbV6yoAlnJ2kg2z9VTOSbQOSP18WvdCSYwPP8YStLy1PNYP1yw9US3WBelsWw/rPxQ4DSZz7S0+yMJEHAG86hwBvY3WiSxbRcR6Bnv4DPa9ogaHgD+x6bgC8Qrx1j80G82qXP9JLWlIHfMiCXyRm5/lfCUpxs8QZXJJ/gnAPfphe9jr1KrKk2gOKZd8R1tVAX+FiZ5Ustc2yJxwhR9PG5i/O527X5cSRv9emac7TtXG9pniWEhjr/2D6McKg8Z5ApJcpytfPnRG1Ksrsl2McPpcZPZMqmwF+Xmeunfwoiazbzr8aJyzRssuWS4+kZcPeKqEweiOhDrUoVvSreiWw6LSoQr/ncSU1jEiQsetYuo5D20ViUk8/YO493A7cgfYV70uMopHPvfpFZg0ew3VVkiecf4O1AElC0EYv/Q7PDu9l8dA0SY6JEWPanG3qF+4b1/FZYsMxejOS0PA4TSvt/BktfNK1vRWIGYto2gRbypA56IHW9XEcFx3i/bueZcB1IwwGrAX2PfoaHTK9di8g8YF+XYDpAC9jeqmamTpQmHADS7W3S4xzh3/D8G1o6+FAcGsoccWzd8EgdrksTpIzYHVY8zdcqFmF5uYt0nq5ft6LnXek3UaBZgKUYyNLxmWOMvnZ+KWWWcqQ7pGcmLDfXPOtlcE7Ssu5eIRvnazS+/Q9Czj+ImrnRgRgUgOhNyQ/q7+wLxQULS/SY+KQ0tksnH+Wy/IEwa/CS/Koyf8kFPCNNgfjMVPFqEhvh1Fg3eC8lCQnmTed/TDprop+CQERajv/bYjDPm1J4nmCxv9ne0ZzOadmMzCGBdDaVcHzaBBTCGV uajsmIZG z4bWpEzMbkR2NV1K+3+hdQIofY9tzdIfnCQFOqdCZDLWBWtt/I7aiC1e+XMJjTGWKOK+XxUQhL+DAR6h7CglV3/AHLIz2ixBhmFTBLC0DX3XVCCknMOQrrNopPw== 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: vmap blocks which have active mappings cannot be purged. Allocations which have been freed are accounted for in vmap_block::dirty_min/max, so that they can be detected in _vm_unmap_aliases() as potentially stale TLBs. If there are several invocations of _vm_unmap_aliases() then each of them will flush the dirty range. That's pointless and just increases the probability of full TLB flushes. Avoid that by resetting the flush range after accounting for it. That's safe versus other invocations of _vm_unmap_aliases() because this is all serialized with vmap_purge_lock. Signed-off-by: Thomas Gleixner Reviewed-by: Baoquan He Reviewed-by: Christoph Hellwig Reviewed-by: Lorenzo Stoakes --- mm/vmalloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2226,7 +2226,7 @@ static void vb_free(unsigned long addr, spin_lock(&vb->lock); - /* Expand dirty range */ + /* Expand the not yet TLB flushed dirty range */ vb->dirty_min = min(vb->dirty_min, offset); vb->dirty_max = max(vb->dirty_max, offset + (1UL << order)); @@ -2264,7 +2264,7 @@ static void _vm_unmap_aliases(unsigned l * space to be flushed. */ if (!purge_fragmented_block(vb, vbq, &purge_list) && - vb->dirty && vb->dirty != VMAP_BBMAP_BITS) { + vb->dirty_max && vb->dirty != VMAP_BBMAP_BITS) { unsigned long va_start = vb->va->va_start; unsigned long s, e; @@ -2274,6 +2274,10 @@ static void _vm_unmap_aliases(unsigned l start = min(s, start); end = max(e, end); + /* Prevent that this is flushed again */ + vb->dirty_min = VMAP_BBMAP_BITS; + vb->dirty_max = 0; + flush = 1; } spin_unlock(&vb->lock);