关于free list的几个规则

[复制链接]
查看11 | 回复9 | 2005-10-30 17:05:33 | 显示全部楼层 |阅读模式
此文源于ITPUB上的一个帖子:
http://www.itpub.net/showthread. ... 15&pagenumber=1
两篇原文可以参考如下:
http://support.oracle.co.uk/meta ... &p_id=1029850.6
http://www.ixora.com.au/q+a/datablock.htm#end
下面谈谈我自己的理解。
几个规则:
data block Algorithms
1.当data block中的空闲空间大于PCTFREE的时候,该data block就被塞入free list中
2.当data block的使用空间大于PCTUSED并且不足以塞入一行数据时(这个是需要触发的)就会从free list上摘掉
3.当data block被摘掉后,应为delete或者update操作使得使用空间小于PCTUSED将再次被塞入到free list中
4. 每次塞入时都是塞入到链表的头部
Transaction Free List Algorithms:
1. 当transaction因为删除或者更新产生了free block的时候,会申请transaction free list,用于存放这些free block
2. transaction首先扫描看有没有自己的free list,如果有就用自己的(肥水不流外人田啊)
3. 如果没有的话就看有没有空的或者是已经提交的transaction曾进使用过的T free list.
4. 如果没有的话就等待,注意这里等待的方式比较特别。以我一开始想象中的应该是等待哪一个transaction提交了,赶紧去抢他的位子

(日常生活经验啦)。
而oracle的处理方式就比较君子一点,是根据PID % (Tx free lists total number)算出自己应该等待的是哪一个tx free list,然后就死等

一直等到占着位子
的transaction提交,估计是避免频繁的扫描吧
5. Tx free list中的free block可以给占用该free list的transaction立即使用,其他session需要使用需要等该transaction提交后
free block申请规则
当一个session因为insert或者update需要free block的时候遵循下面的规则:
1. 首先查看自己有没有Tx free list,如果有的话看上面有没有足够的free block,有的话就用自己的,没有的话到下一步
2. 根据(P % NFL) + 1计算出来的值定位自己的process free list(注意不是看所有的process free list)看上面有没有空闲的块
where P : Oracle PID of the process (index in V$PROCESS),
and NFL : Process free lists number as defined by parameter FREELISTS
3. 如果还是不能满足要求的话,就会发生Free Lists Merge的动作,从master free list上移动一些空闲块到process free list上面
4. 如果master free list还不能满足要求的话,就会查看Tx free list看有没有已经提交的transaction的T free list上面有空闲块,有的话就会吧这些空闲块移动到
master free list上,再从master free list上移到process free list上面
5.如果以上都不行的话,就进行bump up HWM 大小为
min (5, unused blocks in the extent): before 7.2
min (5*(NFL+1), unused blocks in the extent): since 7.2.
新增加的block塞入到master free list中
6.如果HWM已经到了extent的末端,无可扩展,此时就需要进行申请新的extent了,然后再bump up HWM
free block的转移过程大致上是这样的
硬盘空间-->extent-->HWM内-->master free list-->process free lsit ---> transaction free list ---> master free list ..........循环
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
有兴趣大家可以看原文,讲的很详细
不知自己有没有理解不准确的地方
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
1.当data block中的空闲空间大于PCTFREE的时候,该data block就被塞入free list中
2.当data block的使用空间大于PCTUSED并且不足以塞入一行数据时(这个是需要触发的)就会从free list上摘掉
我看了前面的,这两处写错了
下面是原版的教材,请参考
The PCTFREE parameter sets the minimum percentage of a data block to be reserved as free space for possible updates to rows that already exist in that block.
The PCTUSED parameter sets the minimum percentage of a block that can be used for row data plus overhead before new rows are added to the block.
As an example, if you issue a CREATE TABLE statement with PCTFREE set to 20, the Oracle server reserves 20% of each data block in the data segment of this table for updates to the existing rows in each block. The used space in the block can grow (1) until the row data and overhead total 80% of the total block size. Then the block is removed from the free list to prevent additional inserts (2).
After you issue a DELETE or UPDATE statement, the Oracle server processes the statement and checks to see whether the space being used in the block is now less than PCTUSED. If it is, the block goes to the beginning of the freelist. When the transaction is committed, free space in the block becomes available for other transactions (3).
After a data block is filled to the PCTFREE limit again (4), the Oracle server again considers the block unavailable for the insertion of new rows until the percentage of that block falls below the PCTUSED parameter.
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
这个并不错啊,事实上不是等到1-PCTFREE%都塞满的时候才从free list上摘掉的
而是只要有当
1)data block的使用空间大于PCTUSED
2)并且不足以塞入一行数据时(这个是需要触发的)
这两个条件就会摘掉
你在往下看原文中有这么一段
A block is unlinked from a free list if the free space in the block is not
enough to allow a new row insert, and if the percentage of the used space
remains above PCTUSED.
后面还有具体的触发情景描述
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
至于第一点不是被触发,不是空闲空间大于PCTFREE就塞入,而是一个初始的情景,例如bump up HWM或者扩展extent的时候得到的block,翻译是不太准确
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
你的翻译是有错误的,呵呵,不要怪我说话直接,毕竟学知识要严谨一些,大家讨论讨论
比如你说1.当data block中的空闲空间大于PCTFREE的时候,该data block就被塞入free list中
而oracle 033的第13课Using Oracle Blocks Efficiently关于pctfree,pctused的原文是这样的
After you issue a DELETE or UPDATE statement, the Oracle server processes the statement and checks to see whether the space being used in the block is now less than PCTUSED. If it is, the block goes to the beginning of the freelist. When the transaction is committed, free space in the block becomes available for other transactions (3).
当你发布一个DELETE或UPDATE语句时,oracle server执行这个语句并且检查这个块的空间使用是否低于pctused的设置(比如pctused设置为20,那么就检查当前块的使用空间是否低于整个块大小的20%),如果是,那么这个块回到freelist的开始。当这个事务提交后,这个块中的空闲空间就可以被其它事务使用了。
说你说块被塞入free list中和PCTFREE的设置有关是错误的。
其它也有些错误,仔细对照原文就可以发现
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
最初由 eagle_fan 发布
[B]这个并不错啊,事实上不是等到1-PCTFREE%都塞满的时候才从free list上摘掉的
而是只要有当
1)data block的使用空间大于PCTUSED
2)并且不足以塞入一行数据时(这个是需要触发的)
这两个条件就会摘掉
你在往下看原文中有这么一段
A block is unlinked from a free list if the free space in the block is not
enough to allow a new row insert, and if the percentage of the used space
remains above PCTUSED.
后面还有具体的触发情景描述 [/B]

