I was trying to optimize my Linux server to handle 10,000 threads per process while it does just 382 right now. As per this article the following formula is used to find out total possible threads:number of threads = total virtual memory / (stack size*1024*1024)This means threads store all their data in virtual memory. And to the best of my knowledge, virtual memory is swap space in a Linux machine which is stored on harddisk than RAM or cache. So my question is does our threads uses harddisk to store for processing/store its data. If yes, then doesnt this effect performance? Can we enhance the performance by putting in them on RAM or cache? How? If no, how exactly do threads works?Update:According to useless's answer, virtual memory is a system comprising roughly:physical memory (RAM)any swapfiles you have attachedhardware support for translating virtual to physical addresses andissuing page faults when a virtual address isn't available inphysical memory(kernel) software support for: managing the lookup tables used bythat hardware handling those page faults by pulling pages in fromswap on demandThus, Everything that is on virtual memory is collectively on RAM(Real Memory) and Hard Disk(Swap Files). And as James explain in his answer decision on Ram vs HDD is taken by Kernel using algorithims such as LRU. 
Do threads use virtual memory or real memory?
memory;thread
to the best of my knowledge, virtual memory is swap space in a Linux machineNope, virtual memory is a system comprising roughly:physical memory (RAM)any swapfiles you have attachedhardware support for translating virtual to physical addresses and issuing page faults when a virtual address isn't available in physical memory(kernel) software support for:managing the lookup tables used by that hardwarehandling those page faults by pulling pages in from swap on demandIt's up to the kernel to make sure the virtual memory you want is cached into RAM when you want it - unless you're writing your own userspace VM layer (such as databases often do, iiuc), just don't worry about it.