Received: by 10.192.165.148 with SMTP id m20csp424835imm; Fri, 20 Apr 2018 08:57:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/2JtorRWGwtYvq4Rv0knw+1mHFp4XiaVPMwmFsOuDwu+xMFwM7vCsaKvde91rWlxht27oy X-Received: by 2002:a17:902:7249:: with SMTP id c9-v6mr10816025pll.217.1524239872932; Fri, 20 Apr 2018 08:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524239872; cv=none; d=google.com; s=arc-20160816; b=1JSfQLhb+kCpFXWD+S6RLfLeGDb3OHM0A09CGgZZs3Ym3AbfskwupiFewGlGGRAMdO csogwlaVssvBFiJII2qdMS2m7o9iYGNPobJ55nhA+85Q+bZOyONrSBa1VritXctrKppk noiNxMrVgEwTqGUVcCVascCnTqtLJADMcYz7fPr6EfMpAycOePKTLLhsffzuHR7Ic6iq DUyD5VACAB9jm0CV7dysQHqKK4oiorsHmTcOtBcYblLDCAIKuH9UKsCoQ+EuRkHqIZYj dL2R1/G9L35dce7hwB8Dr5U2UkEVnDtth5wZRK3kbFeFw6bphkajAr+DuK0sy2bSYozv tNtQ== 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=9ZRI2V4YkYmTzd1dQqT/kJAE/uJLOLR2mC+eW9oKAkI=; b=UM+nje2jNsj2mlu/HYEYNLi2DgD5i0xFKWB1gBc7sMVUdAcUYaQdwVTifYI1jrKsRs o/09nDqi3vg7taTuOE0IqR4xdiQYDSlGlImu1oT2KvKOEaM/b/7gwewzTbeRH1ZqzIoY V/pXEoW27r4FHOoO0AZU9ywYFydZcFZCjWEJQk6P2fNxukV93TSNtSJI70B6DjVQ37cA CWDffyDDKmyoBTSwVf7eYk6TFapTOqt5wPftDYDAUHhCrUvR0L+olpV2hEie7XkEH6Vk t6Vit0VdRDaW6CwHSMPR4U0JXritOmXSbJvPACUdT3DfdNtzgrX1XFt+Zz+j/SxIdoTs qPXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dXoMrGfr; 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 e5-v6si5888599plt.209.2018.04.20.08.57.38; Fri, 20 Apr 2018 08:57:52 -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=dXoMrGfr; 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 S1755934AbeDTP4R (ORCPT + 99 others); Fri, 20 Apr 2018 11:56:17 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:37546 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755903AbeDTPz5 (ORCPT ); Fri, 20 Apr 2018 11:55:57 -0400 Received: by mail-pf0-f196.google.com with SMTP id p6so4484424pfn.4 for ; Fri, 20 Apr 2018 08:55:56 -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=9ZRI2V4YkYmTzd1dQqT/kJAE/uJLOLR2mC+eW9oKAkI=; b=dXoMrGfr3H+xHsqaMdFcwF9rjmXf7sj2J1pLnmORv2kNJYYugm67wCZUnl1rHAo9jx nhYqrjpGwb7pfQFN84NxTlu+fMXcIqo3IwJFVr5bIRKeEKEi/i3UIvi6vPHKoE0CLehV 6O03fLZXDmG5Romh3aQxzXWf8NlIZoaERCQO7EKWamdnNqtAc/oiR7lVfwkz3PN08XU7 kaRekijBQ/o1IRQEMW452lm7creW4TlsQxR2ZqnZ5h8KNzJ3+F0QJkBZs/xcsmbmR88s OvKNYKbzhGbIc1Dkmx9q6511KU0RPJY4OVjQXv7QJrDHpiwl0uG0fLyVqce9DIK4fLxF Rtww== 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=9ZRI2V4YkYmTzd1dQqT/kJAE/uJLOLR2mC+eW9oKAkI=; b=NqJb4F1ixk6uf6f7bi78m5itNt/u/oMe0gRAKt/0/uMoSSkrPV9Ba4PfkdtAVIexDM fa8VCqy8qrjhW86o4wZ1vUE0q+tyfDmJYS+tpfROnAc6axN3CoJ7B+gGvYvz4o9uDsGC vqDjFngjicXTRz4epWL0PGy21w3Iv5FtT88SMCISA0P2/KxhKExp4NWfNApEaY/0OCXw E55WmDOFs41qyxHThdNLPnXvOGHv9F6dKMzCXdYKKsOYt6weGjcD5YGQuGOTf8a20eSv PCN+x6VgOhrstkFglTqDPnJaoEAWEmkxIWT+UwcR879kRmeuBUD9lJ+KKuaxLr0Nz0lL CWeQ== X-Gm-Message-State: ALQs6tCco5mXVATjCQPBfUzuqmZuMbrh1JHeIHWYAOvHvDZAiQ1iDKnV UfOuGhNq8oMcOiBO7i8/0ULhTw== X-Received: by 10.99.163.77 with SMTP id v13mr4639719pgn.224.1524239755901; Fri, 20 Apr 2018 08:55:55 -0700 (PDT) Received: from localhost ([2620:15c:2c4:1:7e6f:1e60:1805:893c]) by smtp.gmail.com with ESMTPSA id x17sm11120179pfm.161.2018.04.20.08.55.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Apr 2018 08:55:54 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" Cc: netdev , linux-kernel , Soheil Hassas Yeganeh , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 4/4] tcp: mmap: move the skb cleanup to tcp_mmap_hook() Date: Fri, 20 Apr 2018 08:55:42 -0700 Message-Id: <20180420155542.122183-5-edumazet@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog In-Reply-To: <20180420155542.122183-1-edumazet@google.com> References: <20180420155542.122183-1-edumazet@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Freeing all skbs and sending ACK is time consuming. This is currently done while both current->mm->mmap_sem and socket lock are held, in tcp_mmap() Thanks to mmap_hook infrastructure, we can perform the cleanup after current->mm->mmap_sem has been released, thus allowing other threads to perform mm operations without delay. Note that the preparation work (building the array of page pointers) can also be done from tcp_mmap_hook() while mmap_sem has not been taken yet, but this is another independent change. Signed-off-by: Eric Dumazet --- net/ipv4/tcp.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e913b2dd5df321f2789e8d5f233ede9c2f1d5624..82f7c3e47253cecac6ea1819fbb7a0712058ec55 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1740,9 +1740,16 @@ int tcp_mmap_hook(struct socket *sock, enum mmap_hook mode) */ return 0; } - /* TODO: Move here the stuff that can been done after - * current->mm->mmap_sem has been released. - */ + if (mode == MMAP_HOOK_COMMIT) { + u32 offset; + + tcp_rcv_space_adjust(sk); + + /* Clean up data we have read: This will do ACK frames. */ + tcp_recv_skb(sk, tcp_sk(sk)->copied_seq, &offset); + + tcp_cleanup_rbuf(sk, PAGE_SIZE); + } release_sock(sk); return 0; } @@ -1843,13 +1850,8 @@ int tcp_mmap(struct file *file, struct socket *sock, if (ret) goto out; } - /* operation is complete, we can 'consume' all skbs */ + /* operation is complete, skbs will be freed from tcp_mmap_hook() */ tp->copied_seq = seq; - tcp_rcv_space_adjust(sk); - - /* Clean up data we have read: This will do ACK frames. */ - tcp_recv_skb(sk, seq, &offset); - tcp_cleanup_rbuf(sk, size); ret = 0; out: -- 2.17.0.484.g0c8726318c-goog