summaryrefslogtreecommitdiff
path: root/src/include/cache.i
blob: 2145a85d25697a2db25fa1dc3dbeca9cec936777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*-
 * Copyright (c) 2008-2012 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

/*
 * __wt_eviction_check --
 *	Wake the eviction server if necessary.
 */
static inline void
__wt_eviction_check(WT_SESSION_IMPL *session, int *read_lockoutp)
{
	WT_CACHE *cache;
	WT_CONNECTION_IMPL *conn;
	uint64_t bytes_inuse, bytes_max;

	conn = S2C(session);
	cache = conn->cache;

	/*
	 * If we're over the maximum cache, shut out reads (which
	 * include page allocations) until we evict to back under the
	 * maximum cache.  Eviction will keep pushing out pages so we
	 * don't run on the edge all the time.
	 */
	bytes_inuse = __wt_cache_bytes_inuse(cache);
	bytes_max = conn->cache_size;
	if (read_lockoutp != NULL)
		*read_lockoutp = (bytes_inuse > bytes_max);

	/* Wake eviction when we're over the trigger cache size. */
	if (bytes_inuse > cache->eviction_trigger * (bytes_max / 100))
		__wt_evict_server_wake(session);
}

/*
 * __wt_eviction_page_check --
 *	Check if a page is too big and wake the eviction server if necessary.
 */
static inline int
__wt_eviction_page_check(WT_SESSION_IMPL *session, WT_PAGE *page)
{
	WT_CONNECTION_IMPL *conn;

	conn = S2C(session);

	/*
	 * If the page is pathologically large, force eviction.
	 * Otherwise, if the cache is more than 95% full, wake up the eviction
	 * thread.
	 */
	if (page != NULL &&
	    !F_ISSET(page, WT_PAGE_FORCE_EVICT | WT_PAGE_PINNED) &&
	    (((int64_t)page->memory_footprint > conn->cache_size / 2) ||
	    (page->memory_footprint > 20 * session->btree->maxleafpage))) {
		/*
		 * We're already inside a serialized function, so we need to
		 * take some care.
		 */
		WT_RET(__wt_evict_page_request(session, page));
	} else
		__wt_eviction_check(session, NULL);

	return (0);
}