Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Nov 2017 12:39:11 -0800
From:      Larry McVoy <lm@mcvoy.com>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Larry McVoy <lm@mcvoy.com>, Warner Losh <imp@bsdimp.com>, Scott Long <scottl@netflix.com>, Kevin Bowling <kbowling@llnw.com>, Drew Gallatin <gallatin@netflix.com>, "freebsd-arch@freebsd.org" <freebsd-arch@freebsd.org>
Subject:   Re: small patch for pageout. Comments?
Message-ID:  <20171130203911.GC30262@mcvoy.com>
In-Reply-To: <20171130203725.GG2272@kib.kiev.ua>
References:  <20171130173424.GA811@mcvoy.com> <CANCZdfqL9ZsKTfFi%2BvsCTh3yaNjtwaYYY3fvivdbNybBnujawg@mail.gmail.com> <20171130184923.GA30262@mcvoy.com> <20171130193213.GF2272@kib.kiev.ua> <20171130203047.GB30262@mcvoy.com> <20171130203725.GG2272@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
Perhaps I misunderstood, I thought your patch was instead of the pageout
patch.  Is that not the case?

On Thu, Nov 30, 2017 at 10:37:25PM +0200, Konstantin Belousov wrote:
> On Thu, Nov 30, 2017 at 12:30:47PM -0800, Larry McVoy wrote:
> > I'll give this patch a try and compare to the pageout patch.
> 
> What do you mean by 'compare to ...' ?
> 
> BTW, below are some fixes which I found when re-read the changes.
> It messed up counters/timeouts.  Better use this.
> 
> diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c
> index ece496407c2..48b3934ddd5 100644
> --- a/sys/vm/vm_fault.c
> +++ b/sys/vm/vm_fault.c
> @@ -134,6 +134,16 @@ static void vm_fault_dontneed(const struct faultstate *fs, vm_offset_t vaddr,
>  static void vm_fault_prefault(const struct faultstate *fs, vm_offset_t addra,
>  	    int backward, int forward);
>  
> +static int vm_pfault_oom_attempts = 3;
> +SYSCTL_INT(_vm, OID_AUTO, pfault_oom_attempts, CTLFLAG_RWTUN,
> +    &vm_pfault_oom_attempts, 0,
> +    "");
> +
> +static int vm_pfault_oom_wait = 10;
> +SYSCTL_INT(_vm, OID_AUTO, pfault_oom_wait, CTLFLAG_RWTUN,
> +    &vm_pfault_oom_wait, 0,
> +    "");
> +
>  static inline void
>  release_page(struct faultstate *fs)
>  {
> @@ -531,7 +541,7 @@ vm_fault_hold(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type,
>  	vm_pindex_t retry_pindex;
>  	vm_prot_t prot, retry_prot;
>  	int ahead, alloc_req, behind, cluster_offset, error, era, faultcount;
> -	int locked, nera, result, rv;
> +	int locked, nera, oom, result, rv;
>  	u_char behavior;
>  	boolean_t wired;	/* Passed by reference. */
>  	bool dead, hardfault, is_first_object_locked;
> @@ -543,6 +553,8 @@ vm_fault_hold(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type,
>  	hardfault = false;
>  
>  RetryFault:;
> +	oom = 0;
> +RetryFault_oom:;
>  
>  	/*
>  	 * Find the backing store object and offset into it to begin the
> @@ -787,7 +799,17 @@ RetryFault:;
>  			}
>  			if (fs.m == NULL) {
>  				unlock_and_deallocate(&fs);
> -				VM_WAITPFAULT;
> +				if (vm_pfault_oom_attempts < 0 ||
> +				    oom < vm_pfault_oom_attempts) {
> +					oom++;
> +					vm_waitpfault(vm_pfault_oom_wait);
> +					goto RetryFault_oom;
> +				}
> +				if (bootverbose)
> +					printf(
> +	"proc %d (%s) failed to alloc page on fault, starting OOM\n",
> +					    curproc->p_pid, curproc->p_comm);
> +				vm_pageout_oom(VM_OOM_MEM);
>  				goto RetryFault;
>  			}
>  		}
> diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
> index 4711af9d16d..67c8ddd4b92 100644
> --- a/sys/vm/vm_page.c
> +++ b/sys/vm/vm_page.c
> @@ -2724,7 +2724,7 @@ vm_page_alloc_fail(vm_object_t object, int req)
>   *	  this balance without careful testing first.
>   */
>  void
> -vm_waitpfault(void)
> +vm_waitpfault(int wp)
>  {
>  
>  	mtx_lock(&vm_page_queue_free_mtx);
> @@ -2734,7 +2734,7 @@ vm_waitpfault(void)
>  	}
>  	vm_pages_needed = true;
>  	msleep(&vm_cnt.v_free_count, &vm_page_queue_free_mtx, PDROP | PUSER,
> -	    "pfault", 0);
> +	    "pfault", wp * hz);
>  }
>  
>  struct vm_pagequeue *
> diff --git a/sys/vm/vm_pageout.h b/sys/vm/vm_pageout.h
> index 2cdb1492fab..bf09d7142d0 100644
> --- a/sys/vm/vm_pageout.h
> +++ b/sys/vm/vm_pageout.h
> @@ -96,11 +96,10 @@ extern bool vm_pages_needed;
>   *	Signal pageout-daemon and wait for it.
>   */
>  
> -extern void pagedaemon_wakeup(void);
> +void pagedaemon_wakeup(void);
>  #define VM_WAIT vm_wait()
> -#define VM_WAITPFAULT vm_waitpfault()
> -extern void vm_wait(void);
> -extern void vm_waitpfault(void);
> +void vm_wait(void);
> +void vm_waitpfault(int wp);
>  
>  #ifdef _KERNEL
>  int vm_pageout_flush(vm_page_t *, int, int, int, int *, boolean_t *);

-- 
---
Larry McVoy            	     lm at mcvoy.com             http://www.mcvoy.com/lm 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171130203911.GC30262>