locked
How to limit virtual memory size in Linux RRS feed

  • Question

  • User-1262787652 posted

    .NET 5 sample core application created using Visual Studio 2019 core template is running in VPS Debian server with Apache and proxy to kestrel. Linux x64 deploment mode was selected to increate startup speed so native linux x64 application (Store) was created.

    VPS has 12 GB of ram and swap file disabled. top shows that application (Store) can use 22 GB of virtual memory.

    Since swap is disabled using such amount of memory is not possible.

        > MiB Mem :  12288,0 total,   5297,8 free,   1234,3 used,   5755,9 buff/cache MiB 
        > Swap:      0,0 total,      0,0 free, 0,0 used.  10898,5 avail Mem
        >   PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+  COMMAND 
        > 27080 www-data  20   0   22,0g  70332  33532 S   0,0   0,6   0:02.02 /var/www/store5/Store
    

    Is it reasonable and if yes, how to limit .NET 5 application virtual memory size? There will be may applications in server so maximum allowed virtual memory should be about 2 GB for this application.

    I tried some times Apache benchmark

    ab -n 35000 -c 140 https://mysite.com/store5

    After that RES size has increased from 70MB to 120MB. It looks like .NET may try to allocate 22GB on RAM after some time if lot of requests are processed.

    Friday, December 25, 2020 11:33 AM

All replies

  • User-474980206 posted

    More likely you have a memory leak that you should fix. 

    Friday, December 25, 2020 3:20 PM
  • User753101303 posted

    Hi,

    A linux forum could be better. Try perhaps ulimit Man Page - Linux - SS64.com and the -v option or do you want to play with GC settings found at Garbage collector config settings - .NET | Microsoft Docs ?

    The basic idea behing the GC is already to grab/release memory when it makes sense (for example there is no need to spend time in releasing memory to the OS if you still have free memory available).

    So I would not spend time in trying to tune that unless seeing a real problem (maybe starting with monitoring first what happens).

    Edit: according to the previous link it seems that GC full collections are done when the memory load is beyond 90% of the physical memory.

    Friday, December 25, 2020 3:52 PM