Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1917567rwd; Wed, 17 May 2023 03:17:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7BIKK/pV5TjwTAs/UQmsER1lToW8BZNZLX5qA/OxIsISaJuhUxq19pOPkIPmo3Do7BrjSY X-Received: by 2002:a05:6a00:1248:b0:646:74ce:a36c with SMTP id u8-20020a056a00124800b0064674cea36cmr327302pfi.8.1684318627884; Wed, 17 May 2023 03:17:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318627; cv=none; d=google.com; s=arc-20160816; b=ZRDz1LYb3Mga204JjoshkPS0qQRkrP9/VywiPF1L9Ce0/noJzNJ6wUj6MIzTqImMJv Gh4asGF9B/ipdPfA8S+7yvIX46oqJI23HR/Z0F8ETvEOZmNmSfmHmEmcnfh/FAoQzIF6 rS6RYsesMWSkqx9skZAY8PDAI5VcCFnA3xK2c7M1DMjypCDLolMB2a9zB7Da80GX9DKl U2tY7VUBDeA6OSfdQwYf/kjGR3RTBILxBXHijYhvsrqXjjeS8PiM4xvJGJD/TvGRqhQS WakvCwDOqfz74a8Gk4RJXay8RLNLrlHgvwTaDSXdVUuIjBmlS966A5K03RJIKpulPWY2 e9oQ== 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=K8D5KuDDKipE8qXsFk88CkviaAH/ULehzBw9uhptfNg=; b=HZyI3NUJeqWREJxlRrd0nMoO/SVLuufUtKLenLLTxeldq5UniRZ39a21BWJdVNPqI/ L26zfRzGReEg/KYZo82NLHjO892Ap7ptL8QkM0GkDLgPXu1fwVwlrni0dUaUtXT0Gzf/ l8KVfdHkIkCCr9hMDbsU4pu1HWkk31en2JzVrBwMNyC0TsrAz+OAB5WLfYo5hjBt++Rv X34bzQ7Z5i0vyzMTNam+zI8PhWdAfmso6f+BjHI+U3SpTw1NztsH8wh6zURXad+ly2Mm IU764WXhjspMiQ9YYYYaBBRjtnjZez/FWyDH3xhX11S9teIdyoFARgFMyp+F+n10hVtq k5eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=b2G+mGDs; 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 m64-20020a625843000000b0064cf16e666asi4377pfb.82.2023.05.17.03.16.53; Wed, 17 May 2023 03:17: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=b2G+mGDs; 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 S230057AbjEQJ6o (ORCPT + 99 others); Wed, 17 May 2023 05:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjEQJ6n (ORCPT ); Wed, 17 May 2023 05:58:43 -0400 Received: from bee.tesarici.cz (bee.tesarici.cz [77.93.223.253]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C1A35580; Wed, 17 May 2023 02:58:26 -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 6B409163772; Wed, 17 May 2023 11:58:22 +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=1684317502; bh=WhnfW/mNpML+q2vB7o5SxfZBdLz/zpvDWou9zmU6K08=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=b2G+mGDs3X7jGbTxNRGMvDaOp+pASwt8O3+PV+zwt6N5+/4XQEX/muYWn7+C1lTm4 1J65WG88OPP8glU6VVwbJHKZ7nqADENiNYEhaHlSDGR62ihbw6lLMZQid3D/QGg9K0 p5Rq2wM7rNyaqK9w6otk4OU726Am08OS332pk2j73wsFz7JS6Vq7sQolPQ73P0CkJP u2Z7IjwhrroeV114wIJ0846G+iOiJHLI/PfLL36nt/U0iPYuWfJCq2OWLReIPXutpD ylB+EWOL7TExQ6zoG3f3fOmu02hxHVXFstnL9mGkrWG2wDMUzp+v1LfgUIEELznx5j 1NIrwlLNxC/pA== Date: Wed, 17 May 2023 11:58:21 +0200 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Catalin Marinas Cc: Christoph Hellwig , "Michael Kelley (LINUX)" , Petr Tesarik , Jonathan Corbet , Greg Kroah-Hartman , "Rafael J. Wysocki" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Marek Szyprowski , Robin Murphy , "Paul E. McKenney" , Borislav Petkov , Randy Dunlap , Damien Le Moal , Kim Phillips , "Steven Rostedt (Google)" , Andy Shevchenko , Hans de Goede , Jason Gunthorpe , Kees Cook , Thomas Gleixner , "open list:DOCUMENTATION" , open list , "open list:DRM DRIVERS" , "open list:DMA MAPPING HELPERS" , Roberto Sassu , Kefeng Wang Subject: Re: [PATCH v2 RESEND 4/7] swiotlb: Dynamically allocated bounce buffers Message-ID: <20230517115821.4bf63bf5@meshulam.tesarici.cz> In-Reply-To: References: <346abecdb13b565820c414ecf3267275577dbbf3.1683623618.git.petr.tesarik.ext@huawei.com> <20230516061309.GA7219@lst.de> <20230516083942.0303b5fb@meshulam.tesarici.cz> <20230517083510.0cd7fa1a@meshulam.tesarici.cz> <20230517065653.GA25016@lst.de> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 Wed, 17 May 2023 10:41:19 +0100 Catalin Marinas wrote: > On Wed, May 17, 2023 at 08:56:53AM +0200, Christoph Hellwig wrote: > > Just thinking out loud: > > > > - what if we always way overallocate the swiotlb buffer > > - and then mark the second half / two thirds / > of the thin air> slots as used, and make that region available > > through a special CMA mechanism as ZONE_MOVABLE (but not allowing > > other CMA allocations to dip into it). > > > > This allows us to have a single slot management for the entire > > area, but allow reclaiming from it. We'd probably also need to make > > this CMA variant irq safe. > > I think this could work. It doesn't need to be ZONE_MOVABLE (and we > actually need this buffer in ZONE_DMA). But we can introduce a new > migrate type, MIGRATE_SWIOTLB, and movable page allocations can use this > range. The CMA allocations go to free_list[MIGRATE_CMA], so they won't > overlap. > > One of the downsides is that migrating movable pages still needs a > sleep-able context. Pages can be migrated by a separate worker thread when the number of free slots reaches a low watermark. > Another potential confusion is is_swiotlb_buffer() for pages in this > range allocated through the normal page allocator. We may need to check > the slots as well rather than just the buffer boundaries. Ah, yes, I forgot about this part; thanks for the reminder. Indeed, movable pages can be used for the page cache, and drivers do DMA to/from buffers in the page cache. Let me recap: - Allocated chunks must still be tracked with this approach. - The pool of available slots cannot be grown from interrupt context. So, what exactly is the advantage compared to allocating additional swiotlb chunks from CMA? > (we are actually looking at a MIGRATE_METADATA type for the arm64 memory > tagging extension which uses a 3% carveout of the RAM for storing the > tags and people want that reused somehow; we have some WIP patches but > we'll post them later this summer) > > > This could still be combined with more aggressive use of per-device > > swiotlb area, which is probably a good idea based on some hints. > > E.g. device could hint an amount of inflight DMA to the DMA layer, > > and if there are addressing limitations and the amout is large enough > > that could cause the allocation of a per-device swiotlb area. > > If we go for one large-ish per-device buffer for specific cases, maybe > something similar to the rmem_swiotlb_setup() but which can be > dynamically allocated at run-time and may live alongside the default > swiotlb. The advantage is that it uses a similar slot tracking to the > default swiotlb, no need to invent another. This per-device buffer could > also be allocated from the MIGRATE_SWIOTLB range if we make it large > enough at boot. It would be seen just a local accelerator for devices > that use bouncing frequently or from irq context. A per-device pool could also be used for small buffers. IIRC somebody was interested in that. Petr T