//=============================
//Pseduo Code of Cache Policy
//=============================
Cache_write_policy()
{
if (cache_hit)
{
if(cache_write_through)
{
write_data_to_cache_memory();
write_data_to_main_memory(); // cache -> write buffer -> main memory
}
else if(cache_write_back)
{
write_data_to_cache_memory();
label_cache_line_is_dirty();
}
}
}
Cache_replacement_policy()
{
if(cache miss)
{
if(victim cache line is valid, dirty)
{
flush_cache_line_to_main_memory();
}
}
}
Cache_allocation_policy()
{
if(cache miss)
{
// allocation cache on read miss only
if(cache_read_allocation)
{
if(read request)
{
Cache_replacement_policy();
Fill_cache_line_from_main_memory();
}
else if(write request)
{
write_data_to_main_memory();
}
}
// allocation cache on read / write miss
else if (cache_read_write_allocation)
{
if (read request)
{
follow_cache_read_allocation();
}
else if(write request)
{
if (victim cache_line is valid)
{
Cache_replacement_policy();
}
// from now on, cache write bahavior is like cache hit
cache_under_hit();
Cache_write_policy();
}
}
}
else if (cache hit)
{
if (read request)
{
fetch_cache_line_data_to_processor();
}
else if (write request)
{
Cache_write_policy();
}
}
}
本文深入解析了缓存系统中的关键策略,包括写入政策和替换政策,详细介绍了写入缓存内存与主内存的操作流程,以及在缓存缺失时的替换策略与分配策略。
2028

被折叠的 条评论
为什么被折叠?



