vm_lowmem is prevented every 2**31 ticks

Ian Lepore ian at freebsd.org
Wed Aug 5 23:59:33 UTC 2015


On Wed, 2015-08-05 at 19:48 -0400, Ryan Stone wrote:
> Currently vm_pageout_scan() uses a calculation on ticks to rate-limit the
> number of vm_lowmem() events.  The calculation that it uses is:
> 
> if (vmd == &vm_dom[0] && pass > 0 &&
>     (ticks - lowmem_ticks) / hz >= lowmem_period)
> 
> 
> The problem with this code is that there is no guarantee that
> vm_pageout_scan() will be called with pass > 0 within any time period.
> This can mean that (for example) lowmem_ticks could have been 0 an
> arbitrarily long time ago, and if ticks happens to be negative when we are
> running low on memory, the result of ticks - lowmem_ticks will be negative
> and the condition will not be true until ticks goes positive again.
> 
> A coworker suggested casting the result of the subtraction to a u_int.
> This narrows the window considerably (down to 2 * lowmem_period seconds),
> but it's not possible to eliminate the problem entirely as long as we use
> ticks.  I am tempted to just call getbintime() instead.  Low memory events
> should be infrequent enough that calling getbintime() should be ok.
> 
> Unless somebody has an objection or an alternate solution, I'll put
> together a patch using getbintime() and get that into phabricator.

If you're measuring elapsed time, please use getbinuptime() rather than
the time of day clock (which can be stepped arbitrarily).

Hey wait a sec... if it's currently some_ticks/hz it's counting seconds,
right?  So no need to mess with bintimes, if whole seconds are good
enough just use the global time_uptime.

-- Ian



More information about the freebsd-hackers mailing list