Simon Mackinlay wrote: >>I think what you want to do is to increase dirty_background_ratio and >>dirty_ratio, so the system buffers _more_ dirty data before lighting up the >>disk. But it shouldn't be disabled altogether. > > The greater component of functional gain from laptop-mode derives > from the notion that we want to schedule writeout events with some > controlled period (default in documentation is 10min interval, at > next journal commit event, or at next read event, whichever arrives > first). > > Is it possible instead to put a ceiling on the amount of data we're > willing to accept for writeout and somehow apply back-pressure > to the task (or even, more coarsely, to the system as a whole), > rather than arbitrarily stretching these ratios to ${MAGIC NUMBER} > when laptop mode is active - given that the overall goal is to > control what triggers may result in disk activity. > > In other words - what happens at present if we're unable to > accept more data into the system buffers because we're already > out of memory (and quite possibly now awaiting completion of > a writeout), and are we not able to just allow this condition > (of being apparently out of memory - and presumably stalling > writers) to persist until either of... > > * the timers controlled via laptop-mode permit a writeout event > * a journal commit event > * a read event > > ... occurs? > > Apologies in advance for the naivete - but this functionality > seems too useful to ignore, particularly considering that MTBF > figures and warranties for notebook drives tend to put a ceiling > against the number of operational hours for which the unit will be > supported - also considering that the periodicity of both writeout > and journal commit are tunable (with safe defaults), and that the > mode itself is not default (ie, notebook users, here's a gun, > don't shoot your feet would seem to apply?). I think Andrew has a point. The dirty writebacks (controlled by dirty_ratio and dirty_background_ratio) should simply be set to possibly higher and, more importantly, *equal* values. This will effectively disable background writeouts (which are good for speed, but bad for battery power because it will spin up your disk sooner than necessary), but it will not make the system keep accumulating dirty pages ad infinitum like the current laptop_mode patch does. IMO, if a writer writes enough to have filled up 40% of all available memory with dirty pages, the disk deserves to spin up. Find attached version 5 of the laptop-mode patch. It includes the following changes: * Fix for supporting 64-bit sector_t (thanks hugang!) * Simplified the design a bit, saved us a timer. It now only wakes up kupdate to write back stuff: kupdate disregards age while laptop_mode is active, so it writes back everything anyway. * balance_dirty_pages does it's job again in laptop mode. However, when it decides to write back pages, it now also calls disk_is_spun_up(), which makes sure that the remainder of the dirty pages are written immediately as well. That means that if a writer writes an amount of data that is about 50% of memory, and dirty_ratio is 40%, that the disk will spin up after 4/5ths of the data is written, will write the full 4/5ths of the data at once, and then the disk can spin down again because the remaining 10% will be not be written until the next spin-up. * The control script now sets dirty_background_ratio to the same value as dirty_ratio, so that background writes are effectively disabled. This enables a writer to fill up up to dirty_ratio (default 40%) of the memory with dirty blocks before the disk is spun up. * Includes control script (scripts/laptop_mode). * Includes docs (Documentation/laptop-mode.txt). -- Bart