引用你的原文
A block is unlinked from a free list if the free space in the block is not enough to allow a new row insert, and if the percentage of the used space remains above PCTUSED.
这段话是说一个块unlinked from a free list有以下两种情况,一 不足以插入一新行 不用多说,二 块的使用仍然在PCTUSED之上。
这个只是说块不在freelist上的两种情况,
并不是你所说的 data block的使用空间大于PCTUSED 块就从free list上摘掉啊。
照你这样说,如果一个新块,PCTUSED设置为20,在块的空间使用为19%时,块在freelist上,如果块的空间使用一旦超过20%,比如是21%了,这个块就不在freelist上了啊,那这个块的使用多浪费啊。一个块只可以使用20%,否则就不允许插入了啊,呵呵,明显是错误的。
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
How PCTFREE and PCTUSED Work Together
You use two space management parameters, PCTFREE and PCTUSED, to control the use of free space within all the data blocks of a segment. You specify these parameters when creating or altering a table or cluster (which has its own data segment).
If you are using Automatic Segment Space Management the value of PCTUSED has no meaning because there is no free list. Instead the space management is handled by way of a bitmap. However, PCTFREE does still have meaning and should be set appropriately.
The PCTFREE parameter sets the minimum percentage of a data block to be reserved as free space for possible updates to rows that already exist in that block.
The PCTUSED parameter sets the minimum percentage of a block that can be used for row data plus overhead before new rows are added to the block.
As an example, if you issue a CREATE TABLE statement with PCTFREE set to 20, the Oracle server reserves 20% of each data block in the data segment of this table for updates to the existing rows in each block. The used space in the block can grow (1) until the row data and overhead total 80% of the total block size. Then the block is removed from the free list to prevent additional inserts (2).
DML Statements and PCTFREE
After you issue a DELETE or UPDATE statement, the Oracle server processes the statement and checks to see whether the space being used in the block is now less than PCTUSED. If it is, the block goes to the beginning of the freelist. When the transaction is committed, free space in the block becomes available for other transactions (3).
After a data block is filled to the PCTFREE limit again (4), the Oracle server again considers the block unavailable for the insertion of new rows until the percentage of that block falls below the PCTUSED parameter.
DML Statements, PCTFREE, and PCTUSED
Two types of statements can increase the free space of one or more data blocks:
DELETE statements
UPDATE statements which update existing values to values that use less space
Released space in a block may not be contiguous; for example, when a row in the middle of the block is deleted. The Oracle server coalesces the free space of a data block only when:
An INSERT or UPDATE statement attempts to use a block that contains enough free space to contain a new row piece
The free space is fragmented so that the row piece cannot be inserted in a contiguous section of the block
The Oracle server performs this compression only when required, because otherwise the performance of a database system would decrease due to the continuous compression of the free space in data blocks.
Setting PCTFREE for an Index
You can also specify the PCTFREE storage parameter when creating or altering an index. Setting PCTFREE for an index specifies how much of a block to fill when the index is created or during a block split. It does not keep space available for updates as is done with data blocks.
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
最初由 道可道非常道 发布
[B]
引用你的原文
A block is unlinked from a free list if the free space in the block is not enough to allow a new row insert, and if the percentage of the used space remains above PCTUSED.
这段话是说一个块unlinked from a free list有以下两种情况,一 不足以插入一新行 不用多说,二 块的使用仍然在PCTUSED之上。
这个只是说块不在freelist上的两种情况,
并不是你所说的 data block的使用空间大于PCTUSED 块就从free list上摘掉啊。
照你这样说,如果一个新块,PCTUSED设置为20,在块的空间使用为19%时,块在freelist上,如果块的空间使用一旦超过20%,比如是21%了,这个块就不在freelist上了啊,那这个块的使用多浪费啊。一个块只可以使用20%,否则就不允许插入了啊,呵呵,明显是错误的。 [/B]

