Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4541291rwl; Tue, 28 Mar 2023 08:12:07 -0700 (PDT) X-Google-Smtp-Source: AKy350YQgAmAGOwl0ljUCSfmiNpbJHU0iQ2lA2m9gkUP/uHNT3I7WrfL90grUV5ik7Hpj3mxxVT4 X-Received: by 2002:aa7:9696:0:b0:5a8:bcf2:125 with SMTP id f22-20020aa79696000000b005a8bcf20125mr15644510pfk.21.1680016327110; Tue, 28 Mar 2023 08:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680016327; cv=none; d=google.com; s=arc-20160816; b=Pimb5OvH6k6DSed0SyYo1i3jTNQLtKegoSI6DCN5thfzMMsqkQQM7LrTr9tD4jBz1L TC1qDlhUZsa3PeB8T1T0nIgGMsxaSNcmInWwqkJzOYtq/vxw7fO4UkZ7W7fflesSNF01 WK98I9XR+Eyu2LST7T04IAkEKDpdHPhpuFfjDd9YqLMYgHpeEEBKTOrx0zmMZnc9Ogk4 9GVbEnLgpF18jgkRzZ/M7S/UU95BMEqdNd0TSWmSlnDxcJQWXrtTcRz/qSwIVFccUST6 SR97RzAiJy2OhJkA1483vGbd1KZzDuasqWz5xpOOs9JPQsbi/GSAa/wI1C/60OjrgXXF /f2g== 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=OXsuMo+t96SWiIGN3G91HclNRUFxSMbwTnCqt1E0rJ0=; b=NmpXvamu07IrMghDaABuuW/4W2BsmE7xXIxFktRfu+LAgcGNY6Z5LC4A2Zm99HW3VY mM10L8m0539lJVX2HNduwsRD7WJl9LgnGEeMd4EPs0WfxxNeOzuIu2kx66bmd3HP3YIO gk/GpRorA6BGTIXzDWlHT3YdQFK/Nrc/TmNa2Hqc1Z74m9AbxifKvJiub3M5mFm4AJvx 8oh+bUbf3+RUyFMuzvje8cRd7d6RxMvMF27buWFrJPwfUGavE6vCn5n2uPKMHFOJCah8 SSMN/ReBIh4CBdVIGN8G3UpRKSlFKmGOUTWaTT+yrKTK/6A3SB41ufSZD7OL71AoXKt0 /JcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=hJdGEF4s; 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 s12-20020a056a0008cc00b005a85d73f825si30223130pfu.125.2023.03.28.08.11.54; Tue, 28 Mar 2023 08:12:07 -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=hJdGEF4s; 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 S229806AbjC1PLj (ORCPT + 99 others); Tue, 28 Mar 2023 11:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjC1PLi (ORCPT ); Tue, 28 Mar 2023 11:11:38 -0400 Received: from bee.tesarici.cz (bee.tesarici.cz [IPv6:2a03:3b40:fe:2d4::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F2EEEC4E for ; Tue, 28 Mar 2023 08:10:41 -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 3D8A9162E7F; Tue, 28 Mar 2023 17:07:40 +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=1680016060; bh=+/3nvo1yYXim8zKDDEGS5Ln3cTmFtDCEk+Ab9n7rpdA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hJdGEF4sm5cpMC96PhA7CJdP7X4/E2TDIlbCRhbxzRSrN7aeY+0D6JFo5YseQbKMc c9QmAA7jyYGyo7QK+uvFpNH4J4xnuDt+KEOkTjiPwoJuqkeKreOK+27iV1dd9w2ydF /A0DgOf70+M6yhkIDp3jEHqw/1UelXANFOwpsRxQ/DDe440of55Dy/NrzDvtGIMNYL PzIDxwkAA6sidCbdxDDTMfdH+PfVAnh5xuyT0NkkqsuukcblNvHP1TxCK/AUh+OqPm Z9uk4pFt3dYEvHsVbvCFwxY/wKq+Ohbk9Ga7toFWjHOXWTizA9EallH57bdHWszCaz U7fbsGkU79MSQ== Date: Tue, 28 Mar 2023 17:07:39 +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: <20230328170739.10e33345@meshulam.tesarici.cz> In-Reply-To: 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 14:29:03 +0000 "Michael Kelley (LINUX)" wrote: > From: Petr Tesa=C5=99=C3=ADk Sent: Tuesday, March 28, = 2023 6:50 AM > >=20 > > On Tue, 28 Mar 2023 13:12:13 +0000 > > "Michael Kelley (LINUX)" wrote: > > =20 > > > From: Christoph Hellwig Sent: Monday, March 27, 2= 023 6:34 =20 > > PM =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 devi= ce *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, = new_used)); > > > > > + > > > > > return slot_index; =20 > > > > > > > > Hmm, so we're right in the swiotlb hot path here and add two new gl= obal > > > > atomics? =20 >[...] > > For my purposes, it does not have to be 100% accurate. I don't really > > mind if it is off by a few slots because of a race window, so we could > > (for instance): > >=20 > > - update a local variable and set the atomic after the loop, > > - or make it a per-cpu to reduce CPU cache bouncing, > > - or just about anything that is less heavy-weight than an atomic > > CMPXCHG in the inner loop of a slot search. > > =20 >=20 > Perhaps I'm missing your point, but there's no loop here. The atomic > add is done once per successful slot allocation. If swiotlb_do_find_slot= s() > doesn't find any slots for the current area, it exits at the "not_found" = label > and the atomic add isn't done. My bad. I read the patch too quickly and thought that the update was done for each searched area. I stay corrected here. >[...] > I thought about tracking the high water mark on a per-CPU basis or > per-area basis, but I don't think the resulting data is useful. Adding up > the individual high water marks likely significantly over-estimates the > true high water mark. Is there a clever way to make this useful that I'm > not thinking about? No, not that I'm aware of. Min/max cannot be easily split. >[...] > Regarding your other email about non-default io_tlb_mem instances, > my patch just extends what is already reported in debugfs, which > is only for the default io_tlb_mem. The non-default instances seemed > to me to be fairly niche cases that weren't worth the additional > complexity, but maybe I'm wrong about that. What I mean is that the values currently reported in debugfs only refer to io_tlb_default_mem. Since restricted DMA pools also use swiotlb_find_slots() and swiotlb_release_slots(), the global counters now get updated both for io_tlb_default_mem and all restricted DMA pools. In short, this hunk is a change in behaviour: static int io_tlb_used_get(void *data, u64 *val) { - *val =3D mem_used(&io_tlb_default_mem); + *val =3D (u64)atomic_long_read(&total_used); return 0; } Before the change, it shows the number of used slots in the default SWIOTLB, after the change it shows the total number of used slots in the SWIOTLB and all restricted DMA pools. Petr T