From bfa86281b980fee652fa89f854faf34a4b9689ad Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 2 Apr 2011 16:05:58 -0700 Subject: [PATCH] kernel - allow PG_NOTMETA to be set on regular files too * Allow this flag to be set for VM pages associated with regular files too, the flag prevents the related VM page from being swapcache'd. The flag is set by HAMMER on normal file buffer cache buffers when double buffering is enabled to prevent swapcache from caching the data twice. * This also fixes an issue when a large number of files exceeding the maxvnode limit are recycled, and double buffering is enabled along with vm.swapcache.data_enable. We do not want swapcache to try to cache the pages via the vnode, instead we'd rather it cache them via the block device (whos vnode doesn't get recycled). --- sys/vm/swap_pager.h | 2 ++ sys/vm/vm_swapcache.c | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sys/vm/swap_pager.h b/sys/vm/swap_pager.h index 6412b2d422..4f5539d09e 100644 --- a/sys/vm/swap_pager.h +++ b/sys/vm/swap_pager.h @@ -93,6 +93,8 @@ extern int vm_swap_cache_use; extern int vm_swap_anon_use; extern int vm_swapcache_read_enable; extern int vm_swapcache_inactive_heuristic; +extern int vm_swapcache_use_chflags; + extern struct blist *swapblist; extern int nswap_lowat, nswap_hiwat; diff --git a/sys/vm/vm_swapcache.c b/sys/vm/vm_swapcache.c index 9379b1c9b4..e0e8a8afc4 100644 --- a/sys/vm/vm_swapcache.c +++ b/sys/vm/vm_swapcache.c @@ -96,7 +96,7 @@ static int vm_swapcache_data_enable = 0; static int vm_swapcache_meta_enable = 0; static int vm_swapcache_maxswappct = 75; static int vm_swapcache_hysteresis; -static int vm_swapcache_use_chflags = 1; /* require chflags cache */ +int vm_swapcache_use_chflags = 1; /* require chflags cache */ static int64_t vm_swapcache_minburst = 10000000LL; /* 10MB */ static int64_t vm_swapcache_curburst = 4000000000LL; /* 4G after boot */ static int64_t vm_swapcache_maxburst = 2000000000LL; /* 2G nominal max */ @@ -315,6 +315,15 @@ vm_swapcache_writing(vm_page_t marker) switch(vp->v_type) { case VREG: + /* + * PG_NOTMETA generically means 'don't swapcache this', + * and HAMMER will set this for regular data buffers + * (and leave it unset for meta-data buffers) as + * appropriate when double buffering is enabled. + */ + if (m->flags & PG_NOTMETA) + continue; + /* * If data_enable is 0 do not try to swapcache data. * If use_chflags is set then only swapcache data for @@ -334,8 +343,10 @@ vm_swapcache_writing(vm_page_t marker) break; case VCHR: /* - * The PG_NOTMETA flag only applies to pages - * associated with block devices. + * PG_NOTMETA generically means 'don't swapcache this', + * and HAMMER will set this for regular data buffers + * (and leave it unset for meta-data buffers) as + * appropriate when double buffering is enabled. */ if (m->flags & PG_NOTMETA) continue; @@ -534,7 +545,9 @@ vm_swapcache_cleaning(vm_object_t marker) lwkt_gettoken(&vm_token); lwkt_gettoken(&vmobj_token); - while ((object = TAILQ_NEXT(object, object_list)) != NULL && count--) { + while ((object = TAILQ_NEXT(object, object_list)) != NULL) { + if (--count <= 0) + break; if (object->type != OBJT_VNODE) continue; if ((object->flags & OBJ_DEAD) || object->swblock_count == 0) -- 2.41.0