本文共 2551 字,大约阅读时间需要 8 分钟。
static noinline_for_stack unsigned long shrink_inactive_list(unsigned long nr_to_scan,
struct lruvec *lruvec, struct scan_control *sc, enum lru_list lru)
{
LIST_HEAD(page_list);
unsignedlong nr_scanned;
unsignedlong nr_reclaimed = 0;
unsignedlong nr_taken;
unsignedlong nr_dirty = 0;
unsignedlong nr_congested = 0;
unsignedlong nr_unqueued_dirty = 0;
unsignedlong nr_writeback = 0;
unsignedlong nr_immediate = 0;
isolate_mode_tisolate_mode = 0;
int file = is_file_lru(lru);
struct zone *zone = lruvec_zone(lruvec);
struct zone_reclaim_stat *reclaim_stat =&lruvec->reclaim_stat;
while (unlikely(too_many_isolated(zone,file, sc))) {
congestion_wait(BLK_RW_ASYNC, HZ/10);
if(fatal_signal_pending(current))
returnSWAP_CLUSTER_MAX;
}
lru_add_drain();
if (!sc->may_unmap)
isolate_mode|= ISOLATE_UNMAPPED;
if (!sc->may_writepage)
isolate_mode|= ISOLATE_CLEAN;
spin_lock_irq(&zone->lru_lock);
nr_taken =isolate_lru_pages(nr_to_scan, lruvec, &page_list,&nr_scanned, sc,isolate_mode, lru);
update_lru_size(lruvec,lru, -nr_taken);
__mod_zone_page_state(zone,NR_ISOLATED_ANON + file, nr_taken);
reclaim_stat->recent_scanned[file]+= nr_taken;
if (global_reclaim(sc)) {
__mod_zone_page_state(zone,NR_PAGES_SCANNED, nr_scanned);
if(current_is_kswapd())
__count_zone_vm_events(PGSCAN_KSWAPD,zone, nr_scanned);
else
__count_zone_vm_events(PGSCAN_DIRECT,zone, nr_scanned);
}
spin_unlock_irq(&zone->lru_lock);
if(nr_taken == 0)
return0;
nr_reclaimed=shrink_page_list(&page_list,zone,sc,TU_UNMAP,&nr_dirty,
&nr_unqueued_dirty,&nr_congested,&nr_writeback,
&nr_immediate,false);
spin_lock_irq(&zone->lru_lock);
if (global_reclaim(sc)) {
if(current_is_kswapd())
__count_zone_vm_events(PGSTEAL_KSWAPD,zone, nr_reclaimed);
else
__count_zone_vm_events(PGSTEAL_DIRECT,zone, nr_reclaimed);
}
putback_inactive_pages(lruvec,&page_list);
__mod_zone_page_state(zone,NR_ISOLATED_ANON + file, -nr_taken);
spin_unlock_irq(&zone->lru_lock);
mem_cgroup_uncharge_list(&page_list);
free_hot_cold_page_list(&page_list,true);
if (nr_writeback && nr_writeback== nr_taken)
set_bit(ZONE_WRITEBACK,&zone->flags);
if (sane_reclaim(sc)) {
if(nr_dirty && nr_dirty == nr_congested)
set_bit(ZONE_CONGESTED,&zone->flags);
if(nr_unqueued_dirty == nr_taken)
set_bit(ZONE_DIRTY,&zone->flags);
if(nr_immediate && current_may_throttle())
congestion_wait(BLK_RW_ASYNC,HZ/10);
}
if(!sc->hibernation_mode && !current_is_kswapd() &¤t_may_throttle())
wait_iff_congested(zone,BLK_RW_ASYNC, HZ/10);
trace_mm_vmscan_lru_shrink_inactive(zone,nr_scanned, nr_reclaimed,sc->priority, file);
return nr_reclaimed;
}
转载地址:http://axqti.baihongyu.com/