1

I want to find out how the shared memory is used between the different processes running on a server and got the impression that the "ipcs -m" command can be used for this purpose. So when I try I get this:

# ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status 
0x0052e2c1 327680     postgres   600        66084708352 27

This is on a server which, besides postgresql, is also running tomcat, nginx, and some other programs. Why does no other process show up in the output?

1

The command ipcs -m will list memory used for inter-process communication, i.e. memory that is used by different processes to share data; this is commonly done when two processes need to pass data between them, because is more efficient than using a network socket or a named pipe; a typical usage scenario is a process connecting to a database running on the same machine, which seems to be exactly what is happening on your server.

Please note that in order to use shared memory, both processes need to do it explicitly; this is not something the OS does for them, it's a programming technique.

It's quite common for database servers to offer this connection option to its clients, exactly for those scenarios where both the client and the server are running on the same system; but why would f.e. Tomcat or Nginx (or any random program) want to use shared memory? To share what with who? They don't have any need for it. They are network servers which receive requests through network sockets.

TL;DR: you only see shared memory in use by PostgresSQL because it's the only program on your server which is using it.

4
  • Doesn't ipcs take into account shared pages that can be seen in /proc/<pid>/smaps? – user202323 Sep 17 '20 at 3:44
  • No, this has nothing to do with shared OS memory, like two processes loading the same library and the OS keeping a single copy of it in memory; ipcs is explicitly tied to inter-process communication, as its name implies. – Massimo Sep 17 '20 at 8:23
  • Anyway, I suggest you ask for more details on unix.stackexchange.com, where there are more experts on the inner working of Linux memory management. – Massimo Sep 17 '20 at 8:25
  • I understand it better now. Many thanks! – user202323 Sep 17 '20 at 10:19

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.