Received: by 10.192.165.148 with SMTP id m20csp280648imm; Tue, 24 Apr 2018 22:29:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx48K2/++W1b6lXBCRLXLMNRHG4dLFsOkWm3ZJEsI4H93uiEnycnWkH5fQWRQkELH+FYhyH8V X-Received: by 2002:a17:902:24c7:: with SMTP id l7-v6mr28522271plg.320.1524634142989; Tue, 24 Apr 2018 22:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524634142; cv=none; d=google.com; s=arc-20160816; b=oh2cArNPtUpSRu5U56JNIRdBCuiGlOxKKFW7394g/3kOO0PqK16h61yvR6kPmjpdxR qNk2Krm3q8XNv8K/B/sso3Zg1yXbTEHbQt66zkjmbcJcmDgEseUEiGKfNNLt87VSyKJS jyaO086v8dYoqEXErA/FYmGwnx2kdRIGGaKRS/2Z2bSC3rmR4MXOxY0Hn4pwJr/zyAHS htVM/eomy7eZEfZuTHQRDbGWNOnm27M/hiH5O2azPyvmuJAbnmQ9OTqg5uSCJ1An/av+ 5j5F1RVHeZb0xYHsVXr5mKwE98j23zhKwDXAwaGoZaKbQm2EJnwDPFIFyQ3q0neqyUcW QYOw== 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=1UjZg7+6TcLjit3pDnzcrMq5lVs8sIPYtU+QZR4aTSQ=; b=M81JELof4gFZCL6BsdL19l2LDLQz9g+6WUfJ8QRAjeuYzSZpOMFIL4HkD05Q2pQL33 r27zemNIwgvNv+WtGCzxHLD7043CbcplF1b7xDf2v7Ry0afaLlMKkMFdn9l79M9h3fAH fq6n5Do819kcodU7icZ+RdbsOxJCbbDNp/uyh2/iqYl5HrkXdu8woUfoyw8+QQUinBcg EbSsaWRP0NR8jz61tTNXHV3Tn1yd60d4qIcP9hONscbVSInog0boB/YfPjtKPNYYk5Oe HCM5r7U5nI2XEvzNPWNDW/BLucquTDMZBoZH9L+/XaQbT2fwLjcBOwnDLGkp2fb6bPOx IaFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=N0+/xt8x; 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 n3si12817497pgd.534.2018.04.24.22.28.48; Tue, 24 Apr 2018 22:29:02 -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=N0+/xt8x; 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 S1751336AbeDYF1m (ORCPT + 99 others); Wed, 25 Apr 2018 01:27:42 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:40243 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751181AbeDYF1h (ORCPT ); Wed, 25 Apr 2018 01:27:37 -0400 Received: by mail-wr0-f195.google.com with SMTP id v60-v6so51996045wrc.7 for ; Tue, 24 Apr 2018 22:27:36 -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=1UjZg7+6TcLjit3pDnzcrMq5lVs8sIPYtU+QZR4aTSQ=; b=N0+/xt8xag/tlBJslgXTJx6VQx1LNn71C8SAVo75OJa8PGEr0SipNBsoqjllSjk6TM kZXH7QV8WOR3+R3SW5c7t/EP9os9p4lTipcv0zJLYQyR4YvchYgTvE+rxAyTfNpKkpOI gN0c0HESwUhOZAnePu/2cBpTkOdWD8pj62U6nNmcdYIxeTmcCcsR6Bj5vvpNsZVA3eSr fv1CMJ6ut5GDBAPvc2MKCpK6L5AlG/DXPwTJz666Qw7+SDRGSWDIsB/pl4CqhnK9WTkc p0IccBPRAybA/lLW8CAMTMo73t5tiWdSA/FTQGOo2cx7vrUHrIPnTmK98nvGFrCh4Fps 9fwg== 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=1UjZg7+6TcLjit3pDnzcrMq5lVs8sIPYtU+QZR4aTSQ=; b=HRBa1j8WvWBMFvQt/dK+PSJJNSAnPQMZbq7yhUz0VPfKVUbMGTFP4QFquX9YA40F9y 2ots5u/jA/HBHA475teaCCw7Vg8V8lp3eJXm1+nL9UvZ7HzgIymUSgSOtTCVjof2fIQh 1mlVzE/5KmtE3MIJkFujHutW+jfXksCJStblHKjN4q0IrCNR4OhswxgL7T5Lx+4yt7p0 hjhK2b8KTxnbzBF+hP+7Nea8+ag4W7ydkROftm30sfRlrJz+Kc6wsgi7QggN9Ue6SLhb JzN4fzlDMXVc1GaYPLgoiRBrFQ7HhE8DLnbsspcfGtRqqQfaEkqbXHIu+zWHB7MYL3Wh w7BA== X-Gm-Message-State: ALQs6tA+nE4YMxG35heBbR/+M4m1EeDIFj7WDsMG3TbAqkToZ9UtXkAB eYdStVVyYMgU4jsLy4GZEFJY4w== X-Received: by 2002:adf:bacd:: with SMTP id w13-v6mr21590296wrg.125.1524634055356; Tue, 24 Apr 2018 22:27:35 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id z5-v6sm1960711wrm.61.2018.04.24.22.27.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Apr 2018 22:27:34 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" Cc: netdev , Andy Lutomirski , linux-kernel , linux-mm , Soheil Hassas Yeganeh , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 2/2] selftests: net: tcp_mmap must use TCP_ZEROCOPY_RECEIVE Date: Tue, 24 Apr 2018 22:27:22 -0700 Message-Id: <20180425052722.73022-3-edumazet@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog In-Reply-To: <20180425052722.73022-1-edumazet@google.com> References: <20180425052722.73022-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.484.g0c8726318c-goog