Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

mp_trickle.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: mp_trickle.c,v 12.4 2005/10/07 20:21:33 ubell Exp $
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  * __memp_trickle_pp --
00027  *      DB_ENV->memp_trickle pre/post processing.
00028  *
00029  * PUBLIC: int __memp_trickle_pp __P((DB_ENV *, int, int *));
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  * __memp_trickle --
00051  *      DB_ENV->memp_trickle.
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          * If there are sufficient clean buffers, no buffers or no dirty
00074          * buffers, we're done.
00075          *
00076          * XXX
00077          * Using hash_page_dirty is our only choice at the moment, but it's not
00078          * as correct as we might like in the presence of pools having more
00079          * than one page size, as a free 512B buffer isn't the same as a free
00080          * 8KB buffer.
00081          *
00082          * Loop through the caches counting total/dirty buffers.
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          * Be careful in modifying this calculation, total may be 0.
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 }

Generated on Sun Dec 25 12:14:41 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2