share pool 管理机制
Library cache是Shared pool的一部分,它几乎是Oracle内存结构中最复杂的一部分,主要存放shared curosr(SQL)和PLSQL对象(function,procedure,trigger)的信息,以及这些对象所依赖的table,index,view等对象的信息。
Library cache需要解决三个问题:
1.快速定位的问题:Library cache中对象众多,Oracle如何管理这些对象,以便服务进程可以迅速找到他们需要的信息。比如某个服务进程需要迅速定位某个SQL是否存在于Library cache中。
2.关系依赖的问题:Library cache中的对象存在复杂的依赖关系,当某个objec失效时,可以迅速将依赖其的对象也置为失效状态。比如某个表发生了结构变化,依赖其的SQL语句需要重新解析。
3.并发控制的问题:Library cache中必须有一个并发控制的机构,比如锁机制,来管理大量共享对象的并发访问和修改的问题,比如某个SQL在重新编译的同时,其所依赖的对象不能被修改。
Library cache结构:
Oracle利用hash table结构来解决library cache中快速定位的问题,hash table就是很多hash bucket组成的数组:

LibraryCache 保存了explicitSQL, PL/SQLcommands,shared 和 nonshared cursors。 这些对象都保存在Hash table里,Hash table 又由Hash Bucket组成。 Hash Bucket 由一些Object Handle List 组成,所以在Hash Bucket里查找某个对象,就是搜索这个Handle List。
Object Handle
在上图我们可以看到Object handle 保存的信息。 Library cache handle指向library cache object(LCO, heap 0),它包含了library object的名字,命名空间,时间
戳,引用列表,lock对象以及pin对象的列表信息等等。
关于Namespace,参考我的blog:
Oracle Namespace 说明
http://blog.csdn.net/tianlesoftware/article/details/6624122
所以对Library cache中所有对象的访问是通过利用library cache handle来实现的,也就是说我们想要访问library cache object,我们必须先找到library cache handle。
因为Object handle保存了lock 和pin 的信息,即记录哪个用户在这个这个handle上有lock,或者是哪个用户正在等待获得这个lock。那么这里我们也知道了library cache lock是发生在handle上的。
当一个进程请求library cache object, librarycache manager就会应用一个hash 算法,从而得到一个hash 值,根据相应的hash值到相应的hash bucket中去寻找。
如果library cache object在内存中,那么这个library cache handle就会被找到。有时候,当shared pool不够大,library cache handle会保留在内存中,然而library cache heap由于内存不足被age out,这个时候我们请求的object heap就会被重载。最坏的情况下,library cache handle在内存中没有找到,这个时候就必须分配一个新的library cachehandle,同时object heap也会被加载到内存中。
Library Cache Object(LCO: Heap 0)
它的结构信息如下图。 这个图需要认真的去理解。

DSI 的说明:
(1)Internally, most of the objectidentity is represented by structures of type kglob.
(2)These are thestructures stored in heap 0.
(3)Object structures have thefollowing components:
Type
Name
Flags
Tables
Datablocks
LibraryCache 存储SQL或者shared cursors 等。 这些信息就是通过Heap 0 这个LCO 来保存的。
1 Object Types
(1)Objects aregrouped in namespaces according to their type.
(2)Each object can only be of onetype.
(3)All the objects of the same typeare in the same namespace.
(4)A namespace may be used by morethan one type.
(5)The most important namespace iscalled cursor (CRSR) and houses the shared SQL cursors.
2 Object Names
(1)Library cache object names havethree parts:
Nameof schema
Nameof object
Nameof database link (remote objects only)
(2)The format used isSCHEMA.NAME@DBLINK.
Forexample, HR.EMPLOYEES@ACME.COM
3 Object Flags
(1)Public flags:
Arenot protected by pins or latches
Indicatein detail the type of the object
(2)Status flags:
Areprotected by pins
Indicatewhether the object is being created/dropped/altered/updated
(3)Special status flags:
Areprotected by the library cache latch
Arerelated to object validity and authorization
4 Object Tables
(1)Dependency table
(2)Child table
(3)Translation table
(4)Authorization table
(5)Access table
(6)Read-only dependency table
(7)Schema name table
Object Table 又分为以上7中类型。
4.1 dependency table
指向本对象所依赖的对象,比如:select * from emp这个cursor的对象,依赖emp这个表,这里指向了emp这个表的handle。
4.2.child table
指向本对象的子对象,比如某个游标的子游标。通俗点说,就是一条SQL 至少有一个parent cursor 和 child cursor。 可能一些SQL 由于某些原因无法共享childcursor,这样就会出现一个parentcursor 和 多个child cursor的情况。 即version count 很高。 那么这种情况下。 parent cursor 里对应的所有childcursor的指针都会保存在child table里面。 Oracle 是用C 写的,所以这里是指针。
注意一点,parent cursor和child cursor都是用library cache object handle 存储在Library Cache里的。即他们的结构完全一样。
这个结论可以通过library cache的dump 文件来证明。在后面我们会做一个测试。
Oracle 高 Version counts 问题说明
http://blog.csdn.net/tianlesoftware/article/details/6628232
4.3.authorization table
对象的授权信息。
5 Object Data Blocks
(1)The remainder ofan object’s data is stored in other independent data heaps.
(2)The object structure contains anarray of data block structures.
(3)The data blockstructures have a pointer to a different data heap.
(4)An object structure has room for 16data block structures but not all of them are in use.
Heap0 也仅仅保存是一个结构,它不保存实际的data。 而实际data 的存储Heap 的指针就存放在这个Data Blocks里。 这个也可以通过dump 来查看。这个Data Blocks指向的Heap 结构如下图:

