00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014
00015 #include <stdlib.h>
00016 #endif
00017
00018 #include "db_int.h"
00019 #include "dbinc/db_shash.h"
00020 #include "dbinc/log.h"
00021 #include "dbinc/mp.h"
00022
00023 static int __memp_trickle __P((DB_ENV *, int, int *));
00024
00025
00026
00027
00028
00029
00030
00031 int
00032 __memp_trickle_pp(dbenv, pct, nwrotep)
00033 DB_ENV *dbenv;
00034 int pct, *nwrotep;
00035 {
00036 DB_THREAD_INFO *ip;
00037 int ret;
00038
00039 PANIC_CHECK(dbenv);
00040 ENV_REQUIRES_CONFIG(dbenv,
00041 dbenv->mp_handle, "memp_trickle", DB_INIT_MPOOL);
00042
00043 ENV_ENTER(dbenv, ip);
00044 REPLICATION_WRAP(dbenv, (__memp_trickle(dbenv, pct, nwrotep)), ret);
00045 ENV_LEAVE(dbenv, ip);
00046 return (ret);
00047 }
00048
00049
00050
00051
00052
00053 static int
00054 __memp_trickle(dbenv, pct, nwrotep)
00055 DB_ENV *dbenv;
00056 int pct, *nwrotep;
00057 {
00058 DB_MPOOL *dbmp;
00059 MPOOL *c_mp, *mp;
00060 u_int32_t dirty, i, total, dtmp, wrote;
00061 int n, ret;
00062
00063 dbmp = dbenv->mp_handle;
00064 mp = dbmp->reginfo[0].primary;
00065
00066 if (nwrotep != NULL)
00067 *nwrotep = 0;
00068
00069 if (pct < 1 || pct > 100)
00070 return (EINVAL);
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 for (ret = 0, i = dirty = total = 0; i < mp->nreg; ++i) {
00085 c_mp = dbmp->reginfo[i].primary;
00086 total += c_mp->stat.st_pages;
00087 __memp_stat_hash(&dbmp->reginfo[i], c_mp, &dtmp);
00088 dirty += dtmp;
00089 }
00090
00091
00092
00093
00094
00095 n = ((total * (u_int)pct) / 100) - (total - dirty);
00096 if (dirty == 0 || n <= 0)
00097 return (0);
00098
00099 ret = __memp_sync_int(
00100 dbenv, NULL, (u_int32_t)n, DB_SYNC_TRICKLE, &wrote);
00101 mp->stat.st_page_trickle += wrote;
00102 if (nwrotep != NULL)
00103 *nwrotep = (int)wrote;
00104
00105 return (ret);
00106 }