Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4356445rwl; Tue, 28 Mar 2023 06:13:51 -0700 (PDT) X-Google-Smtp-Source: AKy350bZ/8NlnHZ2hCKLWPdwgHvzg5vuUnVDLsc5wEuudfDX21l/MUrhmpCccM4afRL+K8C4ejNk X-Received: by 2002:a17:906:33d2:b0:92c:6fbf:4d with SMTP id w18-20020a17090633d200b0092c6fbf004dmr15714590eja.40.1680009230993; Tue, 28 Mar 2023 06:13:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680009230; cv=pass; d=google.com; s=arc-20160816; b=pkaCQO3quZjx2mcSUYIJ0Sz+NP3gQJ6vM40aYF8nO4INuM57Z+AV90vg0RAimoQCHZ 7oQlZ98YxmOX0d3NuRqyEwqXaPR+eWQmGMyKL550kGHCMk/Lw10+oUY1GuVUMz+ppni2 fhXdNfIzpH76seoKYh/lzWX3a+MPUJyf8wlQvIxYEn9a67lFUN/3XZ0d64SHjlOoMgWR 7+Lp2NBuRecNqE0B41ohIrH6nVU/c/nZSaCXH2Qa7qWglC6DCsSI9R56HS88idaiQSK9 wnjdtzA6DYlifnXLvMSbSbJdsi8Et46Bh3A5e4+sG6PyR2r6m7LHxgAlp01Ixx4mr72i ETNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :msip_labels:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=WqusIBji0p4iqpVlYJvLk1RLC13ltJdakU8QcW3YChs=; b=HaUJKhz0Lb0QFC3S0ntw2XenEx/Nl2IIvTEb2zcqqzUD2ad5Izbo8oj2+nEXN8CiXa BUJFwnw2sy0t555HTzCJQpmvLUZvf7Tstw5gwl7C3qql8DQ2k5Z4NSJTrkivrXWmBZqw QOvYgrMRBxZWgaQdMChQpiz8apwrv2Qpj0l6esV8EoKmous58UccrGW+n2obTRdfOnMR hVtJVrgORpqpJMAfmUFztoyFMK9pb5/DXmrt7x7ueYnzDG76ZSqxQV7fGpi13dEXIrRJ 9e9nNrj6jmJt3PUqrxrYUvlP/YDlwOzflDZMvcGUoaluWZNn2i/eTt3Zc7of+8FbbnqA UJOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="Q+kH/oBV"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v26-20020a056402185a00b004af70e6ad12si27766547edy.133.2023.03.28.06.13.18; Tue, 28 Mar 2023 06:13:50 -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=@microsoft.com header.s=selector2 header.b="Q+kH/oBV"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232922AbjC1NMg (ORCPT + 99 others); Tue, 28 Mar 2023 09:12:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232844AbjC1NMc (ORCPT ); Tue, 28 Mar 2023 09:12:32 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021019.outbound.protection.outlook.com [52.101.62.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF1C583EA for ; Tue, 28 Mar 2023 06:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BYkP40/xkjbTaO51134DNBSRXXLV5dCxoukachduhmsO4iBVsV11f1LJ/OlhWv8+omzp+pohLh0wWPleKI8AIobVT2BHENFRsHrOwFj6gxbNxaewpF09a/rW2l+v3MulcBN+SEdygbNsGaMDFHefQAg7MHQqi9BVY9QEEe89Kj8lqEnlbJM8Bq8Mr8yY21KrN5uPLjqeamlr4s4NWvWe1qhfFkKf5pufioYZO5yGFU3ILlPR+2AJIvrqNbZSAbUUAjsqDZUxw8tK2x87De8VY0XiMzgZ4msfQvcgfHzYVjOrgw+7P+HYzMj+tRxh/3HtD0PmUgecCvODyMx5/R0mSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WqusIBji0p4iqpVlYJvLk1RLC13ltJdakU8QcW3YChs=; b=at8k5qZESbrvsRj/ZSBR4ekdkkS2R2yiOB3BqFT2m5BJIRDHbgwRfJtUMd3a66PVpSaR1xmeKFpKHj9VP7B5tHK5htqw52RAfoHO8tlrKtj6ORw5D9qn8j2L9tnQBFfTXvLTjayhNjZvBpM+GDFWSrXa71Ag4HaKupNhLtQJ9kyP3tAzUSyAcvjB86UVU9GOYVmKXUU/bPcaKc9L3QBjjtbXRvZO6msgoBWfW3y2hymbW5pIovqf5EdlkyL1uB9u3BmGsS/47TsrTLVIANK9940nfkRZxXEN+zBfhJoOGFuFIhPf8YvRu04LS1O5dJtfIOq18uAwTq9GGBDjHcDrsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WqusIBji0p4iqpVlYJvLk1RLC13ltJdakU8QcW3YChs=; b=Q+kH/oBVShXEzKxopJfgFwbaSMJhy0x3KHgxETXaBkS0AEagITXFmWYb5MWbZ+Q4cW4eHnhE80scYq8kTvZOJ7P758mHclkUi/UZekAXB4lfkCecEUO0Mb6Z/m7lY9o3J2U1pFiTBP3PQVdm2JclwEoxQbaHslnFcfd0IbJ6DPY= Received: from BYAPR21MB1688.namprd21.prod.outlook.com (2603:10b6:a02:bf::26) by MW4PR21MB1890.namprd21.prod.outlook.com (2603:10b6:303:64::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.7; Tue, 28 Mar 2023 13:12:14 +0000 Received: from BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::acd0:6aec:7be2:719c]) by BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::acd0:6aec:7be2:719c%7]) with mapi id 15.20.6277.006; Tue, 28 Mar 2023 13:12:14 +0000 From: "Michael Kelley (LINUX)" To: Christoph Hellwig CC: "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 Thread-Topic: [PATCH v2 1/1] swiotlb: Track and report io_tlb_used high water mark in debugfs Thread-Index: AQHZX0LG5qMB8+ZzCUqrEQruwKd8m68PbDKAgAC/CxA= Date: Tue, 28 Mar 2023 13:12:13 +0000 Message-ID: References: <1679766790-24629-1-git-send-email-mikelley@microsoft.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=c645c878-e33f-4df7-aacc-9159c2a6a91b;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2023-03-28T12:57:41Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BYAPR21MB1688:EE_|MW4PR21MB1890:EE_ x-ms-office365-filtering-correlation-id: c8408504-6d16-42e4-0dbe-08db2f8e0c35 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HMXfVyzsQ+Y0QsmYK3FGu3lTyTV7yAFM1H05lDi0edqsMtXyMF7Yz58abB0EvMHA09A3F/Nwb88MoyY0zb5eph5Z38iwZwMMyFyZBM55VXB4eiZWWTC8rYHaGHmiI0XESKn4/Yv/Ly3l6UCrJEgBiEhAyY+cou3srQmBMx3t8M4fWSv1Co2aFGRRwsFqbOOpmlQcwkK69q/T6GiQVVipgM6NW2uW3WIqK4sDr1uTx2laDib+qahaJwEAbAD/3JgqhUZ74ALHtZyfKZYSOTaiUOJI4dtd1NZC2fNE9a7l7d2O/ZErEWrVcQ9Vf6wnzmqzsj+mPxnqo7xFLyUdKQO11t5iKCl8gNpGoA0CzgYl5VS2XaNvGjYe5SdWjw3O6A2pLbLu2UUNKSmOU6HNNGPGpmF1JQ+hRiz3l/htPFPI5JsIUTwc08GpBbWXL4eXO16G8a2oV7dKeO9Z7fMBYaHK7svcPjvD+2ZhOjaQCBswiVzEAIOglP/q8TE6QM7mIenOLEdT04ZnetCDUGXx3FTU0eqSpNMY6ouPOw48mOQbPhXYVng2q4rG4slbkPz3NnVoBSF+8o1IGBdVqVIuqy3stdrxlrrAJuPyVgrCIeEKmYx0w98SQE/l+WIMpMXZ49WXoCB3FwKnwZq+wUmQsieBW3wAYvF/BgBOd2mEl9im8Fs= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:cs;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR21MB1688.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(376002)(396003)(366004)(136003)(451199021)(478600001)(54906003)(10290500003)(316002)(9686003)(6506007)(26005)(186003)(6916009)(4326008)(66476007)(8676002)(66446008)(64756008)(66946007)(76116006)(66556008)(2906002)(41300700001)(83380400001)(82960400001)(82950400001)(8990500004)(38100700002)(122000001)(38070700005)(86362001)(71200400001)(7696005)(33656002)(55016003)(5660300002)(52536014)(8936002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?chsdtW5lbjIyxihFOqmuBGzFzE4DRa92O0mzJGN8/e9CdhPPjbK55FLsPx7O?= =?us-ascii?Q?AzdpjKsl+zcw7NbN4GlPM/r65Imt7+UmxzvmLiRkITXnMEIWQLoS3XlAMyRI?= =?us-ascii?Q?NHQbDiWrGRl0D9NF6N34BoHTFGHVoHRI+bkPh+ze7OjsgLgNC/RGHapjHSaj?= =?us-ascii?Q?O2LcHWWDYpGtVCIsDKgihci00M8eW5dNweuqONzbMCzXg0YyjZYwhBkpEUUs?= =?us-ascii?Q?Wz1DlYrA5PhYbKYTyY8uL/YrtTfsrZ5d0eIXYXxZBaaCN+lLiFFdQoFi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ZwZO+2PW0e2p3vuwhjaLtluwVfthhz?= =?us-ascii?Q?1u+logFuCg024TKmaQCMFpgpGoj/d09Em1BwdPY80ZRI1fPSmHQpw1yxOLB8?= =?us-ascii?Q?GpqQXGXs+qfbIeAuLf0rRawxl3Bh5udWAA0SFphcM8iSP6TBPQamiT1ePgt4?= =?us-ascii?Q?yKGMvEC/F0H/aZoDcv0vvn/V4k3iJKPLghtrLWs7UGo/ZRG2JxORa/PLh+fb?= =?us-ascii?Q?6nHeSpR7WQe5/UFWUzj+4Qv7rQQjyJRt+XOzWyR2Ks0wvrGJjdrKtWeO8SGH?= =?us-ascii?Q?enVjcoaWjz6BRq6CR4ZbMXZE6xBiAkjb7q7jlqr6bzte0Vvd82n6tEi1Lu5G?= =?us-ascii?Q?4TiZ8rDGSTQqBxEw8JvEiIV7Nux7ux6jijZ1IbzcrNh4K3smzoqf7bTLPEEH?= =?us-ascii?Q?Xz3LrA0wK4YMkOYjaT+kZ8n52Fh1edmf3qXxEsOcadoS0Oo4MhCCPxivBDsL?= =?us-ascii?Q?TA=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR21MB1688.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8408504-6d16-42e4-0dbe-08db2f8e0c35 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Mar 2023 13:12:13.9167 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: NF9HWBuqERTq2cLJ/dYU+9HJ4aDrAw5KrHxhTILs286fjcAGyO3nvlP3StAumSQGtndC15fMM8sfTpxCGIzmQyoVi6oW0d4z67EgLPur+/M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR21MB1890 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 From: Christoph Hellwig Sent: Monday, March 27, 2023 6:= 34 PM >=20 > On Sat, Mar 25, 2023 at 10:53:10AM -0700, Michael Kelley wrote: > > @@ -659,6 +663,14 @@ static int swiotlb_do_find_slots(struct device *de= v, int > area_index, > > 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_us= ed)); > > + > > return slot_index; >=20 > Hmm, so we're right in the swiotlb hot path here and add two new global > atomics? 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. Perhaps this accounting should go under #ifdef CONFIG_DEBUGFS? Or even add a swiotlb-specific debugfs config option to cover all the swiotlb debugfs code. From Petr Tesarik's earlier comments, it sounds like there is interest in additional accounting, such as for fragmentation. >=20 > > 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; > > } > > + > > +static int io_tlb_hiwater_get(void *data, u64 *val) > > +{ > > + *val =3D (u64)atomic_long_read(&used_hiwater); >=20 > I can't see how these casts would be needed. OK. Will drop the casts in the next version. Michael