X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Thu, 13 Dec 2007 18:59:34 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: VM and non-blocking writes Message-ID: <20071213175934.GB25863@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <47616D31 DOT 7090002 AT 4raccoons DOT com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47616D31.7090002@4raccoons.com> User-Agent: Mutt/1.5.16 (2007-06-09) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Dec 13 09:34, Wayne Christopher wrote: > I have a server application that runs on XP under the latest cygwin, that > opens up a socket connection to a client on another system, makes that > socket non-blocking using fcntl(.... O_NDELAY), and then feeds the client a > large file (100's of MBs) by doing the following: > > 1. call write() with the entire size of the data not yet written > > 2. the return value of write is the number of bytes actually written > (should be limited by the socket buffer size - it is on linux) > > 3. select() for writable status on the socket (and do other things in the > mean time) > > 4. when the socket becomes writable, goto 1 > > What I see is that no matter how large the size is that I give to write(), > the return value is always the full size. Also, I see the virtual memory > used by my process go way up - in fact it goes up by much more than the > amount of data I've written. > > I tried putting in a limit of 10KB in the size given to the write() call. > I still see the VM size grow - more slowly this time, but it eventually > reaches 1.5GB and then I'm out of memory. > > Has anybody seen this behavior? Should I not be using O_NDELAY? Any other > workarounds? I never saw this behaviour. Nonblocking sockets are no problem, usually. ssh is using them, too. A quick scan through the call chain (write -> writev -> sendmsg -> WSASendTo) doesn't show up any memory allocation which wouldn't be free'd again. Practically everything is done on the stack. The return code of write is an error code or the number of bytes written as returned by the WSASendTo function. If it really behaves as you describe, there would be nothing Cygwin could do about that. However, I'd expect that WSASendTo frequently returns SOCKET_ERROR with the error code set to WSAEWOULDBLOCK, which translates to a return code -1 from write with errno set to EAGAIN. Are you absolutely sure you're not wasting the memory yourself, somehow? Or, is it possible that there's a strange interaction with some piece of firewall or virus scanner? > I don't have a simple example program but I can make one if that will help. Yes, please. If it's actually a problem in Cygwin, it's occuring only in some border cases. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/