Received: by 10.192.165.148 with SMTP id m20csp1219009imm; Wed, 25 Apr 2018 14:45:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqtIY1DRLtBlhi/rz7cYMxDiOR7E+nJK+8+eWbnl2O/qUYeGk1cX5RFWnSlOUwzAnwdRMrB X-Received: by 2002:a17:902:7405:: with SMTP id g5-v6mr7901312pll.102.1524692716440; Wed, 25 Apr 2018 14:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524692716; cv=none; d=google.com; s=arc-20160816; b=ba5lNE6idPfof2SrAlmtqX5NUMwIi/1FZ+c+JzSCiJgKt6/1t7iciDyFaisCGeZy1c MyEVUeT+VChaoiGEgpkVGHLFgUBXu/qDXFSBoUtfMQJy7XS922ezgWqVe+yGSuvSWA9n P00AGMPETnbynu1IOSC0FcZSYaT2ryrgf531RQli8vQS0m7aRX3Wov/sG+ZN3rJIQMHS VGLxfYGjqS2br13DH2GDd3rGBbX+euPWGWlqdyFdJxVP8/xfge2fiQGza9JmB+Vz74fL JxXn9OrTLqOFpAMTZu8fNILz27Wt6uKMz346maE411+3xs9ckBiFQNzv2c+PEm1kaVCU 2Dzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qoA+EvLfUS4mzyq2cNb0w4rul1Y8GTgDqC8yR1GRKRA=; b=hiwmH2wtoI/kE4jVSnh1xj0MGglqXkg5y0lKzXrMiQET6Wf+qH/eBTCLDgG+6osel3 gMWlMUMRHwnb3qi97BNILJfdXSp1ow/iHiLBmeOKaZp+HH7gTihsNb7H07MVdM7sxcGC QKqUfk6TCEcNqKLBMS87ZxXHawj1BuFib5Ttip6vDeNgCucAydrBBUykXGxFB8CRMnYP gdTS9OHo3rBJohH5/8e7pjHDWwn1ZyVPwzs4KyuwYdT8uZDM3bEnS3WrMY3C+Mu7nAAZ w0cGvvtH0/chgA5xRVjFT8OoP7JDe/hjP1kMvrtg6udIgYGMyOPBsC/KHAPPiw4rlipM 0z5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Z1mAqGIQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4-v6si17521138pll.438.2018.04.25.14.45.02; Wed, 25 Apr 2018 14:45:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Z1mAqGIQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753549AbeDYVn2 (ORCPT + 99 others); Wed, 25 Apr 2018 17:43:28 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39658 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753344AbeDYVnX (ORCPT ); Wed, 25 Apr 2018 17:43:23 -0400 Received: by mail-pf0-f193.google.com with SMTP id z9so16350157pfe.6 for ; Wed, 25 Apr 2018 14:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qoA+EvLfUS4mzyq2cNb0w4rul1Y8GTgDqC8yR1GRKRA=; b=Z1mAqGIQTppGi8/HmyzV7lYkqyTnC/6+Qwz8590Uj4y4gmhjOgtXPLtv34R9haGm/G LpnmbN/KM7fwbdDhBOYikZZpBidLCpouVto6Z55CZ8VMytZvlyxbjf9psknvu1aFGxM6 N/FbKUVF72dH+eS6pAKPP6acRTVwz4XC/kTpmmgV83SM2Fidi22RowXHGfOwvdLkpVf9 Yc4eQgCsgDclU2OIXo8u9se3WIv3mhfq+ww7b0hQ0Nq7UrbFAD2WnBFDzf3JFsERZmi+ s0hzOikELcUzChg3wjXiigQfRdLmdOJvmVLalKt2/Er4mYptjTUd5AV9/qw/MAc6ol0/ ds1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qoA+EvLfUS4mzyq2cNb0w4rul1Y8GTgDqC8yR1GRKRA=; b=mHuUb30yAeTzupRvxIcbgDXN/esdL7FCQ5l9+H5oXCUi5qzHHUC/qAuLIrADCoVSFu fIrvWZ1Yl2QkK9gvUr77069nDHn6/E7C6U3Ew7ed0ZR++8k5bgvsunqxDhe2almL8hXL Jy0H7YiQ0Ywzob+Xqrry7nLEg2KHopKTncsHTZarm18g2ovLX+lJ6Ak7FGghadpUlt3U TQlOyLpiDi5xY855gkFhgyuUuDs1O9uBzFqrwPWYGTjzoX+N0F6ALC0QJyyGsLqEqOIk LzIt4xgSNYAUWuilLr5T7sHZn1QedjP7pUl8WAypPnpMqT0nCj0KipGOo7HsBGK8gm3r S5pQ== X-Gm-Message-State: ALQs6tBg/yLrnNHj2kfbLDNcl9fzfmfQMA9TqTGXrjM6oJJJjzf4mYos KdWMUBPtiWueTsQQg2TVNgSoBQ== X-Received: by 10.98.236.220 with SMTP id e89mr29707938pfm.33.1524692601896; Wed, 25 Apr 2018 14:43:21 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id 186sm33004837pfe.109.2018.04.25.14.43.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Apr 2018 14:43:20 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" Cc: netdev , Andy Lutomirski , linux-kernel , linux-mm , Eric Dumazet , Eric Dumazet , Soheil Hassas Yeganeh Subject: [PATCH v2 net-next 2/2] selftests: net: tcp_mmap must use TCP_ZEROCOPY_RECEIVE Date: Wed, 25 Apr 2018 14:43:07 -0700 Message-Id: <20180425214307.159264-3-edumazet@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180425214307.159264-1-edumazet@google.com> References: <20180425214307.159264-1-edumazet@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After prior kernel change, mmap() on TCP socket only reserves VMA. We have to use setsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE, ...) to perform the transfert of pages from skbs in TCP receive queue into such VMA. struct tcp_zerocopy_receive { __u64 address; /* in: address of mapping */ __u32 length; /* in/out: number of bytes to map/mapped */ __u32 recv_skip_hint; /* out: amount of bytes to skip */ }; After a successful setsockopt(...TCP_ZEROCOPY_RECEIVE...), @length contains number of bytes that were mapped, and @recv_skip_hint contains number of bytes that should be read using conventional read()/recv()/recvmsg() system calls, to skip a sequence of bytes that can not be mapped, because not properly page aligned. Signed-off-by: Eric Dumazet Cc: Andy Lutomirski Cc: Soheil Hassas Yeganeh --- tools/testing/selftests/net/tcp_mmap.c | 63 +++++++++++++++----------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c index dea342fe6f4e88b5709d2ac37b2fc9a2a320bf44..5b381cdbdd6319556ba4e3dad530fae8f13f5a9b 100644 --- a/tools/testing/selftests/net/tcp_mmap.c +++ b/tools/testing/selftests/net/tcp_mmap.c @@ -76,9 +76,10 @@ #include #include #include -#include #include #include +#include +#include #ifndef MSG_ZEROCOPY #define MSG_ZEROCOPY 0x4000000 @@ -134,11 +135,12 @@ void hash_zone(void *zone, unsigned int length) void *child_thread(void *arg) { unsigned long total_mmap = 0, total = 0; + struct tcp_zerocopy_receive zc; unsigned long delta_usec; int flags = MAP_SHARED; struct timeval t0, t1; char *buffer = NULL; - void *oaddr = NULL; + void *addr = NULL; double throughput; struct rusage ru; int lu, fd; @@ -153,41 +155,45 @@ void *child_thread(void *arg) perror("malloc"); goto error; } + if (zflg) { + addr = mmap(NULL, chunk_size, PROT_READ, flags, fd, 0); + if (addr == (void *)-1) + zflg = 0; + } while (1) { struct pollfd pfd = { .fd = fd, .events = POLLIN, }; int sub; poll(&pfd, 1, 10000); if (zflg) { - void *naddr; + int res; - naddr = mmap(oaddr, chunk_size, PROT_READ, flags, fd, 0); - if (naddr == (void *)-1) { - if (errno == EAGAIN) { - /* That is if SO_RCVLOWAT is buggy */ - usleep(1000); - continue; - } - if (errno == EINVAL) { - flags = MAP_SHARED; - oaddr = NULL; - goto fallback; - } - if (errno != EIO) - perror("mmap()"); + zc.address = (__u64)addr; + zc.length = chunk_size; + zc.recv_skip_hint = 0; + res = setsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE, + &zc, sizeof(zc)); + if (res == -1) break; + + if (zc.length) { + assert(zc.length <= chunk_size); + total_mmap += zc.length; + if (xflg) + hash_zone(addr, zc.length); + total += zc.length; } - total_mmap += chunk_size; - if (xflg) - hash_zone(naddr, chunk_size); - total += chunk_size; - if (!keepflag) { - flags |= MAP_FIXED; - oaddr = naddr; + if (zc.recv_skip_hint) { + assert(zc.recv_skip_hint <= chunk_size); + lu = read(fd, buffer, zc.recv_skip_hint); + if (lu > 0) { + if (xflg) + hash_zone(buffer, lu); + total += lu; + } } continue; } -fallback: sub = 0; while (sub < chunk_size) { lu = read(fd, buffer + sub, chunk_size - sub); @@ -228,6 +234,8 @@ void *child_thread(void *arg) error: free(buffer); close(fd); + if (zflg) + munmap(addr, chunk_size); pthread_exit(0); } @@ -371,7 +379,8 @@ int main(int argc, char *argv[]) setup_sockaddr(cfg_family, host, &listenaddr); if (mss && - setsockopt(fdlisten, SOL_TCP, TCP_MAXSEG, &mss, sizeof(mss)) == -1) { + setsockopt(fdlisten, IPPROTO_TCP, TCP_MAXSEG, + &mss, sizeof(mss)) == -1) { perror("setsockopt TCP_MAXSEG"); exit(1); } @@ -402,7 +411,7 @@ int main(int argc, char *argv[]) setup_sockaddr(cfg_family, host, &addr); if (mss && - setsockopt(fd, SOL_TCP, TCP_MAXSEG, &mss, sizeof(mss)) == -1) { + setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss)) == -1) { perror("setsockopt TCP_MAXSEG"); exit(1); } -- 2.17.0.441.gb46fe60e1d-goog