Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
12 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Per-Class Memory Management
  6. File: Memcls.cpp
  7. Owner: dmitryr
  8. This file contains the code to access ATQ memory cache on per
  9. class basis
  10. ===================================================================*/
  11. #include "denpre.h"
  12. #pragma hdrstop
  13. #include "asperror.h"
  14. #include "clcert.h"
  15. #include "context.h"
  16. #include "cookies.h"
  17. #include "request.h"
  18. #include "response.h"
  19. #include "server.h"
  20. #include "strlist.h"
  21. #include "tlbcache.h"
  22. #include "memcls.h"
  23. // Don't #include "memchk.h" in this file
  24. /*===================================================================
  25. DEBUG only
  26. gs_cTotalObjectsLeaked counts memory leaks
  27. DebugCheckLeaks() outputs the ATQ cache memory
  28. leaks into denmem.log
  29. DEBUG_ACACHE_UNINIT() and DEBUG_ACACHE_FSA_UNINIT() call
  30. DebugCheckLeaks() in DEBUG mode only
  31. ===================================================================*/
  32. #ifdef DBG
  33. static DWORD gs_cTotalObjectsLeaked = 0;
  34. #define SZ_MEMCLS_LOG_FILE "C:\\TEMP\\MEMCLS.LOG"
  35. static void DebugCheckLeaks(ALLOC_CACHE_HANDLER *pach, const char *szClass)
  36. {
  37. ALLOC_CACHE_STATISTICS acStats;
  38. pach->QueryStats(&acStats);
  39. DWORD cLeaked = acStats.nTotal - acStats.nFreeEntries;
  40. if (cLeaked > 0)
  41. {
  42. gs_cTotalObjectsLeaked += cLeaked;
  43. DebugFilePrintf
  44. (
  45. SZ_MEMCLS_LOG_FILE,
  46. "MEMCLS: ATQ allocation cache leak: %d of %s objects.\n",
  47. cLeaked,
  48. szClass
  49. );
  50. }
  51. }
  52. #define DEBUG_ACACHE_UNINIT(C) { DebugCheckLeaks(C::sm_pach, #C); \
  53. ACACHE_UNINIT(C) }
  54. #define DEBUG_ACACHE_FSA_UNINIT(C) { DebugCheckLeaks(g_pach##C, #C); \
  55. ACACHE_FSA_UNINIT(C) }
  56. #else
  57. #define DEBUG_ACACHE_UNINIT(C) ACACHE_UNINIT(C)
  58. #define DEBUG_ACACHE_FSA_UNINIT(C) ACACHE_FSA_UNINIT(C)
  59. #endif
  60. /*===================================================================
  61. For each class with ACACHE_INCLASS_DEFINITIONS() inside add
  62. here ACACHE_CODE macro.
  63. ===================================================================*/
  64. ACACHE_CODE(C449Cookie)
  65. ACACHE_CODE(C449File)
  66. ACACHE_CODE(CASEElem)
  67. ACACHE_CODE(CActiveScriptEngine)
  68. ACACHE_CODE(CAppln)
  69. ACACHE_CODE(CApplnVariants)
  70. ACACHE_CODE(CASPError)
  71. ACACHE_CODE(CAsyncVectorSendCB)
  72. ACACHE_CODE(CClCert)
  73. ACACHE_CODE(CComponentCollection)
  74. ACACHE_CODE(CComponentObject)
  75. ACACHE_CODE(CCookie)
  76. ACACHE_CODE(CDebugResponseBuffer)
  77. ACACHE_CODE(CEngineDispElem)
  78. ACACHE_CODE(CFileApplnList)
  79. ACACHE_CODE(CHitObj)
  80. ACACHE_CODE(CHTTPHeader)
  81. ACACHE_CODE(CIsapiReqInfo)
  82. ACACHE_CODE(CPageComponentManager)
  83. ACACHE_CODE(CPageObject)
  84. ACACHE_CODE(CRequest)
  85. ACACHE_CODE(CRequestData)
  86. ACACHE_CODE(CRequestHit)
  87. ACACHE_CODE(CResponse)
  88. ACACHE_CODE(CResponseBuffer)
  89. ACACHE_CODE(CResponseBufferSet)
  90. ACACHE_CODE(CResponseData)
  91. ACACHE_CODE(CScriptingNamespace)
  92. ACACHE_CODE(CScriptingContext)
  93. ACACHE_CODE(CServer)
  94. ACACHE_CODE(CServerData)
  95. ACACHE_CODE(CSession)
  96. ACACHE_CODE(CSessionVariants)
  97. ACACHE_CODE(CStringList)
  98. ACACHE_CODE(CStringListElem)
  99. ACACHE_CODE(CTemplate)
  100. //ACACHE_CODE(CTemplate::CBuffer)
  101. ACACHE_CODE(CTemplate::CFileMap)
  102. ACACHE_CODE(CTypelibCacheEntry)
  103. ACACHE_CODE(CVariantsIterator)
  104. ACACHE_CODE(CViperActivity)
  105. ACACHE_CODE(CViperAsyncRequest)
  106. /*===================================================================
  107. For each fixed size allocator add here ACACHE_FSA_DEFINITION macro.
  108. ===================================================================*/
  109. ACACHE_FSA_DEFINITION(MemBlock128)
  110. ACACHE_FSA_DEFINITION(MemBlock256)
  111. ACACHE_FSA_DEFINITION(ResponseBuffer)
  112. /*===================================================================
  113. Defines for cache threshold of each kind
  114. ===================================================================*/
  115. #define HARDCODED_PER_APPLN_CACHE_MAX 128
  116. #define HARDCODED_PER_REQUEST_CACHE_MAX 1024
  117. #define HARDCODED_PER_QUEUEITEM_CACHE_MAX 8192
  118. #define HARDCODED_PER_SESSION_CACHE_MAX 8192
  119. #define HARDCODED_PER_SCRPTENG_CACHE_MAX 256
  120. #define HARDCODED_PER_TEMPLATE_CACHE_MAX 2048
  121. #define HARDCODED_PER_RESPONSE_BUFFER_MAX 64
  122. #define HARDCODED_PER_SIZE_BUFFER_MAX 4096
  123. // do scaling per registry setting
  124. DWORD dwMemClsScaleFactor;
  125. #define PER_APPLN_CACHE_MAX ((HARDCODED_PER_APPLN_CACHE_MAX * dwMemClsScaleFactor) / 100)
  126. #define PER_REQUEST_CACHE_MAX ((HARDCODED_PER_REQUEST_CACHE_MAX * dwMemClsScaleFactor) / 100)
  127. #define PER_QUEUEITEM_CACHE_MAX ((HARDCODED_PER_QUEUEITEM_CACHE_MAX * dwMemClsScaleFactor) / 100)
  128. #define PER_SESSION_CACHE_MAX ((HARDCODED_PER_SESSION_CACHE_MAX * dwMemClsScaleFactor) / 100)
  129. #define PER_SCRPTENG_CACHE_MAX ((HARDCODED_PER_SCRPTENG_CACHE_MAX * dwMemClsScaleFactor) / 100)
  130. #define PER_TEMPLATE_CACHE_MAX ((HARDCODED_PER_TEMPLATE_CACHE_MAX * dwMemClsScaleFactor) / 100)
  131. #define PER_RESPONSE_BUFFER_MAX ((HARDCODED_PER_RESPONSE_BUFFER_MAX * dwMemClsScaleFactor) / 100)
  132. #define PER_SIZE_BUFFER_MAX ((HARDCODED_PER_SIZE_BUFFER_MAX * dwMemClsScaleFactor) / 100)
  133. /*===================================================================
  134. InitMemCls
  135. To be called from DllInit(). Creates per-class ATQ memory allocators.
  136. For each class with ACACHE_INCLASS_DEFINITIONS() inside add
  137. here ACACHE_INIT macro.
  138. For each ACACHE_FSA_DEFINITION() add here ACACHE_FSA_INIT macro.
  139. Parameters
  140. Returns:
  141. HRESULT
  142. ===================================================================*/
  143. HRESULT InitMemCls()
  144. {
  145. // Set the scaling to normal
  146. dwMemClsScaleFactor = 100;
  147. // Init the allocators
  148. HRESULT hr = S_OK;
  149. ACACHE_INIT(C449Cookie, PER_TEMPLATE_CACHE_MAX/4, hr)
  150. ACACHE_INIT(C449File, PER_TEMPLATE_CACHE_MAX/4, hr)
  151. ACACHE_INIT(CASEElem, PER_SCRPTENG_CACHE_MAX, hr)
  152. ACACHE_INIT(CActiveScriptEngine, PER_SCRPTENG_CACHE_MAX, hr)
  153. ACACHE_INIT_EX(CAppln, PER_APPLN_CACHE_MAX, FALSE, hr)
  154. ACACHE_INIT(CApplnVariants, PER_REQUEST_CACHE_MAX, hr)
  155. ACACHE_INIT(CASPError, PER_RESPONSE_BUFFER_MAX,hr)
  156. ACACHE_INIT(CAsyncVectorSendCB, PER_REQUEST_CACHE_MAX, hr)
  157. ACACHE_INIT(CClCert, PER_REQUEST_CACHE_MAX, hr)
  158. ACACHE_INIT(CComponentCollection, PER_SESSION_CACHE_MAX, hr)
  159. ACACHE_INIT(CComponentObject, 2*PER_SESSION_CACHE_MAX, hr)
  160. ACACHE_INIT(CCookie, PER_REQUEST_CACHE_MAX, hr)
  161. ACACHE_INIT(CDebugResponseBuffer, PER_REQUEST_CACHE_MAX, hr)
  162. ACACHE_INIT(CEngineDispElem, PER_REQUEST_CACHE_MAX, hr)
  163. ACACHE_INIT(CFileApplnList, 2*PER_APPLN_CACHE_MAX, hr)
  164. ACACHE_INIT(CHitObj, PER_QUEUEITEM_CACHE_MAX,hr)
  165. ACACHE_INIT(CHTTPHeader, 2*PER_REQUEST_CACHE_MAX, hr)
  166. ACACHE_INIT(CIsapiReqInfo, PER_QUEUEITEM_CACHE_MAX,hr)
  167. ACACHE_INIT(CPageComponentManager, PER_QUEUEITEM_CACHE_MAX,hr)
  168. ACACHE_INIT(CPageObject, PER_REQUEST_CACHE_MAX, hr)
  169. ACACHE_INIT(CRequest, PER_SESSION_CACHE_MAX, hr)
  170. ACACHE_INIT(CRequestData, PER_REQUEST_CACHE_MAX, hr)
  171. ACACHE_INIT(CRequestHit, PER_REQUEST_CACHE_MAX, hr)
  172. ACACHE_INIT(CResponse, PER_SESSION_CACHE_MAX, hr)
  173. ACACHE_INIT(CResponseBuffer, PER_REQUEST_CACHE_MAX, hr)
  174. ACACHE_INIT(CResponseBufferSet, PER_REQUEST_CACHE_MAX, hr)
  175. ACACHE_INIT(CResponseData, PER_REQUEST_CACHE_MAX, hr)
  176. ACACHE_INIT(CScriptingContext, PER_SESSION_CACHE_MAX, hr)
  177. ACACHE_INIT(CScriptingNamespace, PER_SESSION_CACHE_MAX, hr)
  178. ACACHE_INIT(CServer, PER_SESSION_CACHE_MAX, hr)
  179. ACACHE_INIT(CServerData, PER_REQUEST_CACHE_MAX, hr)
  180. ACACHE_INIT_EX(CSession, PER_SESSION_CACHE_MAX, FALSE, hr)
  181. ACACHE_INIT(CSessionVariants, PER_REQUEST_CACHE_MAX, hr)
  182. ACACHE_INIT(CStringList, PER_REQUEST_CACHE_MAX, hr)
  183. ACACHE_INIT(CStringListElem, 2*PER_REQUEST_CACHE_MAX, hr)
  184. ACACHE_INIT(CTemplate, PER_TEMPLATE_CACHE_MAX, hr)
  185. // ACACHE_INIT(CTemplate::CBuffer, PER_TEMPLATE_CACHE_MAX, hr)
  186. ACACHE_INIT(CTemplate::CFileMap, PER_TEMPLATE_CACHE_MAX, hr)
  187. ACACHE_INIT(CTypelibCacheEntry, PER_REQUEST_CACHE_MAX, hr)
  188. ACACHE_INIT(CVariantsIterator, PER_REQUEST_CACHE_MAX, hr)
  189. ACACHE_INIT(CViperActivity, PER_REQUEST_CACHE_MAX, hr)
  190. ACACHE_INIT(CViperAsyncRequest, PER_QUEUEITEM_CACHE_MAX,hr)
  191. ACACHE_FSA_INIT(MemBlock128, 128, PER_SIZE_BUFFER_MAX, hr)
  192. ACACHE_FSA_INIT(MemBlock256, 256, PER_SIZE_BUFFER_MAX, hr)
  193. ACACHE_FSA_INIT(ResponseBuffer, RESPONSE_BUFFER_SIZE, PER_RESPONSE_BUFFER_MAX, hr)
  194. #ifdef DBG
  195. unlink(SZ_MEMCLS_LOG_FILE);
  196. DebugFilePrintf
  197. (
  198. SZ_MEMCLS_LOG_FILE,
  199. "MEMCLS: ATQ allocation cache inited with HRESULT=%08x.\n",
  200. hr
  201. );
  202. #endif
  203. return hr;
  204. }
  205. /*===================================================================
  206. UnInitMemCls
  207. To be called from DllInit(). Deletes per-class ATQ memory allocators.
  208. For each class with ACACHE_INCLASS_DEFINITIONS() inside add
  209. here ACACHE_UNINIT macro.
  210. For each ACACHE_FSA_DEFINITION() add here ACACHE_FSA_UNINIT macro.
  211. Parameters
  212. Returns:
  213. HRESULT
  214. ===================================================================*/
  215. HRESULT UnInitMemCls()
  216. {
  217. #ifdef DBG
  218. gs_cTotalObjectsLeaked = 0;
  219. #endif
  220. DEBUG_ACACHE_UNINIT(C449Cookie)
  221. DEBUG_ACACHE_UNINIT(C449File)
  222. DEBUG_ACACHE_UNINIT(CASEElem)
  223. DEBUG_ACACHE_UNINIT(CActiveScriptEngine)
  224. DEBUG_ACACHE_UNINIT(CAppln)
  225. DEBUG_ACACHE_UNINIT(CApplnVariants)
  226. DEBUG_ACACHE_UNINIT(CASPError)
  227. DEBUG_ACACHE_UNINIT(CAsyncVectorSendCB)
  228. DEBUG_ACACHE_UNINIT(CClCert)
  229. DEBUG_ACACHE_UNINIT(CComponentCollection)
  230. DEBUG_ACACHE_UNINIT(CComponentObject)
  231. DEBUG_ACACHE_UNINIT(CCookie)
  232. DEBUG_ACACHE_UNINIT(CDebugResponseBuffer)
  233. DEBUG_ACACHE_UNINIT(CEngineDispElem)
  234. DEBUG_ACACHE_UNINIT(CFileApplnList)
  235. DEBUG_ACACHE_UNINIT(CHitObj)
  236. DEBUG_ACACHE_UNINIT(CHTTPHeader)
  237. DEBUG_ACACHE_UNINIT(CIsapiReqInfo)
  238. DEBUG_ACACHE_UNINIT(CPageComponentManager)
  239. DEBUG_ACACHE_UNINIT(CPageObject)
  240. DEBUG_ACACHE_UNINIT(CRequest)
  241. DEBUG_ACACHE_UNINIT(CRequestData)
  242. DEBUG_ACACHE_UNINIT(CRequestHit)
  243. DEBUG_ACACHE_UNINIT(CResponse)
  244. DEBUG_ACACHE_UNINIT(CResponseBuffer)
  245. DEBUG_ACACHE_UNINIT(CResponseBufferSet)
  246. DEBUG_ACACHE_UNINIT(CResponseData)
  247. DEBUG_ACACHE_UNINIT(CScriptingNamespace)
  248. DEBUG_ACACHE_UNINIT(CScriptingContext)
  249. DEBUG_ACACHE_UNINIT(CServer)
  250. DEBUG_ACACHE_UNINIT(CServerData)
  251. DEBUG_ACACHE_UNINIT(CSession)
  252. DEBUG_ACACHE_UNINIT(CSessionVariants)
  253. DEBUG_ACACHE_UNINIT(CStringList)
  254. DEBUG_ACACHE_UNINIT(CStringListElem)
  255. DEBUG_ACACHE_UNINIT(CTemplate)
  256. // DEBUG_ACACHE_UNINIT(CTemplate::CBuffer)
  257. DEBUG_ACACHE_UNINIT(CTemplate::CFileMap)
  258. DEBUG_ACACHE_UNINIT(CTypelibCacheEntry)
  259. DEBUG_ACACHE_UNINIT(CVariantsIterator)
  260. DEBUG_ACACHE_UNINIT(CViperActivity)
  261. DEBUG_ACACHE_UNINIT(CViperAsyncRequest)
  262. DEBUG_ACACHE_FSA_UNINIT(MemBlock128)
  263. DEBUG_ACACHE_FSA_UNINIT(MemBlock256)
  264. DEBUG_ACACHE_FSA_UNINIT(ResponseBuffer)
  265. #ifdef DBG
  266. DebugFilePrintf
  267. (
  268. SZ_MEMCLS_LOG_FILE,
  269. "MEMCLS: ATQ allocation cache uninited.\n"
  270. "MEMCLS: Total of %d ASP objects leaked.\n",
  271. gs_cTotalObjectsLeaked
  272. );
  273. #endif
  274. return S_OK;
  275. }