diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2009-08-08 15:04:44 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2009-08-08 15:04:44 +0000 |
commit | 2d58dd87326d6060063b3fd69af5111759024a44 (patch) | |
tree | 569b9a723f8b8ef0762f2537b5c6565cafecba40 /sys | |
parent | 48c93dcab82091d4520edffb2ce17ab53bb4a978 (diff) |
two things:
1) fix buffer cache low water mark to allow for extremely low memory machines
without dying
2) Add "show bcstats" to ddb to allow for looking at the buffer cache statistics in ddb
ok art@ oga@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/ddb/db_command.c | 12 | ||||
-rw-r--r-- | sys/ddb/db_command.h | 3 | ||||
-rw-r--r-- | sys/kern/vfs_bio.c | 40 | ||||
-rw-r--r-- | sys/sys/mount.h | 5 |
4 files changed, 48 insertions, 12 deletions
diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c index c6ca04ff0a9..8e4b9239b38 100644 --- a/sys/ddb/db_command.c +++ b/sys/ddb/db_command.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_command.c,v 1.54 2009/07/15 19:05:14 miod Exp $ */ +/* $OpenBSD: db_command.c,v 1.55 2009/08/08 15:04:43 beck Exp $ */ /* $NetBSD: db_command.c,v 1.20 1996/03/30 22:30:05 christos Exp $ */ /* @@ -439,6 +439,15 @@ db_uvmexp_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif) uvmexp_print(db_printf); } +void bcstats_print(int (*)(const char *, ...)); + +/*ARGSUSED*/ +void +db_bcstats_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif) +{ + bcstats_print(db_printf); +} + /* * 'show' commands */ @@ -456,6 +465,7 @@ struct db_command db_show_all_cmds[] = { struct db_command db_show_cmds[] = { { "all", NULL, 0, db_show_all_cmds }, + { "bcstats", db_bcstats_print_cmd, 0, NULL }, { "breaks", db_listbreak_cmd, 0, NULL }, { "buf", db_buf_print_cmd, 0, NULL }, { "extents", db_extent_print_cmd, 0, NULL }, diff --git a/sys/ddb/db_command.h b/sys/ddb/db_command.h index 867a05d703c..a2d7bde4c92 100644 --- a/sys/ddb/db_command.h +++ b/sys/ddb/db_command.h @@ -1,4 +1,4 @@ -/* $OpenBSD: db_command.h,v 1.24 2009/06/17 01:30:30 thib Exp $ */ +/* $OpenBSD: db_command.h,v 1.25 2009/08/08 15:04:43 beck Exp $ */ /* $NetBSD: db_command.h,v 1.8 1996/02/05 01:56:55 christos Exp $ */ /* @@ -65,6 +65,7 @@ void db_boot_poweroff_cmd(db_expr_t, int, db_expr_t, char *); void db_stack_trace_cmd(db_expr_t, int, db_expr_t, char *); void db_dmesg_cmd(db_expr_t, int, db_expr_t, char *); void db_show_panic_cmd(db_expr_t, int, db_expr_t, char *); +void db_bcstats_print_cmd(db_expr_t, int, db_expr_t, char *); extern db_addr_t db_dot, db_last_addr, db_prev, db_next; diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 045bd969ee3..f2821c6b233 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.119 2009/08/02 16:28:40 beck Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.120 2009/08/08 15:04:43 beck Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /* @@ -112,6 +112,7 @@ long maxcleanpages; long backoffpages; /* backoff counter for page allocations */ long buflowpages; /* bufpages low water mark */ long bufhighpages; /* bufpages high water mark */ +long bufbackpages; /* number of pages we back off when asked to shrink */ /* XXX - should be defined here. */ extern int bufcachepercent; @@ -213,6 +214,14 @@ bufinit(void) */ buflowpages = physmem * 10 / 100; + /* + * set bufbackpages to 100 pages, or 10 percent of the low water mark + * if we don't have that many pages. + */ + + bufbackpages = buflowpages * 10 / 100; + if (bufbackpages > 100) + bufbackpages = 100; if (bufkvm == 0) bufkvm = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 10; @@ -341,13 +350,13 @@ bufbackoff() if (bufpages <= buflowpages) return(-1); - if (bufpages - BACKPAGES >= buflowpages) - d = BACKPAGES; + if (bufpages - bufbackpages >= buflowpages) + d = bufbackpages; else d = bufpages - buflowpages; - backoffpages = BACKPAGES; + backoffpages = bufbackpages; bufadjust(bufpages - d); - backoffpages = BACKPAGES; + backoffpages = bufbackpages; return(0); } @@ -963,8 +972,8 @@ buf_get(struct vnode *vp, daddr64_t blkno, size_t size) */ if ((backoffpages == 0) && (bufpages < bufhighpages)) { if ( gcount == 0 ) { - bufadjust(bufpages + BACKPAGES); - gcount += BACKPAGES; + bufadjust(bufpages + bufbackpages); + gcount += bufbackpages; } else gcount--; } @@ -1220,3 +1229,20 @@ biodone(struct buf *bp) } } } + +#ifdef DDB +void bcstats_print(int (*)(const char *, ...)); +/* + * bcstats_print: ddb hook to print interesting buffer cache counters + */ +void +bcstats_print(int (*pr)(const char *, ...)) +{ + (*pr)("Current Buffer Cache status:\n"); + (*pr)("numbufs %d freebufs %d\n", bcstats.numbufs, bcstats.freebufs); + (*pr)("bufpages %d freepages %d dirtypages %d\n", bcstats.numbufpages, + bcstats.numfreepages, bcstats.numdirtypages); + (*pr)("pendingreads %d, pendingwrites %d\n", + bcstats.pendingreads, bcstats.pendingwrites); +} +#endif diff --git a/sys/sys/mount.h b/sys/sys/mount.h index ac3da0f4959..bee86c7b136 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.h,v 1.96 2009/08/02 16:28:40 beck Exp $ */ +/* $OpenBSD: mount.h,v 1.97 2009/08/08 15:04:43 beck Exp $ */ /* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */ /* @@ -504,9 +504,8 @@ struct bcachestats { int64_t cachehits; /* total reads found in cache */ }; #ifdef _KERNEL -#define BACKPAGES 100 extern struct bcachestats bcstats; -extern long buflowpages, bufhighpages; +extern long buflowpages, bufhighpages, bufbackpages; #define BUFPAGES_DEFICIT (((buflowpages - bcstats.numbufpages) < 0) ? 0 \ : buflowpages - bcstats.numbufpages) extern int bufcachepercent; |