[THIN] KB: CTX106023 - Virtual Memory Optimization Feature FAQ

  • From: "Jim Kenzig http://thethin.net" <jimkenz@xxxxxxxxxxxxxx>
  • To: thin@xxxxxxxxxxxxx
  • Date: Thu, 19 May 2005 18:39:30 -0700 (PDT)

CTX106023 - Virtual Memory Optimization Feature 

This document was published at: 
http://support.citrix.com/kb/entry.jspa?externalID=CTX106023 


Document ID: CTX106023, Created on: Apr 25, 2005, Updated: May 17, 2005 
Products: Citrix Presentation Server 4.0 for Microsoft Windows 2000, Citrix 
Presentation Server 4.0 for Microsoft Windows 2003 
 
Summary

Virtual Memory Optimization is a new feature in MetaFrame Presentation Server 
4.0. The following questions and answers will explain the benefits and inner 
workings of the feature.

Q:  What is Virtual Memory Optimization? 

It is a MetaFrame Presentation Server 4.0 feature designed to decrease Virtual 
Memory consumption of applications and improve application initialization time.

Q:  What Edition of MetaFrame supports this feature?

MetaFrame Presentation Server 4.0 Enterprise Edition with an Enterprise Edition 
license file on the license server.

Q:  Why is this feature necessary?

DLLs are designed to be shared by all applications, so that only one instance 
of a DLL is needed in memory (RAM) regardless of how many applications are 
using that DLL. When an application initializes and loads its DLL into its view 
of memory (the virtual memory), there is a chance that the base memory address 
where it is attempting to load that DLL may already be occupied by another DLL. 
This event of attempting to load two DLLs at the same base memory address is 
called a collision. When a collision occurs the DLL has to be relocated to an 
available base memory address. When this occurs, the DLL can no longer be 
shared by other applications, and hence this takes up more actual memory, which 
also increases the amount of paging that the system must do and slows down 
overall performance. The loader then has to update all the hard-coded pointers 
in the DLL to reflect the new base address, which slows application load-time. 

Q:  What files and executables are used with this feature and where are they 
located?

All files related to this feature are located in Program Files\Citrix\Server 
Resource Management\Memory Optimization Management. Below is a description of 
these files:

? CtxSFOsvc.exe - Monitors all DLLs on a server to find where collisions are 
occurring

? CtxBace.exe - Optimizes the DLLs that are having trouble by calculating a new 
bases memory address and copying and changing the DLL to load at that address.

? CtxTest.DLL - Responsible for testing all DLLs that have been modified to 
make sure that they still work

? Repair.SFO - This is an XML file that has information about problematic DLLs 
found on a system that are to be modified by the CtxBace.exe process.

? Bind ####.SFO - Log files that list the DLLs that were optimized and how much 
virtual memory was saved because of the optimization

Q:  How does Virtual Memory Optimization work?

1. The feature is enabled in the Presentation Server Console under the farm or 
server properties in the Memory/CPU Utilization Management section. Once the 
feature is enabled, the Citrix Virtual Memory Optimization service is started 
automatically. If the feature is disabled the service will stop automatically.

2. Once the feature is enabled, the Citrix Virtual Memory Optimization service, 
which is tied to the CtxSFOSvc.exe process, monitors all DLLs on the system to 
find out where DLL collisions and relocation are occurring. It writes the name 
of these DLLs to a file called Repair.sfo located in Program 
Files\Citrix\Server Resource Management\Memory Optimization Management\Data.

3. At a scheduled time every day and during system startup, CtxBace.exe reads 
the Repair.sfo file and optimizes the DLL to prevent collisions from occurring 
the next time the DLL is loaded. 

4. After CtxBace.exe optimizes the DLL, CtxTestDLL.exe loads the DLL to ensure 
that the DLL is still functional.

5. Other than rebasing DLLs, the optimization process also involves Binding 
executables to make application initialization time faster.

Q:  What is DLL Rebasing?

Rebasing changes a DLL so that it loads at an optimal base memory address to 
avoid collisions and relocations.

Q:  What is Binding?

In order to explain what the Binding process does, here is a bit of background 
on how applications work. When an application initializes, the executable loads 
various DLLs that it needs at run-time. DLLs export functions that are made 
available to the application executable. However, in order for the executable 
to make use of a DLLs exported functions, it needs to look at the export table 
of that DLL to find the memory address where the functions are located. 

The Binding process modifies the executable so that it has the memory address 
of these functions in advance. By having the address of these functions in 
advance, the executable doesn?t have to read the DLLs export table. It just 
loads the DLL and goes directly to the memory address of that function at 
run-time.

Q:  When does the actual optimization process occur?

The optimization occurs when the Ctxbace.exe process is running. That process 
can be seen in Task Manager. This process runs once when scheduled then exits. 
It can be configured to run at a specified time in the Presentation Server 
Console under farm properties, Memory Optimization. By default the process is 
scheduled to run under the system account but it can be modified to run under 
another account in the Console.

