Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4451850rwl; Tue, 28 Mar 2023 07:12:14 -0700 (PDT) X-Google-Smtp-Source: AKy350aWdt3eOcPxRLnL9ZXY+gBtGRNogc68/jFCfcdAFKaAtfW4kIlDsCeDdsRjDOvPQnRvQlo5 X-Received: by 2002:aa7:d98d:0:b0:4fc:3f28:719c with SMTP id u13-20020aa7d98d000000b004fc3f28719cmr15193314eds.33.1680012734489; Tue, 28 Mar 2023 07:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680012734; cv=none; d=google.com; s=arc-20160816; b=cnATxcxb03MOELvtfs0D7pH/kNeSgRD5EEzI/YLEUSsvnmLG1e32vXlj+Z8sUCedBz lFcNfJGkqmf8FM4iTNzuTHzh278cxVMhNBAKR4I302ZJTv8rdtFw2X0qsI1rvMErSNX6 BuRMLU7J6P+Cj0VW51V+bkSRhxgCSiLfZtzndSeS5oZDPq9l2Gq3+lCNq9udBggg/wBV hZ2lyLNSvqu12Ofta45lwyEe6HjcHE1z6NlyTXpFLZgdf5Ms8L5Rw9eAJRpPRW5Ra68/ su3auFGefyX1DallL/9sdJrkpe2YkhgDaJDzBrf2YoK/CR73GYmWKlX7XfbzyOqeQ9Kq HtiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=aLm/CFUPQAqRWg08BXChMqEEgAO6D3vO51ZxoXvzUBw=; b=EjQs32Hp9fuTI7smG/nSiWRC1o+EyYpIvdgmxp2B/TkVqpgz3w6nX2zi9gKQvFGIIM mrk/6jplVzh6/JZWHZjvPFgXb5Y4P55mSBzxI9IOv91IwCEkj6yG2hpb8Nf3xU+XoqC+ qBDh6LP9FWxNdaSVpwltsLSZio4g3vs1N8NNYC12jMiyk3VPYDHKMzs98E0FHCHQqu5n O30FjBwQJBdDWjkKo5OEGw4kEfL9o6ojbnJxdAfYxTtBQDhg7pqjn1+ExbGmuccDKOIw 6B7fDX6hcfCrZiNpY33LaYyIrnSHUUUXnFvsQDr19aaC+uYLyou81QkmnMsyxUr6j6iS qcBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=oxokpOgz; 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=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k21-20020aa7c395000000b004fc687ac2a7si32784253edq.360.2023.03.28.07.11.46; Tue, 28 Mar 2023 07:12:14 -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=@tesarici.cz header.s=mail header.b=oxokpOgz; 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=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232648AbjC1OHS (ORCPT + 99 others); Tue, 28 Mar 2023 10:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbjC1OHQ (ORCPT ); Tue, 28 Mar 2023 10:07:16 -0400 X-Greylist: delayed 935 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 28 Mar 2023 07:06:01 PDT Received: from bee.tesarici.cz (bee.tesarici.cz [77.93.223.253]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DE7A19BC for ; Tue, 28 Mar 2023 07:06:00 -0700 (PDT) Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id D9432164B37; Tue, 28 Mar 2023 16:04:30 +0200 (CEST) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=none dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1680012271; bh=dLhHv/WzPGJpZ6GUidyDbJHkEOMAUN6OwnftRnlmPa8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=oxokpOgzIdS3rZkEtLatMm7RHGP1IN6GS5a/cZD6tpboCaE2gnDkxguu2AD4LLCd2 1UvcWl6Lw3jlx8176Y5MNYU75Zxo/LCeXqJfP5TJgmZ3klar4sIl70wUG3C6BKjfc6 hXAGiurLDmR8FGD9XvcAwkNMD+zYSz3rzLOsvS+cG0kP48WIzmBUm/Ga8UTemlDzcV kmGYDXPW5Kr/6KLhq21wu5VfCyEiVd1k/u+mUkGvgrVQZ/il6689eRtVKk4k0l27Gx gHcffZHwPlg7MG2h5VWjxdZvc4cz+ZdIoLBc5BGDIzr4Q77R5FSr3Tav+wQQvvUPaU xzR0BG75E3vZw== Date: Tue, 28 Mar 2023 16:04:29 +0200 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: "Michael Kelley (LINUX)" Cc: Christoph Hellwig , "hch@lst.de" , "m.szyprowski@samsung.com" , "robin.murphy@arm.com" , Dexuan Cui , Tianyu Lan , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2 1/1] swiotlb: Track and report io_tlb_used high water mark in debugfs Message-ID: <20230328160429.38f58623@meshulam.tesarici.cz> In-Reply-To: <20230328155017.5636393b@meshulam.tesarici.cz> References: <1679766790-24629-1-git-send-email-mikelley@microsoft.com> <20230328155017.5636393b@meshulam.tesarici.cz> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.35; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 On Tue, 28 Mar 2023 15:50:17 +0200 Petr Tesa=C5=99=C3=ADk wrote: > On Tue, 28 Mar 2023 13:12:13 +0000 > "Michael Kelley (LINUX)" wrote: >=20 > > From: Christoph Hellwig Sent: Monday, March 27, 202= 3 6:34 PM =20 > > >=20 > > > On Sat, Mar 25, 2023 at 10:53:10AM -0700, Michael Kelley wrote: =20 > > > > @@ -659,6 +663,14 @@ static int swiotlb_do_find_slots(struct device= *dev, int =20 > > > area_index, =20 > > > > area->index =3D wrap_area_index(mem, index + nslots); > > > > area->used +=3D nslots; > > > > spin_unlock_irqrestore(&area->lock, flags); > > > > + > > > > + new_used =3D atomic_long_add_return(nslots, &total_used); > > > > + old_hiwater =3D atomic_long_read(&used_hiwater); > > > > + do { > > > > + if (new_used <=3D old_hiwater) > > > > + break; > > > > + } while (!atomic_long_try_cmpxchg(&used_hiwater, &old_hiwater, ne= w_used)); > > > > + > > > > return slot_index; =20 > > >=20 > > > Hmm, so we're right in the swiotlb hot path here and add two new glob= al > > > atomics? =20 > >=20 > > It's only one global atomic, except when the high water mark needs to be > > bumped. That results in an initial transient of doing the second global > > atomic, but then it won't be done unless there's a spike in usage or the > > high water mark is manually reset to zero. Of course, there's a similar > > global atomic subtract when the slots are released. > >=20 > > Perhaps this accounting should go under #ifdef CONFIG_DEBUGFS? Or > > even add a swiotlb-specific debugfs config option to cover all the swio= tlb > > debugfs code. From Petr Tesarik's earlier comments, it sounds like the= re > > is interest in additional accounting, such as for fragmentation. =20 >=20 > For my purposes, it does not have to be 100% accurate. Actually, why are these variables global? There can be multiple io_tlb_mem instances in the system (one SWIOTLB and multiple restricted DMA pools). Tracking the usage of restricted DMA pools might be useful, but summing them up with the SWIOTLB not so much. AFAICS the watermark should be added to struct io_tlb_mem. Petr T