You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by mi...@apache.org on 2010/09/29 23:34:49 UTC
svn commit: r1002854 - in /httpd/httpd/trunk: CHANGES
docs/manual/programs/htcacheclean.xml support/htcacheclean.c
Author: minfrin
Date: Wed Sep 29 21:34:48 2010
New Revision: 1002854
URL: http://svn.apache.org/viewvc?rev=1002854&view=rev
Log:
htcacheclean: Allow the option to round up file sizes to a given
block size, improving the accuracy of disk usage.
Modified:
httpd/httpd/trunk/CHANGES
httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml
httpd/httpd/trunk/support/htcacheclean.c
Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1002854&r1=1002853&r2=1002854&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Wed Sep 29 21:34:48 2010
@@ -2,6 +2,9 @@
Changes with Apache 2.3.9
+ *) htcacheclean: Allow the option to round up file sizes to a given
+ block size, improving the accuracy of disk usage. [Graham Leggett]
+
*) mod_ssl: Add authz providers for use with mod_authz_core and its
RequireAny/RequireAll containers: 'ssl' (equivalent to SSLRequireSSL),
'ssl-verify-client' (for use with 'SSLVerifyClient optional'), and
Modified: httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml?rev=1002854&r1=1002853&r2=1002854&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml (original)
+++ httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml Wed Sep 29 21:34:48 2010
@@ -45,6 +45,7 @@
[ -<strong>t</strong> ]
[ -<strong>r</strong> ]
[ -<strong>n</strong> ]
+ [ -<strong>R</strong><var>round</var> ]
-<strong>p</strong><var>path</var>
-<strong>l</strong><var>limit</var></code></p>
@@ -53,6 +54,7 @@
[ -<strong>t</strong> ]
[ -<strong>i</strong> ]
[ -<strong>P</strong><var>pidfile</var> ]
+ [ -<strong>R</strong><var>round</var> ]
-<strong>d</strong><var>interval</var>
-<strong>p</strong><var>path</var>
-<strong>l</strong><var>limit</var></code></p>
@@ -61,6 +63,7 @@
[ -<strong>D</strong> ]
[ -<strong>v</strong> ]
[ -<strong>t</strong> ]
+ [ -<strong>R</strong><var>round</var> ]
-<strong>p</strong><var>path</var>
<var>url</var></code></p>
</section>
@@ -110,6 +113,11 @@
<dd>Specify <var>pidfile</var> as the name of the file to write the
process ID to when daemonized.</dd>
+ <dt><code>-R<var>round</var></code></dt>
+ <dd>Specify <var>round</var> as the amount to round sizes up to, to
+ compensate for disk block sizes. Set to the block size of the cache
+ partition.</dd>
+
<dt><code>-l<var>limit</var></code></dt>
<dd>Specify <var>limit</var> as the total disk cache size limit. The value
is expressed in bytes by default (or attaching <code>B</code> to the
Modified: httpd/httpd/trunk/support/htcacheclean.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/htcacheclean.c?rev=1002854&r1=1002853&r2=1002854&view=diff
==============================================================================
--- httpd/httpd/trunk/support/htcacheclean.c (original)
+++ httpd/httpd/trunk/support/htcacheclean.c Wed Sep 29 21:34:48 2010
@@ -233,6 +233,16 @@ static void printstats(char *path, struc
(int)(s->dexpired), (int)(s->dfresh));
}
+/**
+ * Round the value up to the given threshold.
+ */
+static apr_size_t round_up(apr_size_t val, apr_off_t round) {
+ if (round > 1) {
+ return ((val + round - 1) / round) * round;
+ }
+ return val;
+}
+
/*
* delete a single file
*/
@@ -655,7 +665,7 @@ static int process_dir(char *path, apr_p
/*
* purge cache entries
*/
-static void purge(char *path, apr_pool_t *pool, apr_off_t max)
+static void purge(char *path, apr_pool_t *pool, apr_off_t max, apr_off_t round)
{
ENTRY *e, *n, *oldest;
@@ -670,8 +680,8 @@ static void purge(char *path, apr_pool_t
for (e = APR_RING_FIRST(&root);
e != APR_RING_SENTINEL(&root, _entry, link);
e = APR_RING_NEXT(e, link)) {
- s.sum += e->hsize;
- s.sum += e->dsize;
+ s.sum += round_up(e->hsize, round);
+ s.sum += round_up(e->dsize, round);
s.entries++;
}
@@ -692,8 +702,8 @@ static void purge(char *path, apr_pool_t
n = APR_RING_NEXT(e, link);
if (e->response_time > now || e->htime > now || e->dtime > now) {
delete_entry(path, e->basename, pool);
- s.sum -= e->hsize;
- s.sum -= e->dsize;
+ s.sum -= round_up(e->hsize, round);
+ s.sum -= round_up(e->dsize, round);
s.entries--;
s.dfuture++;
APR_RING_REMOVE(e, link);
@@ -717,8 +727,8 @@ static void purge(char *path, apr_pool_t
n = APR_RING_NEXT(e, link);
if (e->expire != APR_DATE_BAD && e->expire < now) {
delete_entry(path, e->basename, pool);
- s.sum -= e->hsize;
- s.sum -= e->dsize;
+ s.sum -= round_up(e->hsize, round);
+ s.sum -= round_up(e->dsize, round);
s.entries--;
s.dexpired++;
APR_RING_REMOVE(e, link);
@@ -754,8 +764,8 @@ static void purge(char *path, apr_pool_t
}
delete_entry(path, oldest->basename, pool);
- s.sum -= oldest->hsize;
- s.sum -= oldest->dsize;
+ s.sum -= round_up(oldest->hsize, round);
+ s.sum -= round_up(oldest->dsize, round);
s.entries--;
s.dfresh++;
APR_RING_REMOVE(oldest, link);
@@ -1000,6 +1010,8 @@ static void usage(const char *error)
NL
" -P Specify PIDFILE as the file to write the pid to." NL
NL
+ " -R Specify amount to round sizes up to." NL
+ NL
" -l Specify LIMIT as the total disk cache size limit. Attach 'K'" NL
" or 'M' to the number for specifying KBytes or MBytes." NL
NL
@@ -1057,7 +1069,7 @@ static void log_pid(apr_pool_t *pool, co
*/
int main(int argc, const char * const argv[])
{
- apr_off_t max;
+ apr_off_t max, round;
apr_time_t current, repeat, delay, previous;
apr_status_t status;
apr_pool_t *pool, *instance;
@@ -1076,6 +1088,7 @@ int main(int argc, const char * const ar
dryrun = 0;
limit_found = 0;
max = 0;
+ round = 0;
verbose = 0;
realclean = 0;
benice = 0;
@@ -1105,7 +1118,7 @@ int main(int argc, const char * const ar
apr_getopt_init(&o, pool, argc, argv);
while (1) {
- status = apr_getopt(o, "iDnvrtd:l:L:p:P:", &opt, &arg);
+ status = apr_getopt(o, "iDnvrtd:l:L:p:P:R:", &opt, &arg);
if (status == APR_EOF) {
break;
}
@@ -1113,6 +1126,8 @@ int main(int argc, const char * const ar
usage(NULL);
}
else {
+ char *end;
+ apr_status_t rv;
switch (opt) {
case 'i':
if (intelligent) {
@@ -1174,9 +1189,6 @@ int main(int argc, const char * const ar
limit_found = 1;
do {
- apr_status_t rv;
- char *end;
-
rv = apr_strtoff(&max, arg, &end, 10);
if (rv == APR_SUCCESS) {
if ((*end == 'K' || *end == 'k') && !end[1]) {
@@ -1218,6 +1230,27 @@ int main(int argc, const char * const ar
pidfilename = apr_pstrdup(pool, arg);
break;
+ case 'R':
+ if (round) {
+ usage_repeated_arg(pool, opt);
+ }
+ rv = apr_strtoff(&round, arg, &end, 10);
+ if (rv == APR_SUCCESS) {
+ if (*end) {
+ usage(apr_psprintf(pool, "Invalid round value: %s"
+ APR_EOL_STR APR_EOL_STR, arg));
+ }
+ else if (round < 0) {
+ usage(apr_psprintf(pool, "Round value must be positive: %s"
+ APR_EOL_STR APR_EOL_STR, arg));
+ }
+ }
+ if (rv != APR_SUCCESS) {
+ usage(apr_psprintf(pool, "Invalid round value: %s"
+ APR_EOL_STR APR_EOL_STR, arg));
+ }
+ break;
+
} /* switch */
} /* else */
} /* while */
@@ -1368,7 +1401,7 @@ int main(int argc, const char * const ar
if (dowork && !interrupted) {
if (!process_dir(path, instance) && !interrupted) {
- purge(path, instance, max);
+ purge(path, instance, max, round);
}
else if (!isdaemon && !interrupted) {
apr_file_printf(errfile, "An error occurred, cache cleaning "