net/smc/smc_tx.c
Source file repositories/reference/linux-study-clean/net/smc/smc_tx.c
File Facts
- System
- Linux kernel
- Corpus path
net/smc/smc_tx.c- Extension
.c- Size
- 21719 bytes
- Lines
- 738
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/net.hlinux/rcupdate.hlinux/workqueue.hlinux/sched/signal.hnet/sock.hnet/tcp.hsmc.hsmc_wr.hsmc_cdc.hsmc_close.hsmc_ism.hsmc_tx.hsmc_stats.hsmc_tracepoint.h
Detected Declarations
function RDMAfunction smc_tx_sndbuf_nonfullfunction smc_tx_waitfunction smc_tx_is_corkedfunction sendmsgfunction smc_tx_should_corkfunction smc_tx_sendmsgfunction smcd_tx_ism_writefunction smc_tx_rdma_writefunction smc_tx_advance_cursorsfunction smcr_tx_rdma_writesfunction smcd_tx_rdma_writesfunction smc_tx_rdma_writesfunction smcr_tx_sndbuf_nonemptyfunction smcd_tx_sndbuf_nonemptyfunction smc_tx_sndbuf_nonemptyfunction smc_tx_pendingfunction smc_tx_workfunction smc_tx_consumer_updatefunction smc_tx_init
Annotated Snippet
if (smc_cdc_rxed_any_close(conn)) {
rc = -ECONNRESET;
break;
}
if (!timeo) {
/* ensure EPOLLOUT is subsequently generated */
set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
rc = -EAGAIN;
break;
}
if (signal_pending(current)) {
rc = sock_intr_errno(timeo);
break;
}
sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk);
if (atomic_read(&conn->sndbuf_space) && !conn->urg_tx_pend)
break; /* at least 1 byte of free & no urgent data */
set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
sk_wait_event(sk, &timeo,
READ_ONCE(sk->sk_err) ||
(READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN) ||
smc_cdc_rxed_any_close(conn) ||
(atomic_read(&conn->sndbuf_space) &&
!conn->urg_tx_pend),
&wait);
}
remove_wait_queue(sk_sleep(sk), &wait);
return rc;
}
static bool smc_tx_is_corked(struct smc_sock *smc)
{
struct tcp_sock *tp = tcp_sk(smc->clcsock->sk);
return (tp->nonagle & TCP_NAGLE_CORK) ? true : false;
}
/* If we have pending CDC messages, do not send:
* Because CQE of this CDC message will happen shortly, it gives
* a chance to coalesce future sendmsg() payload in to one RDMA Write,
* without need for a timer, and with no latency trade off.
* Algorithm here:
* 1. First message should never cork
* 2. If we have pending Tx CDC messages, wait for the first CDC
* message's completion
* 3. Don't cork to much data in a single RDMA Write to prevent burst
* traffic, total corked message should not exceed sendbuf/2
*/
static bool smc_should_autocork(struct smc_sock *smc)
{
struct smc_connection *conn = &smc->conn;
int corking_size;
corking_size = min_t(unsigned int, conn->sndbuf_desc->len >> 1,
sock_net(&smc->sk)->smc.sysctl_autocorking_size);
if (atomic_read(&conn->cdc_pend_tx_wr) == 0 ||
smc_tx_prepared_sends(conn) > corking_size)
return false;
return true;
}
static bool smc_tx_should_cork(struct smc_sock *smc, struct msghdr *msg)
{
struct smc_connection *conn = &smc->conn;
if (smc_should_autocork(smc))
return true;
/* for a corked socket defer the RDMA writes if
* sndbuf_space is still available. The applications
* should known how/when to uncork it.
*/
if ((msg->msg_flags & MSG_MORE ||
smc_tx_is_corked(smc)) &&
atomic_read(&conn->sndbuf_space))
return true;
return false;
}
/* sndbuf producer: main API called by socket layer.
* called under sock lock.
*/
int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
{
size_t copylen, send_done = 0, send_remaining = len;
size_t chunk_len, chunk_off, chunk_len_sum;
struct smc_connection *conn = &smc->conn;
union smc_host_cursor prep;
Annotation
- Immediate include surface: `linux/net.h`, `linux/rcupdate.h`, `linux/workqueue.h`, `linux/sched/signal.h`, `net/sock.h`, `net/tcp.h`, `smc.h`, `smc_wr.h`.
- Detected declarations: `function RDMA`, `function smc_tx_sndbuf_nonfull`, `function smc_tx_wait`, `function smc_tx_is_corked`, `function sendmsg`, `function smc_tx_should_cork`, `function smc_tx_sendmsg`, `function smcd_tx_ism_write`, `function smc_tx_rdma_write`, `function smc_tx_advance_cursors`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.