From nobody Fri Jun 24 16:10:37 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 E924C865AF0; Fri, 24 Jun 2022 16:10:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LV2Cf0CDmz3JRK; Fri, 24 Jun 2022 16:10:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LJZywG53G5qwhAeaU10ArteQ5kerFt1yIV+UGXVFeco=; b=RN4V6kb4VNuuOTb6taogWaTE7FIuvZZDxYKs/KT95nOHUXhAMycoJT0NUCplynmtTbQYV/ EyMvhEDanYzCsthznq0ZxSAp5rJsPjF1RPSKx6/PN4xVb0lJJYwNH1RiKK1o/nGm4pGIUh kyl5lWmu8RoOJeAEat4i8I+vEdThaJnLRrAjg4TVvXYQXd0VKp/Rns92Rm505xsRrrnWeO aj38k6BjI1Zv7OLA2RZ2cvozjbB7kyW1I1G1iQWYlgyz/cL/bq2OGteifAJpCGTFsw7Sa5 vYumg8ngTryqwoA7wMMny/G7AJMm9YJ3RRzEXantL00ZExWXNg95IpUMp56zmg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BDFB813175; Fri, 24 Jun 2022 16:10:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25OGAbPT006266; Fri, 24 Jun 2022 16:10:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25OGAbx9006265; Fri, 24 Jun 2022 16:10:37 GMT (envelope-from git) Date: Fri, 24 Jun 2022 16:10:37 GMT Message-Id: <202206241610.25OGAbx9006265@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 9b841b0e2390 - main - m_uiotombuf: write total memory length of the allocated chain in pkthdr 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=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9b841b0e239027a4966005cad4d32cbefb52e906 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LJZywG53G5qwhAeaU10ArteQ5kerFt1yIV+UGXVFeco=; b=U/YQzLujgAU0yovvV5hCsHNFpdG1zLRVu/vAbqDoNbelsaa8IT8ry7Ugfn0tU52CJTKUei AbFc5C6iqrFlg0rmTIV1tmHedOAF84VHfTtHlSbN/JaU/MnaOALHMbBCs49RarFgEyZTAb w/0SzW+VGaKL1lrDnIMgd7ebs92PBDOt6eGiEKNlIaxJchE+8xtxBCt5tvypM/cmxD+WrP +TEe2jqO/+Vo9qlaIBALf/My6p3hadqW7t66PWyEkE8btkQVTmmuAUazeT67JzugTbPRfX MdEV/1sFRXmODlj7qltj0HkyBDZRnGxv+q2JXNLc5AFlL06KWtQ3l4ISOpfLIA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656087038; a=rsa-sha256; cv=none; b=LJoTsjWFKcM7wcmz+gcqT9+QhuSh95U/UvJdHxU5D8MCmJlrDnHIreEm1y1Uoiq/C3OCmN +PnhZUXcmkXXzfvXgxiPT6B59d9PqoLkTM6roxD5l93YqpWYGK/iFGRgaaLMVUDMyLNdiN M7xX/QLAMv+ou1LTnc1RyoEFa9ukukaWURa+8JZxn4yKj9GAwKwvWmgvk3YQyWtSUf2/5h XX+SxZsHjJ70PdNpE/lLoordcx6+qn6LwaKYY5sd/Kr5M9ea2fJmFy3cIgQeSH2VRHjW9h gw++JzCUcxBjlWS1SZ9rc+7b4smIYxT9EoViV6PyJ5jWQJeUlEgK/zQap4Tivg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9b841b0e239027a4966005cad4d32cbefb52e906 commit 9b841b0e239027a4966005cad4d32cbefb52e906 Author: Gleb Smirnoff AuthorDate: 2022-06-24 16:09:11 +0000 Commit: Gleb Smirnoff CommitDate: 2022-06-24 16:09:11 +0000 m_uiotombuf: write total memory length of the allocated chain in pkthdr Data allocated by m_uiotombuf() usually goes into a socket buffer. We are interested in the length of useful data to be added to sb_acc, as well as total memory used by mbufs. The later would be added to sb_mbcnt. Calculating this value at allocation time allows to save on extra traversal of the mbuf chain. Reviewed by: markj Differential revision: https://reviews.freebsd.org/D35301 --- sys/kern/uipc_mbuf.c | 6 +++++- sys/kern/uipc_usrreq.c | 2 +- sys/sys/mbuf.h | 18 +++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 02a9a120b970..17fa670c9406 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1899,8 +1899,12 @@ m_uiotombuf(struct uio *uio, int how, int len, int align, int flags) mb->m_len = length; progress += length; - if (flags & M_PKTHDR) + if (flags & M_PKTHDR) { m->m_pkthdr.len += length; + m->m_pkthdr.memlen += MSIZE; + if (mb->m_flags & M_EXT) + m->m_pkthdr.memlen += mb->m_ext.ext_size; + } } KASSERT(progress == total, ("%s: progress != total", __func__)); diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 553d0293770c..d1c87865c632 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1268,7 +1268,7 @@ uipc_sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, if (cc <= sbspace(sb)) { STAILQ_INSERT_TAIL(&sb->uxdg_mb, f, m_stailqpkt); /* XXX: would be nice if m_uiotombuf() returns count. */ - for (; f != NULL ; f = f->m_next) { + for (; f != NULL; f = f->m_next) { if (f->m_type != MT_DATA) sb->sb_ctl += f->m_len; sb->sb_mbcnt += MSIZE; diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 8f377d580aa4..48ed63ef67b8 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -207,13 +207,17 @@ struct pkthdr { /* Layer specific non-persistent local storage for reassembly, etc. */ union { - uint8_t eight[8]; - uint16_t sixteen[4]; - uint32_t thirtytwo[2]; - uint64_t sixtyfour[1]; - uintptr_t unintptr[1]; - void *ptr; - } PH_loc; + union { + uint8_t eight[8]; + uint16_t sixteen[4]; + uint32_t thirtytwo[2]; + uint64_t sixtyfour[1]; + uintptr_t unintptr[1]; + void *ptr; + } PH_loc; + /* Upon allocation: total packet memory consumption. */ + u_int memlen; + }; }; #define ether_vtag PH_per.sixteen[0] #define tcp_tun_port PH_per.sixteen[0] /* outbound */