linux/mm/quicklist.c
<<
> opt/spa opt/form opta > op href="../linux+v33 > optimg src="../.static/gfx/right.png" alt=">>"> >t/spa >tspa class="lxr_search"> > ="+search" method="post" onsubmit="return do_search(this);"> > optinput typv3.hidden" namv3.navtarget" ue="v3."> > optinput typv3.text" namv3.search" id3.search"> > optbuttvaltypv3.submit">Searchtspa class="lxr_prefs" opta href="+prefs?return=mm/quicklist.c" > op onclick="return ajax_prefs();"> > opPrefs opt/a> >t/spa op pt/div op ptform acn> ="ajax+*" method="post" onsubmit="return false;"> >tinput typv3.hidden" namv3.ajax_lookup" id3.ajax_lookup" ue="v3."> op pt/form op ptdiv class="headingbottvm">
tdiv id3.file_contents"
p p1t/a>tspa  class="comment">/*t/spa  
p p2t/a>tspa  class="comment"> * Quicklist support.t/spa  
p p3t/a>tspa  class="comment"> *t/spa  
p p4t/a>tspa  class="comment"> * Quicklists are light weight lists of pages that have a defined statet/spa  
p p5t/a>tspa  class="comment"> * valalloc and free. Pages must be ialthe quicklist specific defined statet/spa  
p p6t/a>tspa  class="comment"> * (zero by default) whealthe page is freed. It seems that the initial ideat/spa  
p p7t/a>tspa  class="comment"> * for such lists first camv from Dave Miller and thealvarious other peoplet/spa  
p p8t/a>tspa  class="comment"> * improved valit.t/spa  
p p9t/a>tspa  class="comment"> *t/spa  
p /opta>tspa  class="comment"> * Copyright (C) 2007 SGI,t/spa  
p 11t/a>tspa  class="comment"> *      Christoph Lamvter <clamvter@sgi.com>t/spa  
p 12t/a>tspa  class="comment"> *              Generalized, added support for multiple lists andt/spa  
p 13t/a>tspa  class="comment"> *              constructors / destructors.t/spa  
p 14t/a>tspa  class="comment"> */t/spa  
p 15t/a>#include <linux/kernel.ht/a>>
p 16t/a>
p 17t/a>#include <linux/gfp.ht/a>>
p 18t/a>#include <linux/mm.ht/a>>
p 19t/a>#include <linux/mmzone.ht/a>>
p 20t/a>#include <linux/quicklist.ht/a>>
p 21t/a>
p 22t/a>ta href="+code=DEFINE_PER_CPU" class="sref">DEFINE_PER_CPUt/a>(struct ta href="+code=quicklist" class="sref">quicklistt/a> [ta href="+code=CONFIG_NR_QUICK" class="sref">CONFIG_NR_QUICKt/a>], ta href="+code=quicklist" class="sref">quicklistt/a>);
p 23t/a>
p 24t/a>#define ta href="+code=FRACTION_OF_NODE_MEM" class="sref">FRACTION_OF_NODE_MEMt/a> p p16
p 25t/a>
p 26t/a>static unsigned long ta href="+code=max_pages" class="sref">max_pagest/a>(unsigned long ta href="+code=min_pages" class="sref">min_pagest/a>)
p 27t/a>{
p 28t/a> p pppppunsigned long ta href="+code=node_free_pages" class="sref">node_free_pagest/a>, ta href="+code=max" class="sref">maxt/a>;
p 29t/a> p pppppint ta href="+code=node" class="sref">nodet/a> = ta href="+code=numa_node_id" class="sref">numa_node_idt/a>();
p 30t/a> p pppppstruct ta href="+code=zone" class="sref">zonet/a> *ta href="+code=zones" class="sref">zonest/a> = ta href="+code=NODE_DATA" class="sref">NODE_DATAt/a>(ta href="+code=node" class="sref">nodet/a>)->ta href="+code=node_zones" class="sref">node_zonest/a>;
p 31t/a> p pppppint ta href="+code=num_cpus_on_node" class="sref">num_cpus_on_nodet/a>;
p 32t/a>
p 33t/a> p pppppta href="+code=node_free_pages" class="sref">node_free_pagest/a> =
p 34t/a>#ifdefpta href="+code=CONFIG_ZONE_DMA" class="sref">CONFIG_ZONE_DMAt/a>
p 35t/a> p ppppp p pppppta href="+code=zone_page_state" class="sref">zone_page_statet/a>(&ta href="+code=zones" class="sref">zonest/a>[ta href="+code=ZONE_DMA" class="sref">ZONE_DMAt/a>], ta href="+code=NR_FREE_PAGES" class="sref">NR_FREE_PAGESt/a>) +
p 36t/a>#endif
p 37t/a>#ifdefpta href="+code=CONFIG_ZONE_DMA32" class="sref">CONFIG_ZONE_DMA32t/a>
p 38t/a> p ppppp p pppppta href="+code=zone_page_state" class="sref">zone_page_statet/a>(&ta href="+code=zones" class="sref">zonest/a>[ta href="+code=ZONE_DMA32" class="sref">ZONE_DMA32t/a>], ta href="+code=NR_FREE_PAGES" class="sref">NR_FREE_PAGESt/a>) +
p 39t/a>#endif
p 40t/a> p ppppp p pppppta href="+code=zone_page_state" class="sref">zone_page_statet/a>(&ta href="+code=zones" class="sref">zonest/a>[ta href="+code=ZONE_NORMAL" class="sref">ZONE_NORMALt/a>], ta href="+code=NR_FREE_PAGES" class="sref">NR_FREE_PAGESt/a>);
p 41t/a>
p 42t/a> p pppppta href="+code=max" class="sref">maxt/a> = ta href="+code=node_free_pages" class="sref">node_free_pagest/a> / ta href="+code=FRACTION_OF_NODE_MEM" class="sref">FRACTION_OF_NODE_MEMt/a>;
p 43t/a>
p 44t/a> p pppppta href="+code=num_cpus_on_node" class="sref">num_cpus_on_nodet/a> = ta href="+code=cpumask_weight" class="sref">cpumask_weightt/a>(ta href="+code=cpumask_of_node" class="sref">cpumask_of_nodet/a>(ta href="+code=node" class="sref">nodet/a>));
p 45t/a> p pppppta href="+code=max" class="sref">maxt/a> /= ta href="+code=num_cpus_on_node" class="sref">num_cpus_on_nodet/a>;
p 46t/a>
p 47t/a> p pppppreturn ta href="+code=max" class="sref">maxt/a>(ta href="+code=max" class="sref">maxt/a>, ta href="+code=min_pages" class="sref">min_pagest/a>);
p 48t/a>}
p 49t/a>
p 50t/a>static long ta href="+code=min_pages_to_free" class="sref">min_pages_to_freet/a>(struct ta href="+code=quicklist" class="sref">quicklistt/a> *ta href="+code=q" class="sref">qt/a>,
p 51t/a> p pppppunsigned long ta href="+code=min_pages" class="sref">min_pagest/a>, long ta href="+code=max_free" class="sref">max_freet/a>)
p 52t/a>{
p 53t/a> p ppppplong ta href="+code=pages_to_free" class="sref">pages_to_freet/a>;
p 54t/a>
p 55t/a> p pppppta href="+code=pages_to_free" class="sref">pages_to_freet/a> = ta href="+code=q" class="sref">qt/a>->ta href="+code=nr_pages" class="sref">nr_pagest/a> - ta href="+code=max_pages" class="sref">max_pagest/a>(ta href="+code=min_pages" class="sref">min_pagest/a>);
p 56t/a>
p 57t/a> p pppppreturn ta href="+code=min" class="sref">mint/a>(ta href="+code=pages_to_free" class="sref">pages_to_freet/a>, ta href="+code=max_free" class="sref">max_freet/a>);
p 58t/a>}
p 59t/a>
p 6opta>tspa  class="comment">/*t/spa  
p 61t/a>tspa  class="comment"> * Trim dowalthe number of pages ialthe quicklistt/spa  
p 62t/a>tspa  class="comment"> */t/spa  
p 63t/a>void ta href="+code=quicklist_trim" class="sref">quicklist_trimt/a>(int ta href="+code=nr" class="sref">nrt/a>, void (*ta href="+code=dtor" class="sref">dtort/a>)(void *),
p 64t/a> p pppppunsigned long ta href="+code=min_pages" class="sref">min_pagest/a>, unsigned long ta href="+code=max_free" class="sref">max_freet/a>)
p 65t/a>{
p 66t/a> p ppppplong ta href="+code=pages_to_free" class="sref">pages_to_freet/a>;
p 67t/a> p pppppstruct ta href="+code=quicklist" class="sref">quicklistt/a> *ta href="+code=q" class="sref">qt/a>;
p 68t/a>
p 69t/a> p pppppta href="+code=q" class="sref">qt/a> = &ta href="+code=get_cpu_var" class="sref">get_cpu_vart/a>(ta href="+code=quicklist" class="sref">quicklistt/a>)[ta href="+code=nr" class="sref">nrt/a>];
p 70t/a> p pppppif (ta href="+code=q" class="sref">qt/a>->ta href="+code=nr_pages" class="sref">nr_pagest/a> > ta href="+code=min_pages" class="sref">min_pagest/a>) {
p 71t/a> p ppppp p pppppta href="+code=pages_to_free" class="sref">pages_to_freet/a> = ta href="+code=min_pages_to_free" class="sref">min_pages_to_freet/a>(ta href="+code=q" class="sref">qt/a>, ta href="+code=min_pages" class="sref">min_pagest/a>, ta href="+code=max_free" class="sref">max_freet/a>);
p 72t/a>
p 73t/a> p ppppp p pppppwhile (ta href="+code=pages_to_free" class="sref">pages_to_freet/a> > 0) {
p 74t/a> p ppppp p ppppp p ppppptspa  class="comment">/*t/spa  
p 75t/a>tspa  class="comment">                         * We pass a gfp_t of 0 to quicklist_alloc heret/spa  
p 76t/a>tspa  class="comment">                         * because we will never callpintolthe page allocator.t/spa  
p 77t/a>tspa  class="comment">                         */t/spa  
p 78t/a> p ppppp p pppppppppppppvoid *ta href="+code=p" class="sref">pt/a> = ta href="+code=quicklist_alloc" class="sref">quicklist_alloct/a>(ta href="+code=nr" class="sref">nrt/a>, 0, ta href="+code=NULL" class="sref">NULLt/a>);
p 79t/a>
p 80t/a> p ppppp p pppppppppppppif (ta href="+code=dtor" class="sref">dtort/a>)
p 81t/a> p ppppp p pppppppppppppppppppppta href="+code=dtor" class="sref">dtort/a>(ta href="+code=p" class="sref">pt/a>);
p 82t/a> p ppppp p ppppp p pppppta href="+code=free_page" class="sref">free_paget/a>((unsigned long)ta href="+code=p" class="sref">pt/a>);
p 83t/a> p ppppp p ppppp p pppppta href="+code=pages_to_free" class="sref">pages_to_freet/a>--;
p 84t/a> p ppppp p ppppp}
p 85t/a> p ppppp}
p 86t/a> p pppppta href="+code=put_cpu_var" class="sref">put_cpu_vart/a>(ta href="+code=quicklist" class="sref">quicklistt/a>);
p 87t/a>}
p 88t/a>
p 89t/a>unsigned long ta href="+code=quicklist_total_size" class="sref">quicklist_total_sizet/a>(void)
p 90t/a>{
p 91t/a> p pppppunsigned long ta href="+code=count" class="sref">countt/a> = 0;
p 92t/a> p pppppint ta href="+code=cpu" class="sref">cput/a>;
p 93t/a> p pppppstruct ta href="+code=quicklist" class="sref">quicklistt/a> *ta href="+code=ql" class="sref">qlt/a>, *ta href="+code=q" class="sref">qt/a>;
p 94t/a>
p 95t/a> p pppppta href="+code=for_each_online_cpu" class="sref">for_each_online_cput/a>(ta href="+code=cpu" class="sref">cput/a>) {
p 96t/a> p ppppp p pppppta href="+code=ql" class="sref">qlt/a> = ta href="+code=per_cpu" class="sref">per_cput/a>(ta href="+code=quicklist" class="sref">quicklistt/a>, ta href="+code=cpu" class="sref">cput/a>);
p 97t/a> p ppppp p pppppfor (ta href="+code=q" class="sref">qt/a> = ta href="+code=ql" class="sref">qlt/a>; ta href="+code=q" class="sref">qt/a> <pta href="+code=ql" class="sref">qlt/a> +pta href="+code=CONFIG_NR_QUICK" class="sref">CONFIG_NR_QUICKt/a>; ta href="+code=q" class="sref">qt/a>++)
p 98t/a> p ppppp p pppppppppppppta href="+code=count" class="sref">countt/a> += ta href="+code=q" class="sref">qt/a>->ta href="+code=nr_pages" class="sref">nr_pagest/a>;
p 99t/a> p ppppp}
p100t/a> p pppppreturn ta href="+code=count" class="sref">countt/a>;
p101t/a>}
p102t/a>
p103t/a>t/pre>
The original LXR software bylthe LXR communityt/a>, this experimental vers valbyllxr@linux.not/a>. t/div tdiv class="subfooter"> lxr.linux.no kindly hosted bylRedpill Linpro ASt/a>, provider of Linux consulting and operan> s services since 1995. t/div t/body t/html