Skip to contentSkip to conversation

How many copies to get from NIC RX to user read()?

DISCUSSION [email protected] 2 participants 3 messages Jul 10, 2002

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines

I could've sworn I heard the stack was single-copy on both the TX and RX sides. But, it doesn't look to me like it is. Rather, it looks like there is one copy in tcp_rcv_estabilshed() (via tcp_copy_to_iovec()), and a second copy in tcp_recvmsg() (which is called when the user calls read()). Both of these copies are, I believe, done by skb_copy_datagram_iovec().

tcp_recvmsg() only does the copy from the receive_queue or the backlog queue. tcp_rcv_established() does the copy directly into the iovec or queues it onto the receive_queue or backlog queue for tcp_recvmsg() to complete the work. So there arent two copies of the same data happening, just a question of one or the other function doing the work depending on whether there is currently a process doing a read or not..

hth,

thanks,
Nivedita

#1 lore raw

So, to make sure I have this right:

When the data is processed from the NIC
tcp_rcv_established() is called in processing it
if a user process is waiting on the socket
iovec copy data to the user
else
copy it to receive_queue or backlog_queue

When the user tries read (in any way) a socket
iovec copy from receive_queue or backlog_queue

E.g., if the user is ready for the data, dump it straight from SKBs. Else, don't waste SKBs on a lazy (or busy) user and copy the data to a queue.

If this is right, I'm happy :) If it's wrong, please correct.

Thx,
--Gus

Quoted 23 lines · On Wed, 10 Jul 2002 [email protected] wrote:
Quoted 8 lines

I could've sworn I heard the stack was single-copy on both the TX and RX sides. But, it doesn't look to me like it is. Rather, it looks like there is one copy in tcp_rcv_estabilshed() (via tcp_copy_to_iovec()), and a second copy in tcp_recvmsg() (which is called when the user calls read()). Both of these copies are, I believe, done by skb_copy_datagram_iovec().

tcp_recvmsg() only does the copy from the receive_queue or the backlog queue. tcp_rcv_established() does the copy directly into the iovec or queues it onto the receive_queue or backlog queue for tcp_recvmsg() to complete the work. So there arent two copies of the same data happening, just a question of one or the other function doing the work depending on whether there is currently a process doing a read or not..

hth,

thanks,
Nivedita

#2 lore raw
Quoted 9 lines

So, to make sure I have this right:

When the data is processed from the NIC
tcp_rcv_established() is called in processing it
if a user process is waiting on the socket
iovec copy data to the user
else
copy it to receive_queue or backlog_queue

well, we append the skb to the tail of the queue. this is not a copy operation. (just a few instructions).

Quoted 8 lines

When the user tries read (in any way) a socket
iovec copy from receive_queue or backlog_queue

E.g., if the user is ready for the data, dump it straight from SKBs. Else,
don't waste SKBs on a lazy (or busy) user and copy the data to a queue.

yep.

Quoted 4 lines

If this is right, I'm happy :) If it's wrong, please correct.

Thx,
--Gus

I should add that my reading of the code is hardly authoritative :). caveat emptor...

thanks,
Nivedita