Пример #1
0
/*
 * __wt_block_discard --
 *	Discard blocks from the system buffer cache.
 */
int
__wt_block_discard(WT_SESSION_IMPL *session, WT_BLOCK *block, size_t added_size)
{
	WT_DECL_RET;
	WT_FILE_HANDLE *handle;

	/* The file may not support this call. */
	handle = block->fh->handle;
	if (handle->fh_advise == NULL)
		return (0);

	/* The call may not be configured. */
	if (block->os_cache_max == 0)
		return (0);

	/*
	 * We're racing on the addition, but I'm not willing to serialize on it
	 * in the standard read path without evidence it's needed.
	 */
	if ((block->os_cache += added_size) <= block->os_cache_max)
		return (0);

	block->os_cache = 0;
	ret = handle->fh_advise(handle, (WT_SESSION *)session,
	    (wt_off_t)0, (wt_off_t)0, WT_FILE_HANDLE_DONTNEED);
	return (ret == EBUSY || ret == ENOTSUP ? 0 : ret);
}
Пример #2
0
/*
 * __wt_bm_preload --
 *	Pre-load a page.
 */
int
__wt_bm_preload(
    WT_BM *bm, WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size)
{
	WT_BLOCK *block;
	WT_DECL_ITEM(tmp);
	WT_DECL_RET;
	WT_FILE_HANDLE *handle;
	wt_off_t offset;
	uint32_t cksum, size;
	bool mapped;

	WT_UNUSED(addr_size);

	block = bm->block;

	WT_STAT_FAST_CONN_INCR(session, block_preload);

	/* Crack the cookie. */
	WT_RET(__wt_block_buffer_to_addr(block, addr, &offset, &size, &cksum));

	handle = block->fh->handle;
	mapped = bm->map != NULL && offset + size <= (wt_off_t)bm->maplen;
	if (mapped && handle->fh_map_preload != NULL)
		ret = handle->fh_map_preload(handle, (WT_SESSION *)session,
		    (uint8_t *)bm->map + offset, size, bm->mapped_cookie);
	if (!mapped && handle->fh_advise != NULL)
		ret = handle->fh_advise(handle, (WT_SESSION *)session,
		    (wt_off_t)offset, (wt_off_t)size, WT_FILE_HANDLE_WILLNEED);
	if (ret != EBUSY && ret != ENOTSUP)
		return (ret);

	/* If preload isn't supported, do it the slow way. */
	WT_RET(__wt_scr_alloc(session, 0, &tmp));
	ret = __wt_bm_read(bm, session, tmp, addr, addr_size);
	__wt_scr_free(session, &tmp);

	return (ret);
}