我想你是误解我的意思了
我没有说只要使用空间超过了PCTUSED就会摘掉啊
我强调的是两个条件同时满足
当transaction申请到空闲块时,试图进行插入,如果空闲块的空闲空间不能插入一行数据,就检查空闲块的使用空间是否超过了PCTUSED,如果超过的话才会摘掉。所以这两个条件都是必需条件。
所以事实上可能出现使用空间为21%的块被从free list上摘掉(无法塞入一行较大的数据),而使用空间79%的块仍然留在free list上(满足塞入一行较小数据的要求)
你所贴的concepts上面的内容早就看过了,请看看我后面附着的原文吧
大家讨论讨论
回复

使用道具 举报

千问 | 2005-10-30 17:05:33 | 显示全部楼层
最初由 道可道非常道 发布
[B]你的翻译是有错误的,呵呵,不要怪我说话直接,毕竟学知识要严谨一些,大家讨论讨论
比如你说1.当data block中的空闲空间大于PCTFREE的时候,该data block就被塞入free list中
而oracle 033的第13课Using Oracle Blocks Efficiently关于pctfree,pctused的原文是这样的
After you issue a DELETE or UPDATE statement, the Oracle server processes the statement and checks to see whether the space being used in the block is now less than PCTUSED. If it is, the block goes to the beginning of the freelist. When the transaction is committed, free space in the block becomes available for other transactions (3).
当你发布一个DELETE或UPDATE语句时,oracle server执行这个语句并且检查这个块的空间使用是否低于pctused的设置(比如pctused设置为20,那么就检查当前块的使用空间是否低于整个块大小的20%),如果是,那么这个块回到freelist的开始。当这个事务提交后,这个块中的空闲空间就可以被其它事务使用了。
说你说块被塞入free list中和PCTFREE的设置有关是错误的。
其它也有些错误,仔细对照原文就可以发现 [/B]

你说的这个不就是第三点中列出的吗
第一点是一种初始情况
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行