LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-10-2018, 01:57 PM   #1
fr483
LQ Newbie
 
Registered: Nov 2018
Posts: 8

Rep: Reputation: Disabled
How much time a write() system call is blocked in front of a full buffer, when using sockets?


Hello,

I have a doubt about how the Linux kernel manages UDP sockets. I'm actually using an embedded Linux distribution (OpenWrt; I was actually redirected from their forums to a more Linux kernel related forum) with kernel 4.14.63, but the same behavior can be obsverved also on Linux equipped notebooks communicating over a wireless network.

In particular, I wrote a C application using sockets to periodically send UDP datagrams out (and a corresponding receiver application).

When sending data over the socket I can use sendto() or write(). I noticed that if I try to write over a full UDP buffer (for instance if I try to write too much data with respect to what the wireless network can deliver), these calls are actually blocking my application.

But the question is: how long does the blocking time last? As far as I was able to observe, these calls seems to block for much more time with respect to what is required to free the space for a single packet, letting the buffer get emptied much more. This seeems to influence the packet drop in the kernel, before the WNIC, when trying to offer a large amount of data.

Does this depend on the Linux kernel scheduler? Does it depend on internal operations that copy packets from the UDP buffer towards the WNIC, maybe in blocks only?

The same behavior was also observed, in a better manner, when using the network measurement program iPerf: when sending UDP packets of 1470 B each, I observed that a write() in front of a full buffer would block for much more time, allowing to free up space for around 159.64 KB!

Moreover, setting a reasonable timeout on the socket seems to make the write() call block for less time (depending on the timeout value), since the timeout seems to actually expire, but without generating any error, as, at the expiration time instant, the space for way more than one packet was freed up.

Do you know why this is happening? Is it possible to have a write() which is unblocked without generating any error when the related timeout expires (as it seems to happen)?

Thank you very much in advance.
 
Old 11-11-2018, 04:42 PM   #2
kb2tfa
Member
 
Registered: Oct 2006
Location: New Jersey
Distribution: CentOS
Posts: 175

Rep: Reputation: 18
Quote:
Originally Posted by fr483 View Post
Hello,

When sending data over the socket I can use sendto() or write(). I noticed that if I try to write over a full UDP buffer (for instance if I try to write too much data with respect to what the wireless network can deliver), these calls are actually blocking my application.
It sounds like the the buffer is running out of space. You can try to increase the buffer tcpdump -B size-here-in-kilobytes.
 
Old 11-12-2018, 04:12 AM   #3
fr483
LQ Newbie
 
Registered: Nov 2018
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kb2tfa View Post
It sounds like the the buffer is running out of space. You can try to increase the buffer tcpdump -B size-here-in-kilobytes.
Sorry, probably I explained my doubt is an unclear manner... my doubt is actually not whether the buffer runs out of space or not (I know that it should run out of space since I'm offering too much traffic with respect to what my WNIC can physically manage - for instance with a 3 Mbit/s modulation I'm trying to offer 10 Mbit/s) but it is related to better undestand what happens when a write() call is invoked in front of a buffer without any space left: how much time does it block? Why 159.64 KB are freed up during the block time, when each packet has only 1470 B inside (at least when using UDP)? Is it possible that a timeout set on the socket expires without any kind of error just beacuse, when it expires, there's enough free space on the buffer for a 1470 B packet?

Thank you for you reply, anyway!
 
Old 11-12-2018, 08:27 AM   #4
kb2tfa
Member
 
Registered: Oct 2006
Location: New Jersey
Distribution: CentOS
Posts: 175

Rep: Reputation: 18
I got ya. I wasn't aware of the kernel performing a timeout. I thought the timeout you were referring to was the buffer running out of space.
 
Old 11-17-2018, 01:12 PM   #5
fr483
LQ Newbie
 
Registered: Nov 2018
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kb2tfa View Post
I got ya. I wasn't aware of the kernel performing a timeout. I thought the timeout you were referring to was the buffer running out of space.
Yes, I actually meant the time in which the application is blocked (due to the blocking write()) when it encounters a full buffer (it blocks for much more time with respect to the one needed to free up the memory for a single packet, as far as I understood, but I don't know the exact factors, inside the kernel, that are influencing this "blocking time"). Then, if I set a reasonable socket timeout (for instance with SO_SNDTIMEO in setsockopt()), I noticed that this time seems to be reduced, but without ever getting any error when it expires, probably due to the fact that the buffer is still freed up for more than the space a single packet would require?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
High read/write system call time ambadiaravind Linux - General 8 05-28-2015 11:27 PM
Sudden spike in write system call time Bharadwaj Programming 6 07-17-2012 10:06 AM
How do I write System call that returns a current time abhi1242 Linux - Newbie 3 09-26-2011 12:38 AM
how to write a system call which returns current system time using call by reference mukul2kul4 Debian 2 09-25-2011 11:17 PM
How to use write system call within a system call byteinnovator Linux - Kernel 18 08-05-2010 07:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration