I have a system that is running out of memory and has a lot of open connections. but my swap space is not being used up that much.
Can socket/socket file descriptors use swap space?
This is for a linux system btw.
A socket does not use up a lot of memory: there's just a reference to the kernel structure and a couple of buffers in user-space. The kernel has to maintain a transmit and receive window for network sockets and a small buffer for filesystem sockets. But the existence of a socket implies some sort of communicating process with a code and data footprint. But you didn't say what the connections are.
There may be scope for addressing this depending on what state the sockets are in, what the sockets are doing and what processes have the sockets open but in the absence of a lot more information, its impossible to advise.
kubanczyk may be right - are you sure your memory is really all getting used up?
Regarding kernel swapping own memory: I'd go with kubanczyk's answer here. Regarding the overall question about running out of memory: make sure to run 'free' command and watch at '-/+ buffers/cache' line which will tell you more accurate information about an actual used/free memory.
Regarding the socket usage. Under heavy load (depending on your application of course) it can eat up quite some amount of your memory. Here is how you can calculate your current memory usage for your sockets:
It will probably tell you '4096' which is 4Kb. Now lets find out how many pages are used for current sockets:
You will get information about your current socket usage on the system, something like this (this is under heavy load):
sockets: used 250755 TCP: inuse 5 orphan 0 tw 0 alloc 250873 mem 895545 UDP: inuse 4 mem 2 UDPLITE: inuse 0 RAW: inuse 0 FRAG: inuse 0 memory 0
We are interested in "mem 895545" which tells us the amount of pages used. So to calculate memory usage for sockets on the box we multiply pagesize by this mem value:
4096 * 895545 ~= 3.5Gb