From nobody Sat Oct 22 20:07:10 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MvsnJ35Spz4fy4G; Sat, 22 Oct 2022 20:07:16 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MvsnJ2VBPz4NLh; Sat, 22 Oct 2022 20:07:16 +0000 (UTC) (envelope-from bz@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666469236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Wguz+2AhHGgRiOpagcMF2pLxqMDXSdjhOWgGqAe2o20=; b=yzKbgHrEPHH84GGl7ZqSx27IjkD7JA3qQzboh88Q917azEeMDq1dZYigMJa4ET2PtmLtcE e/C2o83CA3tAnDUS3iIVqSxTvV3kj5Kvn4zEcIAK4T1bUwhI3f3F2fUMAzICG5l31sPFN8 4t8Smfy1E+MGQ2U6BeWcQWEu68ECGD2j2HnQmAztalYoehi6YB45jJTgABpqzDe2+nelL8 JirnSPz51ej8wk/BDuym7hZ6d1TfG+VvVLWjlTKmIbMnJXPAxRrR5gxHB0p5GctlzR7Rd4 AW/rpiHhatd2tn94d1yWAh8JXbtHCXagLOAl8kkkpGlYv5tRVlnKik4LuGAAEw== Received: from mx1.sbone.de (mx1.sbone.de [IPv6:2a01:4f8:13b:39f::9f:25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx1.sbone.de", Issuer "SBone.DE" (not verified)) (Authenticated sender: bz/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4MvsnJ0D47zh0H; Sat, 22 Oct 2022 20:07:16 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from mail.sbone.de (mail.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:1025]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sbone.de (Postfix) with ESMTPS id 05D2E8D4A173; Sat, 22 Oct 2022 20:07:12 +0000 (UTC) Received: from content-filter.t4-02.sbone.de (content-filter.t4-02.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:2742]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPS id 372DA5C3A831; Sat, 22 Oct 2022 20:07:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at sbone.de Received: from mail.sbone.de ([IPv6:fde9:577b:c1a9:4902:0:7404:2:1025]) by content-filter.t4-02.sbone.de (content-filter.t4-02.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:2742]) (amavisd-new, port 10024) with ESMTP id G2c3ppuJM5UO; Sat, 22 Oct 2022 20:07:10 +0000 (UTC) Received: from strong-iwl0.sbone.de (strong-iwl0.sbone.de [IPv6:fde9:577b:c1a9:4902:b66b:fcff:fef3:e3d2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPSA id A98FD5C3A82F; Sat, 22 Oct 2022 20:07:10 +0000 (UTC) Date: Sat, 22 Oct 2022 20:07:10 +0000 (UTC) From: "Bjoern A. Zeeb" To: Colin Percival cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: b7761f1f0830 - main - x86/busdma: Limit reserved pages if low nsegs In-Reply-To: <202210220548.29M5mNP3077218@gitrepo.freebsd.org> Message-ID: <8o30on4n-861q-4p20-26sq-ssrnnn42415p@mnoonqbm.arg> References: <202210220548.29M5mNP3077218@gitrepo.freebsd.org> X-OpenPGP-Key-Id: 0x14003F198FEFA3E77207EE8D2B58B8F83CCF1842 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666469236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Wguz+2AhHGgRiOpagcMF2pLxqMDXSdjhOWgGqAe2o20=; b=COr0Zox90bz5DYx+Icbk/99hpsEbD//DhZXnem8lfpiRaXYvbLF/ZzkrezY4kkt+qsPM7N BbV7rZ4JYRORbe8JoMWSTEgDHzhxr8eaB+dmfpMT1m7qT5UKGIFVUi6Da8/S1v3OKBUkf7 WMiXKnzCm8pSyXTUiwEYN5CiQY/MnkmP44LacX4fGHz/qcndf4p8uxYkNbB8yrVq4mbbii WQimrGdlvHjjJX333XlLn8DPumpI5y6M+CMyDx7S4tvL39K+HUk9AXojdYACfkHe1ERmIl kYIyprA8xh74VtJfvEfEbdT1Nlilhvgaz5f3j50Aex4pHOaI5UZppVXmq7Z7IA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666469236; a=rsa-sha256; cv=none; b=YGeaeWVCHrnvQy36alTwdxcrQCCzov+cA9WhfDWSpdfEjuEbmw+JbO4xLzNXDk5IXwde4o 58nMMZrVsbLBmD3sKXaA5DM8F877Pwg40nt6AJBf4s1gh1fG6AkCUUYLapRKRg2FXgghmm ySKL10Wzyit1xH4WvJYSkamodElyzu2LcG98CHXJd0yZuFeSjka/NaAHzJsizUaAWzCSIQ uZTixlpZSiSEmD+u3OA168nm7NDFSFhG7hkRIkkAo1WNGvmEciNLUWE/5L0DQkixhTSpZy UO/6osE5SpRtRXbpRksSqqGzHucetLJOXng/DUTNwjSBju4G0vC/UtPG6x6xXQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N On Sat, 22 Oct 2022, Colin Percival wrote: > The branch main has been updated by cperciva: > > URL: https://cgit.FreeBSD.org/src/commit/?id=b7761f1f0830fc4b4bd7a1f9f364cfb39b7f4288 > > commit b7761f1f0830fc4b4bd7a1f9f364cfb39b7f4288 > Author: Colin Percival > AuthorDate: 2022-10-21 18:13:36 +0000 > Commit: Colin Percival > CommitDate: 2022-10-22 05:47:33 +0000 > > x86/busdma: Limit reserved pages if low nsegs > > When bus_dmamap_create is called, if bouncing might be required we > reserve enough pages for a maximum-length request, subject to the > MAX_BPAGES constraint (32 MB on amd64; 32 MB or 2 MB on i386 > depending on the amount of RAM). > > Since pages used for bouncing are typically non-consecutive, each > bounced page will typically constitute a busdma segment; as such, we > are unlikely to ever successfully use more pages than the nsegments > limit. Limit the number of pages reserved to nsegments. This is an interesting observation. LinuxKPI desperately needs more consecutive pages but can only ever use one segment. We do have observed cases of bouncing failing due to the LinuxKPI constraints and what busdma provided. I wonder if this is going to make it even harder to by any chance have consecutive pages? I've been trying for a good year to find someone to look into that. There's also other maths which are highly questionable in the bounce parts (c&p and altered between archs). In case anyone is interested in reviewing some bits please get in contact with me. > On FreeBSD/Firecracker, this reduces bounce page memory consumption > from 32 MB to 512 kB, making VMs with 128 MB of RAM usable. > > Reviewed by: imp, mav > Sponsored by: https://www.patreon.com/cperciva > Differential Revision: https://reviews.freebsd.org/D37082 > --- > sys/x86/x86/busdma_bounce.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/sys/x86/x86/busdma_bounce.c b/sys/x86/x86/busdma_bounce.c > index faed4b7353cc..cf919c01ca64 100644 > --- a/sys/x86/x86/busdma_bounce.c > +++ b/sys/x86/x86/busdma_bounce.c > @@ -325,6 +325,7 @@ bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) > if ((dmat->bounce_flags & BUS_DMA_MIN_ALLOC_COMP) == 0 || > (bz->map_count > 0 && bz->total_bpages < maxpages)) { > pages = MAX(atop(dmat->common.maxsize), 1); > + pages = MIN(dmat->common.nsegments, pages); > pages = MIN(maxpages - bz->total_bpages, pages); > pages = MAX(pages, 1); > if (alloc_bounce_pages(dmat, pages) < pages) > -- Bjoern A. Zeeb r15:7