locked
App Domain is marked for unload due to memory pressure RRS feed

  • Question

  • I have a SQL Server 2008 R2 64 bit running on a Windows Server 2012 Server.  The box has 48 gigs of memory for SQL Server to run.  That is the only thing running on that server.

    I am seeing the error log full of messages saying that the App Domain (xxx) is marked for unload due to memory pressure.  I have done some research, and it seems to be related to using CLR code.  I am not using any CLR code other than the SQL Server Spacial objects.  I believe the server has plenty of memory to use, so I am not sure what is going on.

    I am also getting the error message "The app domain with specified version id (%d) was unloaded due to memory pressure and could not be found." in my applications.

    From what I can see, this seems to be related to SQL Server running in 32 bit mode and not having enough memory, but I am running the 64 bit version.

    I wonder if it may be due to SQL Server not using enough memory.  I have noticed that the memory used by SQL Server is close to 5 gigs.

    Below is a screen shot that shows how much memory is being used, and how much is available on the machine. 

    This next screen shot is the configuration values showing that SQL Server should be using as much memory as it likes.  I have about two dozen databases on this server, so I would expect it would use more.

    When looking at the log files for SQL Server, I see this memory error every few seconds, so this is happening all the time.

    Any suggestions?

    Friday, April 24, 2015 9:26 PM

Answers

  • I have changed the Min memory to 8 Gb, and the Max Memory to 41 Gb..

    I would say leave it to default value, unless you have specific reason to keep min server memory to 8 G


    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)   Apr  2 2010 15:48:46   Copyright (c) Microsoft Corporation  Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) .

    This is a blunder please ASAP apply SP3 for SQL Server 2008 R2. There are lots of fixes related to memory and my guess is SP3 would eventually solve this and many other problems.

    Revert after you have applied SP3.


    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

    My Technet Wiki Article

    MVP

    • Marked as answer by Ben Haynie Thursday, April 30, 2015 3:40 AM
    Tuesday, April 28, 2015 5:45 PM

