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.


  • you really should be posting some detail on how you came to the conclusion that it is running out of memory. – the-wabbit Dec 16 '11 at 9:08
  • web server has malloc errors. stating that it is out of memory.... – grassbl8d Dec 18 '11 at 4:32

Running out of memory but not much swap used? I guess this is the case of linuxatemyram.com as in this question.

After a quick web search it seems that Linux kernel is not paging (swapping) its own memory at all, which would include also socket descriptors.

  • i sort of understand that already... i'm just concerned about socket file descriptors vs other file descriptors. thanks – grassbl8d Dec 16 '11 at 8:53

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?

  • my web server has out of memory in its logs. it cant allocate additional memory. one thing though, system performed very poorly. my system memory wasnt eaten up but memory was around 90% usage. – grassbl8d Dec 17 '11 at 12:30
  • What logs? The lack of memory may be within a ulimit or config constrained process while you've still got lots of available memory...."in the absence of a lot more information....". The term "system memory" applies to the kernel and its data structures - if it is using 90% of capacity there's something very wrong here. – symcbean Dec 19 '11 at 10:18

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:

getconf PAGESIZE

It will probably tell you '4096' which is 4Kb. Now lets find out how many pages are used for current sockets:

cat /proc/net/sockstat

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.