OCP知识点讲解 之 LRU链与脏LRU链
一、LRU链:任何缓存的大小都是有限制的,并且总不如被缓存的数据多。就像Buffercache用来缓存数据文件,数据文件的大小远远超过Buffercache。因此,缓存总有被
一、LRU链:
为了实现LRU的功能,Oracle在Buffer cache中创建了一个LRU链表,Oracle将Buffer cache中所有内存块,按照访问次数、访问时间排序串在链表中。链表的两头我们分别叫做热端与冷端, 如下图
当你第一次访问某个块时,如果这个块不在Buffer cache中,Oracle要选将它读进Buffer cache。在Buffer cache中选择牺牲者时,Oracle将从冷端头开始选择,在上图的例子中,内存块U将是牺牲者。
如上图,新块将会被读入U,覆盖U原来的内容。这里,我们假设新块是V。但是块V不会被放在冷端头,因为冷端头的块,会很快被当作牺牲者权覆盖的。这不符合“将最后访问时间距现在最远的块作为牺牲者”的宗旨。块V是最后时间距当前时刻最近的,它不应该作为下一个牺牲者。Oracle是如何实验LRU的,我们继续看。
Oracle将LRU链从中间分为两半,一半记录热端块、一半记录冷端块。如上图,而刚刚被访问的块V,如下图:
如过再有新的块进入Buffer cache,比如块X被读入Buffer cache,它将覆盖T,并且会被移至块V的前面,如下图:
大家可以想像一下,如果按照这面的方式继续下去,最右边冷端头处的块,一定是最后一次访问时间距现在最远的块。那么,访问次数多的块是不会被选做牺牲者的,这一点Oracle是如何实现的?这很简单,Oracle一般以2次为准,块被访问2次以上了,它就有机会进入热端。
Oracle为内存中的每个块都添加了一个记录访问次数的标志位,假设图中每个块的访问次数如下:
如果现在又有新块要被读入Buffer cache,Oracle开始从冷端头寻找牺牲者,冷端头第一个块S,它的访问次数是2,香港虚拟主机,那么,它不能被覆盖,只要访问次数大于等于2的块,Oracle会认为它可能会被经常访问到,Oracle要把它移到热端,它会选择R做为本次的牺牲者:
块S会被从冷端移到热端,并且它的访问次数会被清零。此时,块R就是牺牲者了,因为它的访问次数不到两次。
新块Y覆盖了块R,并被移到了冷端块开始处,它的访问次数是1。如果块Y再被访问了一次,它的访问次数变为了2:
虽然Y的访问次数达到了两次,但它不会马上被移到热端,它仍然留在原来的位置,随着不断有新块加入,被插入到它的前面,虚拟主机,它会不断的被向后推移。
如上图,又加入了很多的新块,Y又被推到了冷端头,当再有新块进入Buffer cache时,Y不会是牺牲者,它会被移到热端头S的前面,Y后面的Z,它的访问次数没有达到2,它将会是牺牲者。
好了,这就是Oracle中Buffer cache管理LRU的原理。按照这种方式运作,Oracle可以把常用的块尽量长的保持在Buffer cache中。而且,每有新块进入Buffer cache,Oracle都会从冷端头处,从右向左搜索牺牲块。因为越靠近冷端,块的访问次数有可能越少、最后的访问时间离现在最远。好了,LRU链还没有讲完,下面,我们再讨论一下脏块与脏LRU链的问题。
二、脏块与脏LRU链:
Oracle中修改块的规则是只对Buffer cache中的块进行修改,并不直接修改磁盘中的块。如果要修改的块不在Buffer cache中,Oracle会先将它读入Buffer cache,再在Buffer cache中进行修改。当Buffer cache中的块被修改后,Oracle会把它标记为“脏”块。脏块含有脏数据,脏数据就是用户修改过的数据。Oracle会定期的将脏块写到磁盘中。有一个专门的后台进程就是专门负责写脏块到磁盘的,它就是DBWn。我们也把DBWn写脏块到磁盘这个过程叫做刷新脏块,刷新过后,脏块就不脏了,又变成了干净块。其实,有一个块A,如果Buffer cache中此块的数据和磁盘上块中数据不一致,香港服务器,那么,这个块就是脏块。否则,就是干净块。当修改完成后,因为Oracle只修改Buffer cache,因此,块中数据和磁盘肯定不一致,这时块就是脏块。当块被刷新后,块被写到磁盘,那么,磁盘中块数据和Buffer cache中块的数据又是一致的,此时,块就又变成了干净块。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Python is currently the most popular programming language. I believe that a large number of novice friends will join the ranks of learning every day. However, no matter how easy a language is to learn, there are still many basic concepts and basic knowledge. For a novice, it is still difficult to master so many in one time. Today, we have collected many Python-related knowledge cheat sheets, which can be said to be all-inclusive. In the future, mom will no longer have to worry about everyone not being able to remember any knowledge points! Python basics Pythonbasics This cheat sheet contains all the basic knowledge of Python, from variable data types to list strings, from environment installation to the use of commonly used libraries, it can be said to be comprehensive. Beginner'sPytho

The secret of HTML caching mechanism: essential knowledge points, specific code examples are required In web development, performance has always been an important consideration. The HTML caching mechanism is one of the keys to improving the performance of web pages. This article will reveal the principles and practical skills of the HTML caching mechanism, and provide specific code examples. 1. Principle of HTML caching mechanism During the process of accessing a Web page, the browser requests the server to obtain the HTML page through the HTTP protocol. HTML caching mechanism is to cache HTML pages in the browser

How to implement LRU caching algorithm using Java Introduction: In the field of computer science, caching is a commonly used optimization technology to improve the speed of data reading and writing. LRU (LeastRecentlyUsed) is a common cache replacement strategy that determines whether to remove data from the cache based on the last time the data was accessed. This article will introduce how to implement the LRU cache algorithm using Java language and provide detailed code examples. Principle of LRU cache algorithm LRU cache algorithm is a time-based

1. Python cache ① Cache function Cache is an optimization technology that can be used in applications to save recent or frequently used data in memory. Accessing data in this way is faster than reading disk files directly. Much higher. Suppose we build a news aggregation website, similar to Feedly, which obtains news from different sources and then aggregates and displays it. When the user browses the news, the background program downloads the article and displays it on the user's screen. If caching technology is not used, when users switch to browse the same article multiple times, they must download it multiple times, which is inefficient and unfriendly. A better approach is to store the content locally, such as in a database, after obtaining each article; then, when the user next

MySQL is one of the most popular relational database management systems in the world and is widely used because of its reliability, high security, high scalability and relatively low cost. MySQL data types define the storage methods of various data types and are an important part of MySQL. This article will explain in detail the data types of MySQL and some knowledge points that need to be paid attention to in practical applications. 1. MySQL data type classification MySQL data types can be divided into the following categories: Integer types: including TINYINT,

Introduction to network security: What are the essential knowledge points for beginners? In recent years, with the rapid development of the Internet, network security has attracted more and more attention. However, for many people, network security is still an unknown ocean. So, to get started with network security, what essential knowledge do beginners need to master? This article will sort it out for you. 1. Network attacks and threats First of all, understanding the types of network attacks and threats is a knowledge point that must be mastered to get started with network security. There are many types of cyber attacks such as phishing attacks, malware, ransomware

Oracle data types revealed: knowledge points you must understand and specific code examples required. Oracle, as one of the world's leading database management systems, plays an important role in data storage and processing. In Oracle, data type is a very important concept, which defines the storage format, range and operation method of data in the database. This article will reveal various knowledge points of Oracle data types and demonstrate their usage and characteristics through specific code examples. 1. Common data types character data types

Important knowledge points: To master the essential skills of CSS responsive layout, specific code examples are required. In the modern Internet era, more and more people use mobile devices to browse web pages, so responsive layout of web pages has become particularly important. Responsive layout means that a web page can automatically adjust its layout and style according to different screen sizes and device types to adapt to different user experiences. Mastering the skills of CSS responsive layout is a must for front-end developers. This article will introduce some important knowledge points and techniques, and provide specific code examples. use media
