Neighbor subsystem of linux protocol stack (garbage collection seven)

  
 

Garbage Collection for Neighbors To avoid wasting unnecessary storage space, the neighbor subsystem maintains a garbage collection mechanism that deletes invalid or long-term neighbor entries. Recall that there is a timer struct timer_list gc_timer structure in the neighbor table (neigh_table), let's see how it is initialized. In neigh_table_init() {…….init_timer(&tbl->gc_timer);tbl->gc_timer.data = (unsigned long)tbl;tbl->gc_timer.function = neigh_periodic_timer;tbl-> Gc_timer.expires = now + 1; add_timer(&tbl->gc_timer;…} After a tick, the timer expires, running the timer handler neigh_periodic_timer() static void neigh_periodic_timer(unsigned long arg){struct neigh_table * Tbl = (struct neigh_table *) arg; struct neighbour *n, **np;unsigned long expire, now = jiffies;NEIGH_CACHE_STAT_INC(tbl, periodic_gc_runs);write_lock(&tbl->lock);/** periodically recompute ReachableTime From random function*///Randomly initialize REACHABLE state timeout time every 300HZ if (time_after(now, tbl->last_rand + 300 * HZ)) {struct neigh_parms *p;tbl->last_rand = now;for (p = &tbl->parms; p; p = p->next)p->reachable_time =neigh_rand_reach_time(p->base_reachable_time);}//hash_chain_gc is processed in the initialization function //so, here Zero np = &tbl->has H_buckets[tbl->hash_chain_gc];//Have hash_chain_gc to the next item, if it exceeds the maximum value hash_mash//then return to the initial value tbl->hash_chain_gc = ((tbl->hash_chain_gc + 1) & Tbl->hash_mask);while ((n = *np) != NULL) {unsigned int state;write_lock(&n->lock);state = n->nud_state;//if the corresponding is static Item, or is being initialized by the timer if (state & (NUD_PERMANENT

Copyright © Windows knowledge All Rights Reserved