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 X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D55D2C433DB for ; Sun, 31 Jan 2021 03:30:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4608364E09 for ; Sun, 31 Jan 2021 03:30:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4608364E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7F7916B0005; Sat, 30 Jan 2021 22:30:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A89A6B0006; Sat, 30 Jan 2021 22:30:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BD736B006C; Sat, 30 Jan 2021 22:30:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id 5735C6B0005 for ; Sat, 30 Jan 2021 22:30:54 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1A826180AD837 for ; Sun, 31 Jan 2021 03:30:54 +0000 (UTC) X-FDA: 77764643628.02.fog86_0103d33275b6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id EF62510097AA1 for ; Sun, 31 Jan 2021 03:30:53 +0000 (UTC) X-HE-Tag: fog86_0103d33275b6 X-Filterd-Recvd-Size: 6619 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Sun, 31 Jan 2021 03:30:53 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id g15so9621301pgu.9 for ; Sat, 30 Jan 2021 19:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :message-id:content-transfer-encoding; bh=WWtdonkpI96IFBE23zlui93VOmpriWeRuclQpLHiSrQ=; b=eSCoksJ1Yzv/0BafKpHiRRXPKnSIvcmu5C8r/mihPZT7sg4H85PPlglIDJW80h3clD fd4ivdugrzla49hkbsIq0/rdtSO+B6t0nc6sqXNZECMM4P/dcjvdqKwnLKxwRwZoisSe g4gxwXfE3hl2hwxq7/RE3gBz8t2xrU2wWagJLphFtVXBZZPYK5pLYj74Mw9vS8oM4pKU 6QYwv7XtIFq+X7sjnwKdzr75ZO1pp1ztyUUWwfOF5YJ7ZyntGlW+ujiU9AEN8+j3Zrdg j/nxnuRNVYt9tavAg8CtBw8/cQ3AL1zngp18EmiNiGAzmmpMHsfadM9qZ4NZVXJD4hTe mAQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=WWtdonkpI96IFBE23zlui93VOmpriWeRuclQpLHiSrQ=; b=MHAcujrhf4uox5xmuPi04RZJhvNTfJPKuhBwbkOqz+KnwiW5RaFFfENsBOWznDxILR 9YLOrPXImSnGvb+UPB3iYL7KYM9TK+iP4ql4jzID5E1NawYIP/hkbDhlJIAeTJcRcOat TxpcCi+oilLJ6HvW3lQ/436y27XMV2E8s4EXR1e+G/TGBtq1943imtU24h8BqQy+La7O Su359Jr8WAXNupJ97XWoiqmb0JJ7n5fgmD/dw2Y6oQQiPMq7U2nd6cNn/jQp8y5ep+DM 6/U6muRh0Ed1vuQftEcNC3r3YX35IgNxZahtf+BGCXOW+tqT5xKw70tPAm9XGsW70aPw 6unA== X-Gm-Message-State: AOAM530ZQQrK4Kq3T/M/luGnzUB6SMkT7qTlFZ8EUFVHcDvPZBSKisb8 ZQ38ab5x+bsHDvuCXE7wRMU= X-Google-Smtp-Source: ABdhPJwg/CC1nlE2QXUEo6aPv7AuExcknG2RvU7iKigAxQiaO+plz8rwLHQC/gO7heys0NGdqRr/GA== X-Received: by 2002:a63:5309:: with SMTP id h9mr11066861pgb.19.1612063852569; Sat, 30 Jan 2021 19:30:52 -0800 (PST) Received: from localhost (192.156.221.203.dial.dynamic.acc50-nort-cbr.comindico.com.au. [203.221.156.192]) by smtp.gmail.com with ESMTPSA id d14sm12961544pfo.156.2021.01.30.19.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jan 2021 19:30:52 -0800 (PST) Date: Sun, 31 Jan 2021 13:30:45 +1000 From: Nicholas Piggin Subject: Re: [RFC 00/20] TLB batching consolidation and enhancements To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Nadav Amit Cc: Andrea Arcangeli , Andrew Morton , Dave Hansen , linux-csky@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Andy Lutomirski , Mel Gorman , Nadav Amit , Peter Zijlstra , Thomas Gleixner , Will Deacon , x86@kernel.org, Yu Zhao References: <20210131001132.3368247-1-namit@vmware.com> In-Reply-To: <20210131001132.3368247-1-namit@vmware.com> MIME-Version: 1.0 Message-Id: <1612063149.2awdsvvmhj.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: Excerpts from Nadav Amit's message of January 31, 2021 10:11 am: > From: Nadav Amit >=20 > There are currently (at least?) 5 different TLB batching schemes in the > kernel: >=20 > 1. Using mmu_gather (e.g., zap_page_range()). >=20 > 2. Using {inc|dec}_tlb_flush_pending() to inform other threads on the > ongoing deferred TLB flush and flushing the entire range eventually > (e.g., change_protection_range()). >=20 > 3. arch_{enter|leave}_lazy_mmu_mode() for sparc and powerpc (and Xen?). >=20 > 4. Batching per-table flushes (move_ptes()). >=20 > 5. By setting a flag on that a deferred TLB flush operation takes place, > flushing when (try_to_unmap_one() on x86). >=20 > It seems that (1)-(4) can be consolidated. In addition, it seems that > (5) is racy. It also seems there can be many redundant TLB flushes, and > potentially TLB-shootdown storms, for instance during batched > reclamation (using try_to_unmap_one()) if at the same time mmu_gather > defers TLB flushes. >=20 > More aggressive TLB batching may be possible, but this patch-set does > not add such batching. The proposed changes would enable such batching > in a later time. >=20 > Admittedly, I do not understand how things are not broken today, which > frightens me to make further batching before getting things in order. > For instance, why is ok for zap_pte_range() to batch dirty-PTE flushes > for each page-table (but not in greater granularity). Can't > ClearPageDirty() be called before the flush, causing writes after > ClearPageDirty() and before the flush to be lost? Because it's holding the page table lock which stops page_mkclean from=20 cleaning the page. Or am I misunderstanding the question? I'll go through the patches a bit more closely when they all come=20 through. Sparc and powerpc of course need the arch lazy mode to get=20 per-page/pte information for operations that are not freeing pages,=20 which is what mmu gather is designed for. I wouldn't mind using a similar API so it's less of a black box when=20 reading generic code, but it might not quite fit the mmu gather API exactly (most of these paths don't want a full mmu_gather on stack). >=20 > This patch-set therefore performs the following changes: >=20 > 1. Change mprotect, task_mmu and mapping_dirty_helpers to use mmu_gather > instead of {inc|dec}_tlb_flush_pending(). >=20 > 2. Avoid TLB flushes if PTE permission is not demoted. >=20 > 3. Cleans up mmu_gather to be less arch-dependant. >=20 > 4. Uses mm's generations to track in finer granularity, either per-VMA > or per page-table, whether a pending mmu_gather operation is > outstanding. This should allow to avoid some TLB flushes when KSM or > memory reclamation takes place while another operation such as > munmap() or mprotect() is running. >=20 > 5. Changes try_to_unmap_one() flushing scheme, as the current seems > broken to track in a bitmap which CPUs have outstanding TLB flushes > instead of having a flag. Putting fixes first, and cleanups and independent patches (like #2) next would help with getting stuff merged and backported. Thanks, Nick