Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp107791pxb; Tue, 17 Aug 2021 20:37:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6E2aHFyO7XOgIhSDOIADXtOtb5iVTp42H493qYRudhGsPVB93icIsk4b2cf8IKz0ye90j X-Received: by 2002:a17:907:2bc1:: with SMTP id gv1mr7850008ejc.58.1629257863483; Tue, 17 Aug 2021 20:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629257863; cv=none; d=google.com; s=arc-20160816; b=lTmWcg3XF6xcqwNFJ0In/DBmm/IJ7G2SySWWSSU9K8DsptLMpB7Rn+ire7fMy+/fHC YvvrvJ0kqkkq3pBDd/18PehAICKYosDlihjI6f4r2qWIUZPrCQUa5bhopRVNYHvFpHWw 3o3g2sLGKv4P5WuhG2YP8GPY/rJcMTGbYifs2pTGI1/h++9WsPGg71BeeDjBYhGjiv2S ASu3I/rRTXn42jZhlKd8fZwyVImMJ8WXEL53iXtaHyyBq7pMb/p2jc4MMIjtyS4vW25y WY4VySmHl6MO3q8zeTO2oKRrJzpEB/UMW8Nt89p/HME4g9lgJ91a+k8sp7qnyODzDeZe zdIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=7h0l1YxqTr6t2K+xdzCy0pBxl8PHHLc9CuMCkhdZHd0=; b=U/vEjjyTtC3uqeJ3Q66KhdUon5CHWkg9DmoV+6of0xO1xJcwd/IdHaGnaCU7C1e3hl bTH0Jnw9M0YAhBtzSiwov9fh2axmk+gn7xN3mk78+tgCO7MJRRtTWfSYDlILyipU+v+q pdjqyrI6TN5gkdtL4YlPTPAbi8Hr4/3ew0LHgDNZ2cxS3TeCHUv5co+fjl1wifXjKoRW ydS89jZMXNxsJkWUcCwT1JD6an96YVOyu+qF/5OiVQMrWFzmjV3eEbJUZbDdeLhxZPdK fI+zAapDDIaQ7pB51fTh0v0faEGEDn8gf58QWuAAGT3djn4iamMU/Y6barFzmU8mOqer s9Dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si4757435edc.400.2021.08.17.20.37.20; Tue, 17 Aug 2021 20:37:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237687AbhHRDeh (ORCPT + 99 others); Tue, 17 Aug 2021 23:34:37 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:8874 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237271AbhHRDeY (ORCPT ); Tue, 17 Aug 2021 23:34:24 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GqD0n3445z8sZf; Wed, 18 Aug 2021 11:29:45 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 18 Aug 2021 11:33:29 +0800 Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 18 Aug 2021 11:33:28 +0800 From: Yunsheng Lin To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH RFC 5/7] sock: support refilling pfrag from pfrag_pool Date: Wed, 18 Aug 2021 11:32:21 +0800 Message-ID: <1629257542-36145-6-git-send-email-linyunsheng@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1629257542-36145-1-git-send-email-linyunsheng@huawei.com> References: <1629257542-36145-1-git-send-email-linyunsheng@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As previous patch has added pfrag pool based on the page pool, so support refilling pfrag from the new pfrag pool for tcpv4. Signed-off-by: Yunsheng Lin --- include/net/sock.h | 1 + net/core/sock.c | 9 +++++++++ net/ipv4/tcp.c | 34 ++++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 6e76145..af40084 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -455,6 +455,7 @@ struct sock { unsigned long sk_pacing_rate; /* bytes per second */ unsigned long sk_max_pacing_rate; struct page_frag sk_frag; + struct pfrag_pool *sk_frag_pool; netdev_features_t sk_route_caps; netdev_features_t sk_route_nocaps; netdev_features_t sk_route_forced_caps; diff --git a/net/core/sock.c b/net/core/sock.c index aada649..53152c9 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -140,6 +140,7 @@ #include #include +#include static DEFINE_MUTEX(proto_list_mutex); static LIST_HEAD(proto_list); @@ -1934,6 +1935,11 @@ static void __sk_destruct(struct rcu_head *head) put_page(sk->sk_frag.page); sk->sk_frag.page = NULL; } + if (sk->sk_frag_pool) { + pfrag_pool_flush(sk->sk_frag_pool); + kfree(sk->sk_frag_pool); + sk->sk_frag_pool = NULL; + } if (sk->sk_peer_cred) put_cred(sk->sk_peer_cred); @@ -3134,6 +3140,9 @@ void sock_init_data(struct socket *sock, struct sock *sk) sk->sk_frag.page = NULL; sk->sk_frag.offset = 0; + + sk->sk_frag_pool = kzalloc(sizeof(*sk->sk_frag_pool), sk->sk_allocation); + sk->sk_peek_off = -1; sk->sk_peer_pid = NULL; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index f931def..992dcbc 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -280,6 +280,7 @@ #include #include #include +#include /* Track pending CMSGs. */ enum { @@ -1337,12 +1338,20 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) if (err) goto do_fault; } else if (!zc) { - bool merge = true; + bool merge = true, pfrag_pool = true; int i = skb_shinfo(skb)->nr_frags; - struct page_frag *pfrag = sk_page_frag(sk); + struct page_frag *pfrag; - if (!sk_page_frag_refill(sk, pfrag)) - goto wait_for_space; + pfrag_pool_updata_napi(sk->sk_frag_pool, + READ_ONCE(sk->sk_napi_id)); + pfrag = pfrag_pool_refill(sk->sk_frag_pool, sk->sk_allocation); + if (!pfrag) { + pfrag = sk_page_frag(sk); + if (!sk_page_frag_refill(sk, pfrag)) + goto wait_for_space; + + pfrag_pool = false; + } if (!skb_can_coalesce(skb, i, pfrag->page, pfrag->offset)) { @@ -1369,11 +1378,20 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) if (merge) { skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); } else { - skb_fill_page_desc(skb, i, pfrag->page, - pfrag->offset, copy); - page_ref_inc(pfrag->page); + if (pfrag_pool) { + skb_fill_pp_page_desc(skb, i, pfrag->page, + pfrag->offset, copy); + } else { + page_ref_inc(pfrag->page); + skb_fill_page_desc(skb, i, pfrag->page, + pfrag->offset, copy); + } } - pfrag->offset += copy; + + if (pfrag_pool) + pfrag_pool_commit(sk->sk_frag_pool, copy, merge); + else + pfrag->offset += copy; } else { if (!sk_wmem_schedule(sk, copy)) goto wait_for_space; -- 2.7.4