Q:  What is actually occurring during the optimization process?

After the Ctxbace.exe process reads the Repair.SFO file to see which DLLs to 
optimize, it makes a temporary copy of the DLL, calculates a potential safe 
base memory address, the CtxTestDLL program loads the new modified DLL to make 
sure it still works, then Ctxbace places the new modified DLL into an Alternate 
Data Stream of the original file. The original DLL is unchanged.

Q:  What is the Repair.sfo file used for?

Repair.sfo is an XML file that is written to, by the Citrix Virtual Memory 
Optimization service (CtxSFOSvc.exe). This file contains a list of all .exes 
and DLLs that are to be optimized. It is located in [Program 
Files\Citrix\Server Resource Management\Memory Optimization Management\Data].

Q:  What is an Alternate Data Stream?

They are hidden files that are attached to visible ones. The size of the 
original file stays the same the only thing that changes is the modified date 
of the original file. The optimization process makes a copy of the original 
file, changes the base address on the copy and puts the modified copy into an 
Alternate Data Stream attached to the original file.

Q:  How does the operating system determine whether to load the original file 
or the modified file located in the Alternate Data Stream?

There is a new file filter driver that is added to MPS4.0 called CtxAltStr.sys 
located in [Program Files\Citrix\Server Resource Management\Memory Optimization 
Management\System32\Drivers ]. This file filter driver intercepts all calls to 
the file system. The driver checks to see if an Alternate Data Stream has been 
added to the file and if so it sends the alternate data stream back to the 
Operating System.

Q:  What if an application is affected by this feature? 

If an application is not functioning correctly after being optimized by this 
feature it can be placed on the application exclusion list. The exclusion list 
is located in the Presentation Server Console under the farm properties in the 
Memory Optimization section. All applications placed on the exclusion list will 
be in the registry of each server under HKEY_LOCAL_MACHINE\ SOFTWARE\ Citrix\ 
SFO <ComponentExclusionList> or <ProcessExclusionList>. If you do not want to 
have the feature optimize a particular application it can also be placed on 
this list.

Q:  Is there a list of applications that will not work with this feature? 

While there may be other applications that do not work with this feature, the 
default exclusion list contains all known applications and DLLs that have been 
problematic in the past. This default exclusion list is in the registry 
location mentioned above.

Q:  Are there are types of applications that this feature is not designed to 
work with?

Yes. Applications that have digitally signed components, applications whose 
DLLs are protected by Windows Rights Management, and any application whose 
executable programmatically checks the DLL after it has been loaded.

Q:  If I stop the Citrix Virtual Memory Optimization process can that stop the 
optimization if it is has already begun? 

No. This service is only monitoring the DLLs on the system and writing the name 
of the problematic .exe and DLL to the Repair.sfo file. Once they have been 
written to the Repair.sfo file when the Ctxbace.exe process runs it will 
optimize what is in the file. By stopping the service you are only stopping any 
future writes to the Repair.sfo file.

Q:  How often should the optimization process run?

It is best to configure the optimization to run daily at an off peak time. You 
can configure this in the Presentation Server Console under Farm properties > 
Memory Optimization.

Q:  Are there any log files that tell what DLLs or executables have been 
optimized?

Yes. After every optimization a log file is created that reports everything 
that was optimized or attempted to be optimized during the last optimization 
session. The file is called ?Bind 38415.696366.SFO? and is located in [Program 
Files\Citrix\Server Resource Management\Memory Optimization 
Management\Data\Archive]. They allow an administrator to see for themselves how 
much savings each application or DLL gets them when it is rebased. There can be 
numerous log files created in this directory over time. They can be deleted or 
archived to another located to save disk space.

Q:  Is the Citrix Virtual Memory Optimization service dependent on the IMA 
service?

The ?Citrix Virtual Memory Optimization? is stopped and started by the IMA 
service. When looking at the properties of the service in the Services Manager 
you will see that it is set to manual because it is controlled by the IMA 
service. However if the IMA service fails to start the ?Citrix Virtual Memory 
Optimization? will not be automatically started either. The service can be 
manually started in the Services manager. If you restart the IMA service it 
will not restart the ?Citrix Virtual Memory Optimization? service.

Q:  How can you tell how much virtual memory has been saved by the Virtual 
Memory Optimization feature? 

An administrator can use the Report Center in the Access Suite Console to 
create run a Virtual Memory optimization report that details how much virtual 
memory has been saved by using this feature. This report does not require a 
connection to a summary database. It pulls its information from the Bind 
######.sfo log files located in the \Archive directory.

Q:  Is there a list of applications that are compatible with this feature and 
the expected Virtual Memory savings listed anywhere? 

Yes. See article CTX106022 ? Virtual Memory Optimization Feature Application 
Compatibility List.

http://support.citrix.com/kb/entry.jspa?entryID=6386


Other related posts:

  • » [THIN] KB: CTX106023 - Virtual Memory Optimization Feature FAQ