mariadb/storage/bdb/mp/mp_trickle.c

107 lines
2.2 KiB
C
Raw Normal View History

2001-03-04 19:42:05 -05:00
/*-
* See the file LICENSE for redistribution information.
*
2005-12-05 10:27:46 -08:00
* Copyright (c) 1996-2005
2001-03-04 19:42:05 -05:00
* Sleepycat Software. All rights reserved.
2005-07-20 15:48:22 -07:00
*
2005-12-05 10:27:46 -08:00
* $Id: mp_trickle.c,v 12.4 2005/10/07 20:21:33 ubell Exp $
2001-03-04 19:42:05 -05:00
*/
2005-07-20 15:48:22 -07:00
#include "db_config.h"
2001-03-04 19:42:05 -05:00
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <stdlib.h>
#endif
#include "db_int.h"
2002-10-30 15:57:05 +04:00
#include "dbinc/db_shash.h"
2005-07-20 15:48:22 -07:00
#include "dbinc/log.h"
2002-10-30 15:57:05 +04:00
#include "dbinc/mp.h"
2001-03-04 19:42:05 -05:00
2005-07-20 15:48:22 -07:00
static int __memp_trickle __P((DB_ENV *, int, int *));
2001-03-04 19:42:05 -05:00
/*
2005-07-20 15:48:22 -07:00
* __memp_trickle_pp --
* DB_ENV->memp_trickle pre/post processing.
2002-10-30 15:57:05 +04:00
*
2005-07-20 15:48:22 -07:00
* PUBLIC: int __memp_trickle_pp __P((DB_ENV *, int, int *));
2001-03-04 19:42:05 -05:00
*/
int
2005-07-20 15:48:22 -07:00
__memp_trickle_pp(dbenv, pct, nwrotep)
2001-03-04 19:42:05 -05:00
DB_ENV *dbenv;
int pct, *nwrotep;
{
2005-12-05 10:27:46 -08:00
DB_THREAD_INFO *ip;
int ret;
2001-03-04 19:42:05 -05:00
PANIC_CHECK(dbenv);
2002-10-30 15:57:05 +04:00
ENV_REQUIRES_CONFIG(dbenv,
dbenv->mp_handle, "memp_trickle", DB_INIT_MPOOL);
2001-03-04 19:42:05 -05:00
2005-12-05 10:27:46 -08:00
ENV_ENTER(dbenv, ip);
REPLICATION_WRAP(dbenv, (__memp_trickle(dbenv, pct, nwrotep)), ret);
ENV_LEAVE(dbenv, ip);
2005-07-20 15:48:22 -07:00
return (ret);
}
/*
* __memp_trickle --
* DB_ENV->memp_trickle.
*/
static int
__memp_trickle(dbenv, pct, nwrotep)
DB_ENV *dbenv;
int pct, *nwrotep;
{
DB_MPOOL *dbmp;
MPOOL *c_mp, *mp;
u_int32_t dirty, i, total, dtmp, wrote;
int n, ret;
2001-03-04 19:42:05 -05: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 15:57:05 +04:00
* If there are sufficient clean buffers, no buffers or no dirty
2001-03-04 19:42:05 -05:00
* buffers, we're done.
*
* XXX
2002-10-30 15:57:05 +04: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-04 19:42:05 -05:00
*/
2002-10-30 15:57:05 +04: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-04 19:42:05 -05:00
2005-07-20 15:48:22 -07:00
/*
* !!!
* Be careful in modifying this calculation, total may be 0.
*/
n = ((total * (u_int)pct) / 100) - (total - dirty);
if (dirty == 0 || n <= 0)
2002-10-30 15:57:05 +04:00
return (0);
2001-03-04 19:42:05 -05:00
2005-07-20 15:48:22 -07:00
ret = __memp_sync_int(
dbenv, NULL, (u_int32_t)n, DB_SYNC_TRICKLE, &wrote);
mp->stat.st_page_trickle += wrote;
if (nwrotep != NULL)
*nwrotep = (int)wrote;
2001-03-04 19:42:05 -05:00
2002-10-30 15:57:05 +04:00
return (ret);
2001-03-04 19:42:05 -05:00
}