예제 #1
0
ServerBlock* DiskBackedBlockMap::get_block_for_updating(const BlockId& block_id){
	/** If block is not in block map, allocate space for it
	 * Otherwise, if the block is in memory, read and return
	 * if it is only on disk, read it in, store in block map and return.
	 * set in_memory and dirty_flag
	 */
	ServerBlock* block = block_map_.block(block_id);
	size_t block_size = sip_tables_.block_size(block_id);
	if (block == NULL) {
		std::stringstream msg;
		msg << "S " << sip_mpi_attr_.global_rank();
		msg << " : getting uninitialized block " << block_id << ".  Creating zero block for updating "<< std::endl;
		SIP_LOG(std::cout << msg.str() << std::flush);
		block = allocate_block(NULL, block_size);
	    block_map_.insert_block(block_id, block);
	} else {
		if(!block->is_in_memory()){
			if (block->is_on_disk()){
				read_block_from_disk(block, block_id, block_size);
            } else {
				block->allocate_in_memory_data();
            }
        }
	}

	block->set_in_memory();
	block->set_dirty();

	policy_.touch(block_id);

	return block;
}
예제 #2
0
ServerBlock* DiskBackedBlockMap::get_block_for_reading(const BlockId& block_id){
	/** If block is not in block map, there is an error !!
	 * Otherwise, if the block is in memory, read and return or
	 * if it is only on disk, read it in, store in block map and return.
	 * Set in_memory flag.
	 */
	ServerBlock* block = block_map_.block(block_id);
	size_t block_size = sip_tables_.block_size(block_id);
	if (block == NULL) {
		// Error !

		std::stringstream errmsg;
		errmsg << " S " << sip_mpi_attr_.global_rank();
		errmsg << " : Asking for block " << block_id << ". It has not been put/prepared before !"<< std::endl;
		std::cout << errmsg.str() << std::flush;
		
		sip::fail(errmsg.str());

		// WARNING DISABLED !
		if (false){
			std::stringstream msg;
			msg << "S " << sip_mpi_attr_.global_rank();
			msg << " : getting uninitialized block " << block_id << ".  Creating zero block "<< std::endl;
			std::cout << msg.str() << std::flush;
			block = allocate_block(NULL, block_size);
			block_map_.insert_block(block_id, block);
		}


	} else {
		if(!block->is_in_memory())
			if (block->is_on_disk()){
				read_block_from_disk(block, block_id, block_size);
            } else {
				sip::fail("get_block_for_reading : ServerBlock neither on memory or on disk !");
            }
	}

	block->set_in_memory();

	policy_.touch(block_id);

	sip::check(block != NULL, "Block is NULL in Server get_block_for_reading, should not happen !");
	return block;
}
예제 #3
0
파일: cache.c 프로젝트: IVY-bug/pintos4-1
struct cache_block* cache_block_get (block_sector_t sector, bool dirty)
{
    lock_acquire (&cache_lock);
    struct cache_block *c = block_in_cache (sector);
    if (c)
    {
	c->open_cnt ++;
	c->dirty |= dirty;
	c->accessed = true;
	lock_release (&cache_lock);
	return c;
     }
     if (cache_size < CACHE_AMOUNT)
     {
         c = read_block_from_disk (sector, dirty);
         lock_release (&cache_lock);
	 return c;
     }else{
         c = cache_block_evict (sector, dirty);
     }
     lock_release (&cache_lock);
     return c;
}