share pool 管理机制的更多相关文章
- 【MySQL】InnoDB 内存管理机制 --- Buffer Pool
InnoDB Buffer Pool 是一块连续的内存,用来存储访问过的数据页面 innodb_buffer_pool_size 参数用来定义 innodb 的 buffer pool 的大小 是 M ...
- 【Cocos2d-x 3.x】内存管理机制与源码分析
侯捷先生说过这么一句话 : 源码之前,了无秘密. 要了解Cocos2d-x的内存管理机制,就得阅读源码. 接触Cocos2d-x时, Cocos2d-x的最新版本已经到了3.2的时代,在学习Coco ...
- IOS- 内存管理机制
iOS平台内存常见问题 作为iOS平台的开发者,是否曾经为内存问题而苦恼过?内存莫名的持续增长,程序莫名的crash,难以发现 的内存泄漏,这些都是iOS平台内存相关的常见问题:本文将会详细介绍iOS ...
- OC 内存管理机制总结
OC 内存管理机制总结 一:OC内存管理机制目前分为两块,其一自动内存管理机制,其二手动内存管理机制: 1.首先我们从自动内存管理机制讲起: 1)什么是自动内存管理机制,自动内存管理机制就是程序中所创 ...
- Keil C动态内存管理机制分析及改进(转)
源:Keil C动态内存管理机制分析及改进 Keil C是常用的嵌入式系统编程工具,它通过init_mempool.mallloe.free等函数,提供了动态存储管理等功能.本文通过对init_mem ...
- 2、COCOS2D-X内存管理机制
在C++中.动态内存分配是一把双刃剑,一方面,直接訪问内存地址提高了应用程序的性能,与使用内存的灵活性.还有一方面.因为程序没有正确地分配与释放造成的比如野指针,反复释放,内存泄漏等问题又严重影响着应 ...
- 全面介绍Windows内存管理机制及C++内存分配实例(四):内存映射文件
本文背景: 在编程中,很多Windows或C++的内存函数不知道有什么区别,更别谈有效使用:根本的原因是,没有清楚的理解操作系统的内存管理机制,本文企图通过简单的总结描述,结合实例来阐明这个机制. 本 ...
- ubuntu包管理机制
1 ubuntu包管理机制 跟大家分享一下ubuntu的软件管理机制.如果你们有过: apt-get install 或者 apt-get update 失败的经历. 在众多的apt命令中迷失. 疑惑 ...
- Python 源码剖析(六)【内存管理机制】
六.内存管理机制 1.内存管理架构 2.小块空间的内存池 3.循环引用的垃圾收集 4.python中的垃圾收集 1.内存管理架构 Python内存管理机制有两套实现,由编译符号PYMALLOC_DEB ...
随机推荐
- 有关https有的网站可以访问有的访问不了的问题
在开发中遇到这种情况,在开发工具里面访问可以,当时到了手机上之后就发现有的请求可以正常获取数据,有的则不行. 都是使用https地址,也配置后台了,但是就是不出数据,总是无法请求服务. 后来检查在手机 ...
- errror:[test_rig3.launch] is neither a launch file in package [svo_ros] nor is [svo_ros] a launch file name The traceback for the exception was written to the log file
1. 打开一个终端,运行roscore 2. 打开另一个终端,运行 roslaunch svo_ros test_rig3.launch 出现errror: 忘记关键步骤了 $ cd <path ...
- chorem浏览器无法下载
下载的时候指定字节的长度 context.Response.AddHeader("Content-Length", bytes.Length.ToString()); contex ...
- Android TV开发 焦点控制
转载:http://www.eoeandroid.com/thread-264177-1-1.html 最近在做一款基于Android的互联网电视客户端,开发与phone/pad差不多,但是有一个值得 ...
- "//./root/CIMV2" because of error 0x80041003. Events cannot be delivered through this filter until the problem is corrected.
windows系统日志错误信息: Event filter with query "SELECT * FROM __InstanceModificationEvent WITHIN 60 W ...
- js倒计时跳转页面实现
- Android开发之自定义的ProgressDialog
package com.example.dialog; import android.app.ProgressDialog; import android.content.Context; /** * ...
- C# iframe session 丢失
在页面A中使用iframe引用另一站点页面B,但页面B上面的session总是丢失,百度了一下,不用改程序,直接在iis里面操作,解决方法如下 1.打开IIS管理器 inetmgr 2.选择被嵌入if ...
- Oracle数据库mybatis 插入空值时报错(with JdbcType OTHER)
参考文档: 1.https://blog.csdn.net/fishernemo/article/details/27649233 2.http://helgaxu.iteye.com/blog/21 ...
- UIDataPicker 时间选择器
自用时间选择器 @interface ViewController () { UILabel *cityLabel; UIDatePicker *datePicker; } //@property(n ...