The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Schwartz <davids@webmaster.com>
To: <lk@tantalophile.demon.co.uk>
Cc: <gianni@ecsc.co.uk>, <linux-kernel@vger.kernel.org>
Subject: Re: TCP memory pressure question
Date: Fri, 22 Nov 2002 16:28:10 -0800	[thread overview]
Message-ID: <20021123002812.AAA5286@shell.webmaster.com@whenever> (raw)
In-Reply-To: <20021123000616.GB19162@bjl1.asuk.net>


On Sat, 23 Nov 2002 00:06:17 +0000, Jamie Lokier wrote:

>David Schwartz wrote:

>>So this would be a case where 'poll' or 'select' would return
>>a write hit for a socket but 'write' would return -1 and set errno
>>to EAGAIN.

>Is this really true?  It would livelock several servers I've worked on...
>
>-- Jamie

	We're now getting close to my motivation for asking this question.

	If it does in fact return EAGAIN, then a poll/select loop program that is 
trying to write could get into trouble if another process was responsible for 
large receive queues. It would spin uselessly burning its timeslice as more 
data comes in and it delays the execution of the other process that might be 
able to drain receive queues.

	On the other hand, if send blocked, there would be a disaster if a 
select/poll loop process were the only TCP user on the box. In this case, it 
would deadlock. The process is blocked waiting for memory but the only way to 
get that memory is for the process to get around to reading from other 
connections, which it can't do because it's blocked.

	My motivation in assessing what happens is to develop a sane application 
strategy to detect and handle this condition. If we could detect it, we could 
try not to do TCP writes and try to do reads to relieve the memory problem.

	Some strategies I was considering were this:

	1) For applications that probably aren't using most of the TCP memory: In 
the select/poll loop, we keep track of whether we were able to do any work. 
If we never successfully wrote or read, but did get a hit on at least one 
socket, we sleep for a few milliseconds. (We hope that while we sleep other 
applications can free up more memory for us by draining their receive 
queues.)

	2) For applications that probably are using all or a significant fraction of 
the TCP memory: If a 'write' for a socket that we got a write hit on returns 
EAGAIN, for the rest of this poll/select cycle, we do not attempt any writes, 
only reads. (We hope that this will relieve the memory pressure scenario and 
allow the system to function normally as quickly as possible.)

	3) For applications that have control over how much load they take: If 
writes begin returning EAGAIN under suspicious circumstances, treat this as 
an overload condition and trigger your handling logic. Refuse expensive 
commands or refuse to handle new connections.

	Any comments or suggestions are appreciated. I've found that when we hit TCP 
memory pressure, many applications become very badly behaved.

	DS



  reply	other threads:[~2002-11-23  0:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-21 21:34 TCP memory pressure question David Schwartz
2002-11-22 12:06 ` Gianni Tedesco
2002-11-22 20:28   ` David Schwartz
2002-11-23  0:06     ` Jamie Lokier
2002-11-23  0:28       ` David Schwartz [this message]
2002-11-23 22:34         ` Folkert van Heusden
2002-11-23 22:54           ` David Schwartz
  -- strict thread matches above, loose matches on Subject: below --
2002-11-22  1:27 Nivedita Singhvi
2002-11-22  9:18 ` Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021123002812.AAA5286@shell.webmaster.com@whenever \
    --to=davids@webmaster.com \
    --cc=gianni@ecsc.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lk@tantalophile.demon.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox