+ All Categories
Home > Documents > unit2_ buffer_cache.ppt

unit2_ buffer_cache.ppt

Date post: 08-Feb-2016
Category:
Upload: thota-mahesh
View: 13 times
Download: 1 times
Share this document with a friend
Description:
k
Popular Tags:
44
Buffer Cache Waits
Transcript
Page 1: unit2_ buffer_cache.ppt

Buffer Cache Waits

Page 2: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.2

Buffer Cache Waits

Waits

Disk I/O

Buffer Busy

Library Cache

Enqueue

SQL*Net

Free Buffer

Hot Blocks

Free lists

IO Read

Redo

Buffer Cache

Row Cache

Write Complete

Cache Buffer Chains Latch

Page 3: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.3

Buffer Cache Waits Latch - cache buffers chains Latch - cache buffer chains LRU Free Buffer Wait Buffer Busy Wait

Index Data

Free lists Hot Spots

RBS Write Complete Wait Local Write Wait

Page 4: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.4

REDO Log FilesREDO Log Files Data FilesData Files

DBWRDBWRLGWRLGWR

User2User2

User1User1

User3User3

Log BufferLog Buffer

Buffer CacheBuffer CacheLog Log BufferBuffer

Buffer Buffer CacheCache

SGASGALibrary Library CacheCache

Oracle Memory Stuctures

Page 5: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.5

Buffer Cache

Caches data blocks from disk that are heavily used

Buffer Cache

Disk

ShadowShadow

ProcessProcess

Page 6: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.6

Block in cache?

How do you know if a block is cached?

Do you search all the blocks?

Could be 1000s of blocks to search.

ShadoShadoww

ProcesProcesss

??

Page 7: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.7

Buffer CacheFind a block by

Take

Data file #

Block#

and Hash Them

Page 8: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.8

Hashing I

Simple has could be a Mod function1 mod 4 = 12 mod 4 = 23 mod 4 = 34 mod 4 = 05 mod 4 = 1

Using “mod 4” as a hash funtion creates 4 “buckets” to store things

Page 9: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.9

Hashing II

Empty Buckets

11

22

00

33

Page 10: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.10

Hashing IIIData Block

11

22

00

33

Hash Block’s file# block #’s

Result in a bucket#Put Block in bucket

Page 11: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.11

Hashing IV

11

22

00

33

Page 12: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.12

Hashing V

11

22

00

33

After a while the buckets After a while the buckets become populated with become populated with blocksblocks

Page 13: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.13

To Find a BlockBufferHeaders

Data BlocksHashbucket

1. Hash the block address2. Look for header3. Found, read block in cache4. Not Found Read block off disk

ShadowShadowProcessProcess

11 22 4433

Page 14: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.14

Cache Buffers Chains

11

22

00

33

A different latch protects each bucketA different latch protects each bucket

Note: multiple buckets are now protected by one latchNote: multiple buckets are now protected by one latch

11

22

33

44

Page 15: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.15

Cache Buffers Chains

Hash Buckets

Buffer Headers

Well Well BalancedBalanced

11

22

33

44

55

66

77

88

99

1100

Page 16: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.16

Cache Buffers Chains

Hash Buckets

Buffer Headers

Multiple Buckets protected by same latch v9 onwards

11

22

33

Page 17: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.17

Cache Buffers Chains : Diag

Hash Buckets

s1s1s1s1s1s1s1s1s1s1

SessionsSessions

Contention if too accesses on a bucketContention if too accesses on a bucket

1

22

33

Page 18: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.18

Cache Buffers Chains : Diag

Hash Buckets

Buffer Headers

Contention: Too Contention: Too Many Buffers in Many Buffers in BucketBucket

1

22

33

Page 19: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.19

Cache Buffers Chains : Solution

Fine the SQL causing the problem Contributing Factors

Updates, inserts on blocks while reading those blocks Cause multiple copies

Hot root block of an indexSelect for updateUsing dual instead of x$dual

Page 20: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.20

Need Free Block Block

If the data block isn’t in cache Get a free block in the buffer cacheRead it off diskAdd a headerRead the block into the buffer cache

Need Free Block to Read in New Data Block

Page 21: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.21

Finding a Free Block

ShadowShadow

ProcessProcess

When a session reads a block When a session reads a block

Into the bufffer cache how does Into the bufffer cache how does

it find a it find a FREEFREE spot? spot?

Page 22: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.22

Finding a Free BlockBufferHeaders

Data BlocksHashbucket

Buffer Headers Buffer Headers are also on a are also on a LRU linked ListLRU linked List

Page 23: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.23

Cache Buffers LRU list

MRUMRU LRULRUBuffer Headers

LRU = Least Recently UsedMRU = Least Recently Used

Session

Shadow

Page 24: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.24

Free Buffer Wait

Finding a Free BlockGo to the LRU end of data blocksLook for first non-dirty block If search too many post DBWR to make freeFree Buffer wait

Page 25: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.25

Free Buffer Wait

#17 Data Block Cache lack free buffers Tune by

Increase data blocksTry to tune DBWR

Inefficient SQL requesting large # of blocks

In V7, sorts could flood the cache with dirty blocks

Page 26: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.26

Cache Buffers LRU list

MRUMRU LRULRU

Used Block gets put on FrontUsed Block gets put on Front

Unused blocks get pushed offUnused blocks get pushed off

Buffer Headers

Page 27: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.27

Cache Buffers LRU Latch

MRUMRU LRULRUBuffer Headers

One Latch protects the linked list during changes to the listOne Latch protects the linked list during changes to the list

Page 28: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.28

Cache Buffers LRU Latch

MRUMRU LRULRU

Mid-Point Mid-Point InsertionInsertion

Full Table Scan Full Table Scan Insertion PointInsertion Point

Buffer Headers

Page 29: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.29

Cache Buffers LRU Latch

MRUMRU LRULRU

Mid-Point Mid-Point InsertionInsertion

Oracle Tracks the touch count of blocks. As the Oracle Tracks the touch count of blocks. As the block is pushed to the LRU end, if it’s touch count block is pushed to the LRU end, if it’s touch count is 3 or more, it’s promoted to the MRU endis 3 or more, it’s promoted to the MRU end

Page 30: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.30

Cache Buffers LRU Latch : Solution

Buffer Headers

Multiple SetsMultiple Sets_db_block_lru_latches = 8_db_block_lru_latches = 810gR2 with cpu_count = 210gR2 with cpu_count = 2

Set 1Set 1

Set 2Set 2

Page 31: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.31

Cache Buffers LRU Latch : Solution Other

Increase Size of Buffer Cache Reduce Checkpointing Activity Use Async I/O for DBWR Increase DBWR write batch size

Page 32: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.32

Buffer Busy Waits

User 1 tries to change a buffer header User 2 already has buffer header “locked”

11

22

00

33

User1User1

User2User2

Page 33: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.33

Buffer Busy

14 kinds of blocksUndo Header - more RBS segsdata (index and table are different for bbw)segment header – free listsfreelist blocks – free lists groups

9 kinds Buffer Busy Waits 100,110,120,130 (read I/O issues) 200,210,220,230, 231 (block change issues)

Page 34: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.34

Buffer Busy Wait

What’s Important: What kind of block header

Rollback Data

Index Table

Segment Header If Pre 10

Read (100,110,120,130 ) Write (200,210,220,230, 231 )

Page 35: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.35

Buffer Busy Cases

Undo Header - Not enough rollback segments Undo Block – hot spot in RBS Data Block

Table Block w/ DML : Table lacks Free lists Table I/O : Multiple sessions reading same block into data cache

Note: in 10g, becomes “read by other session” Index : has hot block, partition or change SQL

Segment Header – add free Lists (with Datablock) Free List – add free lists groups

Page 36: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.36

Buffer Busy Solutions

IF Buffer Busy Waits highFirst look at v$waitstat

Class Time/Count

SQL> select * from v$waitstat;

CLASS COUNT TIME------------------ ---------- ----------data block 1 1segment header 0 0free list 0 0undo header 0 0undo block 0 0

Page 37: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.37

Buffer Busy Wait SolutionsBuffer wait Statistics DB/Inst: LINUX3/linux3 Snaps: 39-42-> ordered by wait time desc, waits desc

Class Waits Total Wait Time (s) Avg Time (ms)---------------------- ----------- ------------------- -------------undo header 1,159 18 16data block 132 2 12file header block 45 0 2segment header 4 0 10undo block 1 0 0 ------------------------------------------------------------

Page 38: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.38

Load : Example

4 Sessions running

Insert into toto values (null, ‘a’);Commit;

Page 39: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.39

Lack of Free List : Diag

S1 S2 S3 S4

Page 40: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.40

With Free Lists : Diag

S1 S2 S3 S4

Page 41: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.41

10gSQL> select * from v$waitstat;

CLASS COUNT TIME------------------ ---------- ----------1. data block 89640 137322. sort block 0 03. save undo block 0 04. segment header 1017 25585. save undo header 0 06. free list 0 07. extent map 0 08. 1st level bmb 204874 188969. 2nd level bmb 155 210.3rd level bmb 0 011.bitmap block 0 012.bitmap index block 0 013.file header block 0 014.unused 0 015.system undo header 0 016.system undo block 0 017.undo header 219 12218.undo block 0 0

NAME P1 P2 P3

---------------- -------- ------- ------

buffer busy waits file# block# class

Page 42: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.42

write complete waits

#18 Usually happens in tandem with free buffer Tune by

Increase data block cache Happens because shadow wants to access

blocks that are currently being written to disk by DBWR

Page 43: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.43

Local Write Wait

#25 Truncating a table Wait for Data Cache to be cleared of all

blocks of truncated table Wait by shadow for DBWR

Page 44: unit2_ buffer_cache.ppt

Copyright 2006 Kyle Hailey

#.44

Summary Buffer Cache Waits Latch - cache buffers chains: find SQL Latch - cache buffer chains LRU Free Buffer Wait : increase cache size, tune SQL Buffer Busy Wait

Index : aleveate hot spotsData DML : add free listsData Read: change app, tune I/ORBS : more RBS segs, use UNDO

Write Complete Waits –: increase cache size Local Write Wait : truncates / reduce cache size