1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2000,2008 Oracle.  All rights reserved.
5 *
6 * $Id: util_cache.c,v 12.7 2008/01/08 20:58:08 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13/*
14 * __db_util_cache --
15 *	Compute if we have enough cache.
16 *
17 * PUBLIC: int __db_util_cache __P((DB *, u_int32_t *, int *));
18 */
19int
20__db_util_cache(dbp, cachep, resizep)
21	DB *dbp;
22	u_int32_t *cachep;
23	int *resizep;
24{
25	u_int32_t pgsize;
26	int ret;
27
28	/* Get the current page size. */
29	if ((ret = dbp->get_pagesize(dbp, &pgsize)) != 0)
30		return (ret);
31
32	/*
33	 * The current cache size is in cachep.  If it's insufficient, set the
34	 * the memory referenced by resizep to 1 and set cachep to the minimum
35	 * size needed.
36	 *
37	 * Make sure our current cache is big enough.  We want at least
38	 * DB_MINPAGECACHE pages in the cache.
39	 */
40	if ((*cachep / pgsize) < DB_MINPAGECACHE) {
41		*resizep = 1;
42		*cachep = pgsize * DB_MINPAGECACHE;
43	} else
44		*resizep = 0;
45
46	return (0);
47}
48