Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2404899rwi; Fri, 28 Oct 2022 06:47:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5EYA0vSBmTm/A5KFMoLFqxrL4nRgbF1d056OLV9b03MjkA//J541wRPfeEZlHD5V3KKABv X-Received: by 2002:a05:6402:35d6:b0:45d:a52f:2d30 with SMTP id z22-20020a05640235d600b0045da52f2d30mr49657693edc.4.1666964822348; Fri, 28 Oct 2022 06:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666964822; cv=none; d=google.com; s=arc-20160816; b=ICWdb7kL69DfLmP6QRJ3Z4edK8vjQHVYhBHheMWFR0qYOFhFxOagPPCEkiJQf0eZqk xlGOjIIsBvS5qYUpx+wvUfiYy933AlNVg2m4U2cyEr6b9oms/OhD+JVft8XN1zFH9xFY U/Zps1aBpRuFXb3S4oZSdZffWbrtEVHKLSBF6q0M1yHQjUv2Nr4SgxuwLHHzIhRy/8Za v4W0C5KQLvtBIsi5N0uk8GhnrAcNYDEwYTCkP/3IpYVQCMiJdhb/TdLFUmjq7HVF8sCM Q2O5VMzU4nSOl/G/3pNrg5N/+Ll61bzxGq4ob58GahBDctSi+PmjPg+e/MOPKM9zaH/H jY8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=o3XkdRF1alR2hBxhKv7+KC2xEVL/mNE1pCUslh91CNk=; b=oyC6nhkj678CrH1jzNu/+DDZymHBlOYypgpXn/VK2ZpzW431XHu341vSf0y0lTsAfy awhE0lsMo2asv6EyXCkSjZ3vtArnGdEZcY66gSDOpAoUMu6CWDLqTDiXwS+0kur+bWUI vBtYJq+5OGb0pib9mshlI6q/lmcezTV/pyB0ZLBbJsvYi77AWpW+o4stojogK/ddCPgV iVa1tOE7NRKo3qvcd2fwUkicl1++13stJBxPQZgo1tJQjRfZASpnWqvyhdDabiFUL46q FXhNxqfKrQgzqu4PuJwjVGGGKWj+X2Y4ixSoctpBZCJHknDXC8rDoZLuGLOxVVO/T8FL vfKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=czSDanOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa25-20020a1709076d1900b007aa784a3cb8si4865324ejc.687.2022.10.28.06.46.37; Fri, 28 Oct 2022 06:47:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=czSDanOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230336AbiJ1NM4 (ORCPT + 99 others); Fri, 28 Oct 2022 09:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbiJ1NMz (ORCPT ); Fri, 28 Oct 2022 09:12:55 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8853D1C7D69 for ; Fri, 28 Oct 2022 06:12:52 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id bk15so6511323wrb.13 for ; Fri, 28 Oct 2022 06:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=o3XkdRF1alR2hBxhKv7+KC2xEVL/mNE1pCUslh91CNk=; b=czSDanOWkaznNFvfzkhI+RldJ79y0lOKTXLazE2INVObzdIpuA02fnxmTp4HXTRQTi IvuTylcXIq/Sg1jCgh9FzcPYK6wCnCgisN2SPpD2hY2iM3U6UJQJMLePIaRYzRfU+2Wh y9qb6oEWb7kSxsaXWIlY4Dkr2UM2TLk7qXYPH5mBMLvwd3vtyLYpmiqZDG3Zxj0+CARd L8/aJqqA6LprQ5Pk4/015K7SAUBuZTJBf3EKbWQG93N7hmK53CJDPw0U9whLdkPu5vWz 3ELADVGMWSrtaYcGW48cTX8dbadiAO+awqSfgOoWpeoUTHQ8/pHHrLwFT/4AdLUkI1S8 O7bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=o3XkdRF1alR2hBxhKv7+KC2xEVL/mNE1pCUslh91CNk=; b=dVLMmLpqtVqSoq1miHIkuhNpzl+nK0iRtPDyJ1x6cRPrHS26xkWzdLHOeq/fQSU6MA ckVIyckywGJdlDy3Bt0p0/UlxtyXo1D1MY5NPGpHPMtdmWOKWjz4T49nXJ3PbJEs9QDX zl4qwZvFsptyOwMtdzfwSJ0QjhUkPPnLDZwMeQ7ZPH9JXzY3TFqD8G4zJfyfKihFqmfD whETPv/PoMj+7SJLpTwnNtJ7+5CQuMbt28/W2qOGQBcvzbrWyHVC9ULR5TWPe5WyRcqG 0R3hDaonnUfy4teD3fQjZ+dDCsDMo3vlye6Ob7mdQs2kjD8zB/6bepOn4fXUeZw+Q1sN h+Vw== X-Gm-Message-State: ACrzQf2TYO/fX5U0iHJon1SwgalZ8XOeAX2LbO/llcsxpbMWmJoGlSWy O/dcErdsfVNR70P+Rw4WGNJ4Bw== X-Received: by 2002:a05:6000:18c7:b0:22e:5503:9c46 with SMTP id w7-20020a05600018c700b0022e55039c46mr33561930wrq.668.1666962771104; Fri, 28 Oct 2022 06:12:51 -0700 (PDT) Received: from localhost ([95.148.15.66]) by smtp.gmail.com with ESMTPSA id n17-20020a05600c501100b003b4fdbb6319sm5926108wmr.21.2022.10.28.06.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 06:12:50 -0700 (PDT) From: Punit Agrawal To: Anshuman Khandual Cc: Barry Song <21cnbao@gmail.com>, Punit Agrawal , Yicong Yang , yangyicong@hisilicon.com, corbet@lwn.net, peterz@infradead.org, arnd@arndb.de, linux-kernel@vger.kernel.org, darren@os.amperecomputing.com, huzhanyuan@oppo.com, lipeifeng@oppo.com, zhangshiming@oppo.com, guojian@oppo.com, realmz6@gmail.com, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-mm@kvack.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, wangkefeng.wang@huawei.com, xhao@linux.alibaba.com, prime.zeng@hisilicon.com, Barry Song , Nadav Amit , Mel Gorman , catalin.marinas@arm.com, will@kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v4 2/2] arm64: support batched/deferred tlb shootdown during page reclamation References: <20220921084302.43631-1-yangyicong@huawei.com> <20220921084302.43631-3-yangyicong@huawei.com> <168eac93-a6ee-0b2e-12bb-4222eff24561@arm.com> <8e391962-4e3a-5a56-64b4-78e8637e3b8c@huawei.com> <87o7tx5oyx.fsf@stealth> <8a3ade4c-1714-5ffd-ed57-02ab0509725b@arm.com> Date: Fri, 28 Oct 2022 14:12:49 +0100 In-Reply-To: <8a3ade4c-1714-5ffd-ed57-02ab0509725b@arm.com> (Anshuman Khandual's message of "Fri, 28 Oct 2022 07:44:29 +0530") Message-ID: <877d0k5bxq.fsf@stealth> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Anshuman Khandual writes: > On 10/28/22 03:25, Barry Song wrote: >> On Fri, Oct 28, 2022 at 3:19 AM Punit Agrawal >> wrote: >>> >>> [ Apologies for chiming in late in the conversation ] >>> >>> Anshuman Khandual writes: >>> >>>> On 9/28/22 05:53, Barry Song wrote: >>>>> On Tue, Sep 27, 2022 at 10:15 PM Yicong Yang wrote: >>>>>> On 2022/9/27 14:16, Anshuman Khandual wrote: >>>>>>> [...] >>>>>>> >>>>>>> On 9/21/22 14:13, Yicong Yang wrote: >>>>>>>> +static inline bool arch_tlbbatch_should_defer(struct mm_struct *mm) >>>>>>>> +{ >>>>>>>> + /* for small systems with small number of CPUs, TLB shootdown is cheap */ >>>>>>>> + if (num_online_cpus() <= 4) >>>>>>> It would be great to have some more inputs from others, whether 4 (which should >>>>>>> to be codified into a macro e.g ARM64_NR_CPU_DEFERRED_TLB, or something similar) >>>>>>> is optimal for an wide range of arm64 platforms. >>>>>>> >>>>> I have tested it on a 4-cpus and 8-cpus machine. but i have no machine >>>>> with 5,6,7 >>>>> cores. >>>>> I saw improvement on 8-cpus machines and I found 4-cpus machines don't need >>>>> this patch. >>>>> >>>>> so it seems safe to have >>>>> if (num_online_cpus() < 8) >>>>> >>>>>> Do you prefer this macro to be static or make it configurable through kconfig then >>>>>> different platforms can make choice based on their own situations? It maybe hard to >>>>>> test on all the arm64 platforms. >>>>> Maybe we can have this default enabled on machines with 8 and more cpus and >>>>> provide a tlbflush_batched = on or off to allow users enable or >>>>> disable it according >>>>> to their hardware and products. Similar example: rodata=on or off. >>>> No, sounds bit excessive. Kernel command line options should not be added >>>> for every possible run time switch options. >>>> >>>>> Hi Anshuman, Will, Catalin, Andrew, >>>>> what do you think about this approach? >>>>> >>>>> BTW, haoxin mentioned another important user scenarios for tlb bach on arm64: >>>>> https://lore.kernel.org/lkml/393d6318-aa38-01ed-6ad8-f9eac89bf0fc@linux.alibaba.com/ >>>>> >>>>> I do believe we need it based on the expensive cost of tlb shootdown in arm64 >>>>> even by hardware broadcast. >>>> Alright, for now could we enable ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH selectively >>>> with CONFIG_EXPERT and for num_online_cpus() > 8 ? >>> When running the test program in the commit in a VM, I saw benefits from >>> the patches at all sizes from 2, 4, 8, 32 vcpus. On the test machine, >>> ptep_clear_flush() went from ~1% in the unpatched version to not showing >>> up. >>> >>> Yicong mentioned that he didn't see any benefit for <= 4 CPUs but is >>> there any overhead? I am wondering what are the downsides of enabling >>> the config by default. >> As we are deferring tlb flush, but sometimes while we are modifying the vma >> which are deferred, we need to do a sync by flush_tlb_batched_pending() in >> mprotect() , madvise() to make sure they can see the flushed result. if nobody >> is doing mprotect(), madvise() etc in the deferred period, the overhead is zero. > > Right, it is difficult to justify this overhead for smaller systems, > which for sure would not benefit from this batched TLB framework. Thank you for the pointers to the overhead. Having looked at this more closely, I also see that flush_tlb_batched_pending() discards the entire mm vs just flushing the page being unmapped (as is done with ptep_clear_flush()).