<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Jan 7, 2016, at 6:46 PM, mmzsmm <<a href="mailto:mmzsmm@163.com" class="">mmzsmm@163.com</a>> wrote:<div><blockquote type="cite" class=""><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class="">[...] according to the code comments, the clean-dirty fragmentation is measured as,<br class=""><br class="">* Order such that chunks with higher fragmentation are "less than"<br class="">* those with lower fragmentation -- purging order is from "least" to<br class="">* "greatest". <br class="">    mean current avail run size                 nruns_avail-nruns_adjac<br class="">--------------------------------------------  =  ----------------------------------<br class="">mean defragmented avail run size                  nruns_avail<br class=""><br class="">So if I have a chunkA with avail_runs = 10, adjac = 1, and another chunkB with avail_runs = 20, adjac = 5.<br class="">Obviously, the fragmentA(0.9) > fragmentB(0.75), so the A will be prior to B in the dirty chunk tree, and <br class="">will be purged first. But the chunkB truely has more adjacs than the A, and the performace gain after purging <br class="">chunkA is also less than the other(0.1 vs 0.25). Why we prefer to purge the chunk with "less adjacs"? <br class="">Shouldn't we purge more adjacs or clean-dirty fragments to acquire more continuous unalloc pages?<br class=""></div></div></div></blockquote><div><br class=""></div><div>We actually do purge B first, but it's hard to see unless you follow the calculations in the code.  Note that a_val=0.45 and b_val=1.5 in this case, which means that the comparison function returns 1, causing A to come after B in the in-order tree traversal.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class="">Another question is, I notice that before the git node e3d13060 there are two avail-trees, one is for dirty, <br class="">and another for clean,<br class="">    arena_avail_tree_t    runs_avail_clean;<br class="">    arena_avail_tree_t    runs_avail_dirty;<br class="">After that, the two became one. So how to ensure the new runs allocaction to prefer to dirty pages? <br class=""></div></div></div></blockquote><div><br class=""></div><div>IIRC, there were versions of jemalloc that did not prefer dirty pages.</div><div><br class=""></div><div>Note that you're looking at jemalloc 3.x code, but 4.x uses substantially different algorithms that obsoleted the code that ordered chunks according to fragmentation.</div><div><br class=""></div><div>Jason</div></div></body></html>