All replies

  • Here is a screen shot of the Error Logs
    Friday, April 24, 2015 9:27 PM
  • Have a look at this blog post by SQL Server CSS Engineers and see if the workaround/resolution suggested at the end helps with the problem. http://blogs.msdn.com/b/psssql/archive/2013/01/30/appdomain-unloading-messages-flooding-the-sql-server-error-log.aspx

    In addition, SQL Server 2012 changed the way CLR memory was allocated by SQL Server, not sure if this would be helpful for the specific problem you mention, but you might consider testing a SQL Server 2012 instance to see if would help in future.

    Hope this helps, Bob 

    Friday, April 24, 2015 9:42 PM
  • Thank you.  I have set CLR Enabled to 1, and the article suggests that this should remove the error logs.  However, this does not resolve the issue.
    Friday, April 24, 2015 10:36 PM
  • Hi Ben,

    AppDomain xxxx is marked for unload due to memory pressure

    This KB article is also helpful even if your system is 64 bit, as described in the article, you may see the above error messages with SQL Server 2008 features which use SQL CLR internally, like spatial data types. You can ignore the error message if it doesn’t cause any serious issues in SQL Server.

    There is a similar thread for your reference.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/5f49e7af-3246-40e6-a1ce-7e74df77140c/appdomain-marked-for-unload-due-to-memory-pressure?forum=sqldatabaseengine


    Thanks,
    Lydia Zhang


    Lydia Zhang
    TechNet Community Support




    Monday, April 27, 2015 8:37 AM
  • Thank you for the response.  I guess my biggest concern is that all of the KB's and articles that I have read say that this may occur if there is memory pressure, and my server has more then enough memory to relieve any memory pressure (using 5 GB of 48 GB available on the server).  The error is occurring every few seconds, which seems excessive.  Do I have things configured correctly or does the frequency of the error indicate something else is going on.
    Monday, April 27, 2015 2:10 PM
  • Hi Ben,

    I am no expert on CLR and spatial data types but I can help you about SQL Server memory setting. Did you reffered to blog.msdn article posted by Bob. Many a times in 64 bit system these messages are harmless if they occur few times in error log.

    1. Starting from SQL Server 2012 the memory for CLR is allocated from Max server memory but in SQL Server 2008 R2 its still allocated from outside of the buffer pool. If you note you have not set max server memory for the SQL Server (see 2nd screenshot posted in your question). What might be happening is SQL Server buffer pool would be seeing all 48 G of memory and would be making allocation as per the available memory. Now this might cause memory crunch for applications whoes memory allocation is done outside of buffer pool like CLR in your case.

    2. Please set optimum value for max server memory. I would say if you have 48G of Total RAM set max server memory to 41 or 42G and leave 6 or 7 G for OS. Note this is just tentative value which you might want to change depending on how system behaves. You can refer to This Stackexchage Thread and see answer given by me(shanky) on how to configure optimum value. Changing max server memory setting does not requires restart of SQL server service.

    You can set max server memory value(in MB) in outlined box shown in below figure

    3. What is output of

    select @@Version
    --
    select * from sys.dm_os_process_memory

    4. Can you as well post complete errorlog. I might be able to help you better

    5. You were correct to say that app domain message was mostly a concern in 32 bit but it can also come in 64 bit system if you have incorrectly set value for max server memory.


    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

    My Technet Wiki Article

    MVP

    Tuesday, April 28, 2015 6:33 AM
  • Thank you so much for the response.

    I have changed the Min memory to 8 Gb, and the Max Memory to 41 Gb.

    The results of the query you gave me are:

    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)   Apr  2 2010 15:48:46   Copyright (c) Microsoft Corporation  Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) 

    physical_memory_in_use_kb 1921968
    large_page_allocations_kb 0
    locked_page_allocations_kb 0
    total_virtual_address_space_kb 137438953344
    virtual_address_space_reserved_kb 60728648
    virtual_address_space_committed_kb 2488552
    virtual_address_space_available_kb 137378224696
    page_fault_count 78909709
    memory_utilization_percentage 89
    available_commit_limit_kb 52748804
    process_physical_memory_low 0
    process_virtual_memory_low 0

    

    The logs are located at: https://www.dropbox.com/s/a8mnija7bs82hfn/DB01%20Logs.zip?dl=0

    Thank you again so much for your help, I truly appreciate it.

    Tuesday, April 28, 2015 3:08 PM
  • I have changed the Min memory to 8 Gb, and the Max Memory to 41 Gb..

    I would say leave it to default value, unless you have specific reason to keep min server memory to 8 G


    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)   Apr  2 2010 15:48:46   Copyright (c) Microsoft Corporation  Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) .

    This is a blunder please ASAP apply SP3 for SQL Server 2008 R2. There are lots of fixes related to memory and my guess is SP3 would eventually solve this and many other problems.

    Revert after you have applied SP3.


    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

    My Technet Wiki Article

    MVP

    • Marked as answer by Ben Haynie Thursday, April 30, 2015 3:40 AM
    Tuesday, April 28, 2015 5:45 PM
  • I'd agree with Shanky_621's assessment that you need to leave some memory free for SQLCLR (i.e. don't make max_server_memory infinite) in pre-SQL Server 2012.  SQLCLR UDT (like spatial types) can run out of memory (OOM) pre-2012, if you leave max_server_memory at infinite. SQL Server 2012 changes memory management WRT SQLCLR. There have also been some specific spatial queries that have been know to run SQL Server OOM, I'd also agree with having a look at installing the latest SP and maybe the latest CUs; there have been some spatial-specific fixes.   

    What's your non-spatial workload on the instance; is it only used for large spatial queries or are other large non-spatial workloads running at the same time? How many simultaneous large spatial queries are running in general?

    Cheers, Bob

    Tuesday, April 28, 2015 9:45 PM
  • Thank you again. I have removed the min memory (set it to 0) and I have installed SP3.  I have restarted SQL Server (the service not the machine), and the errors seem to have gone away.

    Thank you.

    Oddly enough, when I click on properties on the database, the memory used is still high.  I wonder if the OS hasn't released it all yet.  I will check again when I reboot the server.

    Thank you again!

    Thursday, April 30, 2015 3:40 AM
  • Oddly enough, when I click on properties on the database, the memory used is still high.  I wonder if the OS hasn't released it all yet.  I will check again when I reboot the server.

    Thank you again!

    That is because of default behavior of SQL Server. It uses as much memory as you provide to cache as much data and  other pages as possible to avoid any physical I/O and once this memory is consumed it wont be given back unless OS signals low memory notification flag. So don't worry if SQL Server is using memory its normal.

    Don't reboot the server, you would see after reboot SQL Server eventually taking same memory


    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

    My Technet Wiki Article

    MVP



    Thursday, April 30, 2015 4:08 AM