mariadb/bdb/mp/mp_trickle.c

84 lines
1.9 KiB
C
Raw Normal View History

2001-03-05 01:42:05 +01:00
/*-
* See the file LICENSE for redistribution information.
*
2002-10-30 12:57:05 +01:00
* Copyright (c) 1996-2002
2001-03-05 01:42:05 +01:00
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
2002-10-30 12:57:05 +01:00
static const char revid[] = "$Id: mp_trickle.c,v 11.24 2002/08/06 06:13:53 bostic Exp $";
2001-03-05 01:42:05 +01:00
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <stdlib.h>
#endif
#include "db_int.h"
2002-10-30 12:57:05 +01:00
#include "dbinc/db_shash.h"
#include "dbinc/mp.h"
2001-03-05 01:42:05 +01:00
/*
2002-10-30 12:57:05 +01:00
* __memp_trickle --
2001-03-05 01:42:05 +01:00
* Keep a specified percentage of the buffers clean.
2002-10-30 12:57:05 +01:00
*
* PUBLIC: int __memp_trickle __P((DB_ENV *, int, int *));
2001-03-05 01:42:05 +01:00
*/
int
2002-10-30 12:57:05 +01:00
__memp_trickle(dbenv, pct, nwrotep)
2001-03-05 01:42:05 +01:00
DB_ENV *dbenv;
int pct, *nwrotep;
{
DB_MPOOL *dbmp;
2002-10-30 12:57:05 +01:00
MPOOL *c_mp, *mp;
u_int32_t clean, dirty, i, total, dtmp;
int ret, wrote;
2001-03-05 01:42:05 +01:00
PANIC_CHECK(dbenv);
2002-10-30 12:57:05 +01:00
ENV_REQUIRES_CONFIG(dbenv,
dbenv->mp_handle, "memp_trickle", DB_INIT_MPOOL);
2001-03-05 01:42:05 +01:00
dbmp = dbenv->mp_handle;
mp = dbmp->reginfo[0].primary;
if (nwrotep != NULL)
*nwrotep = 0;
if (pct < 1 || pct > 100)
return (EINVAL);
/*
2002-10-30 12:57:05 +01:00
* If there are sufficient clean buffers, no buffers or no dirty
2001-03-05 01:42:05 +01:00
* buffers, we're done.
*
* XXX
2002-10-30 12:57:05 +01:00
* Using hash_page_dirty is our only choice at the moment, but it's not
* as correct as we might like in the presence of pools having more
* than one page size, as a free 512B buffer isn't the same as a free
* 8KB buffer.
*
* Loop through the caches counting total/dirty buffers.
2001-03-05 01:42:05 +01:00
*/
2002-10-30 12:57:05 +01:00
for (ret = 0, i = dirty = total = 0; i < mp->nreg; ++i) {
c_mp = dbmp->reginfo[i].primary;
total += c_mp->stat.st_pages;
__memp_stat_hash(&dbmp->reginfo[i], c_mp, &dtmp);
dirty += dtmp;
}
2001-03-05 01:42:05 +01:00
2002-10-30 12:57:05 +01:00
clean = total - dirty;
if (clean == total || (clean * 100) / total >= (u_long)pct)
return (0);
2001-03-05 01:42:05 +01:00
2002-10-30 12:57:05 +01:00
if (nwrotep == NULL)
nwrotep = &wrote;
ret = __memp_sync_int(dbenv, NULL,
((total * pct) / 100) - clean, DB_SYNC_TRICKLE, nwrotep);
2001-03-05 01:42:05 +01:00
2002-10-30 12:57:05 +01:00
mp->stat.st_page_trickle += *nwrotep;
2001-03-05 01:42:05 +01:00
2002-10-30 12:57:05 +01:00
return (ret);
2001-03-05 01:42:05 +01:00
}