On Mon, Sep 13, 2010 at 5:55 PM, Mel Gorman <mel@xxxxxxxxx> wrote: > On Mon, Sep 13, 2010 at 12:37:44AM +0900, Minchan Kim wrote: >> > > > > > <SNIP> >> > > > > > >> > > > > > + * in sleeping but cond_resched() is called in case the current process has >> > > > > > + * consumed its CPU quota. >> > > > > > + */ >> > > > > > +long wait_iff_congested(struct zone *zone, int sync, long timeout) >> > > > > > +{ >> > > > > > + long ret; >> > > > > > + unsigned long start = jiffies; >> > > > > > + DEFINE_WAIT(wait); >> > > > > > + wait_queue_head_t *wqh = &congestion_wqh[sync]; >> > > > > > + >> > > > > > + /* >> > > > > > + * If there is no congestion, check the amount of writeback. If there >> > > > > > + * is no significant writeback and no congestion, just cond_resched >> > > > > > + */ >> > > > > > + if (atomic_read(&nr_bdi_congested[sync]) == 0) { >> > > > > > + unsigned long inactive, writeback; >> > > > > > + >> > > > > > + inactive = zone_page_state(zone, NR_INACTIVE_FILE) + >> > > > > > + zone_page_state(zone, NR_INACTIVE_ANON); >> > > > > > + writeback = zone_page_state(zone, NR_WRITEBACK); >> > > > > > + >> > > > > > + /* >> > > > > > + * If less than half the inactive list is being written back, >> > > > > > + * reclaim might as well continue >> > > > > > + */ >> > > > > > + if (writeback < inactive / 2) { >> > > > > >> > > > > I am not sure this is best. >> > > > > >> > > > >> > > > I'm not saying it is. The objective is to identify a situation where >> > > > sleeping until the next write or congestion clears is pointless. We have >> > > > already identified that we are not congested so the question is "are we >> > > > writing a lot at the moment?". The assumption is that if there is a lot >> > > > of writing going on, we might as well sleep until one completes rather >> > > > than reclaiming more. >> > > > >> > > > This is the first effort at identifying pointless sleeps. Better ones >> > > > might be identified in the future but that shouldn't stop us making a >> > > > semi-sensible decision now. >> > > >> > > nr_bdi_congested is no problem since we have used it for a long time