Question about 'top' values on memory usage, now threads

William LeFebvre bill at lefebvre.org
Mon Oct 15 09:43:50 PDT 2007


Artem Kuchin wrote:
> CPU is more than just enough in my case. There will a a lot https
> sitting there but load, i am sure, will be low.

If the load is low then you may not need very many processes.

> Swapping is simply unacceptable, so i am counting only real physical ram.

Whether there is actual swapping going on or not, processes will still 
need swap space.  There needs to be a backing store for every page 
that's in physical memory.  For text pages and untouched data pages, the 
backing store is the executable file itself.  For modified data pages 
there needs to be some place on disk to put a page when the virtual 
memory system decides it needs more physical pages.  This isn't really 
swapping: its reclaiming infrequently used physical pages when there is 
something else with a more immediate need, usually called a "page out". 
  When a modified data page is paged out it has to be written somewhere. 
  That somewhere is the swap area.  You can say "swapping is 
unacceptable" and that's fine.  But most systems will have page outs: 
its just a fact of life with virtual memory systems.  You can keep 
adding physical memory to minimize the number of page outs, and that 
sounds like what you want to do.  And its even possible to have 
sufficient physical memory to ensure all processes remain memory 
resident.  But without knowing the amount of shared virtual memory there 
is no easy way to determine the amount of physical memory you will need.

> 
> However, noone mentioned anything about threads. DO they give any memory
> advantage on freebsd?

Yes, threading within httpd should provide a big advantage.  The top 
output snippet you first posted indicates that you are not using 
threading yet (THR column is 1).  Multiple threads in the same process 
will share the same text and data pages, but will have their own stacks. 
  There may be some data memory overhead in the pthreads library (and 
within the program itself) to track all the threads, but I believe it 
will be small compared to the extra memory that additional processes 
would use.  Of course there will be additional stack space required. 
Finding this overhead is actually easy.  Just compare a process's SIZE 
when running with one thread and again when running multiple threads.

Bill LeFebvre



More information about the freebsd-stable mailing list