<div dir="rtl"><div dir="auto"><div><p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:"Times New Roman",serif">Thanks Tony for the detailed
answer! I just found the parts of the code you mentioned that related to the
policy eviction.</span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:"Times New Roman",serif">There is something I can't
figure out, What the Red Black Tree DB is used for and what the ADB  is used for? Is there a relationship between the
two? </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:"Times New Roman",serif">Sorry if the answers are pretty
clear, I’m new to BIND.</span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:"Times New Roman",serif"><br></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;line-height:normal;font-size:11pt;font-family:Calibri,sans-serif"><span style="font-size:12pt;font-family:"Times New Roman",serif">Itay</span></p></div><div></div><div><span style="color:rgb(51,51,51);font-family:Assistant;font-size:14px"><br></span></div><div><br><div dir="auto"><br></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 30, 2019, 22:07 Tony Finch <<a href="mailto:dot@dotat.at" target="_blank">dot@dotat.at</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Itay Alayoff <<a href="mailto:itayala@post.bgu.ac.il" rel="noreferrer" target="_blank">itayala@post.bgu.ac.il</a>> wrote:<br>
<br>
> I'd like to know where is the policy eviction currently implemented?<br>
<br>
The way I answer questions like this is to start from the configuration<br>
options, and working my way from bin/named/server.c (where the parsed<br>
config file is processed) I trace through to find the code that uses the<br>
options of interest. Often with an option like `some-thing` I can find<br>
most of the code by grepping for `some.?thing` but the spelling is not<br>
always that consistent.<br>
<br>
In this case, grepping for `cache.?size` I can see a line:<br>
<br>
        dns_cache_setcachesize(cache, max_cache_size);<br>
<br>
So (unsurprisingly!) the next place to look is in lib/dns/cache.c<br>
where I find dns_cache_setcachesize() which sets up a callback function<br>
called water() to implement the limits. In turn water() invokes<br>
dns_db_overmem().<br>
<br>
<a href="https://gitlab.isc.org/isc-projects/bind9/blob/master/lib/dns/cache.c#L880" rel="noreferrer noreferrer" target="_blank">https://gitlab.isc.org/isc-projects/bind9/blob/master/lib/dns/cache.c#L880</a><br>
<br>
There's an abstraction layer around BIND's in-memory database to support<br>
alternative back ends (look around for dyndb and sdb to follow this<br>
side-track) with a C OO interface that will feel familiar to kernel<br>
hackers. But we want to skip to the relevant point which for db matters is<br>
usually lib/dns/rbtdb.c, the red-black tree database. There are a bunch of<br>
method vtbl definitions in this file; we're looking for the `overmem`<br>
method. In fact, looking for `overmem` everywhere in the file should get<br>
you a bit closer to enlightenment.<br>
<br>
<a href="https://gitlab.isc.org/isc-projects/bind9/blob/master/lib/dns/rbtdb.c" rel="noreferrer noreferrer" target="_blank">https://gitlab.isc.org/isc-projects/bind9/blob/master/lib/dns/rbtdb.c</a><br>
<br>
The rbtdb.c overmem() method actually says,<br>
<br>
        /* This is an empty callback.  See adb.c:water() */<br>
<br>
The adb (address database) handles stuff like SRTT calculations and<br>
lameness flags etc. Reading around mentions of `overmem` and `water`<br>
in adb.c is again informative.<br>
<br>
<a href="https://gitlab.isc.org/isc-projects/bind9/blob/master/lib/dns/adb.c#L2305" rel="noreferrer noreferrer" target="_blank">https://gitlab.isc.org/isc-projects/bind9/blob/master/lib/dns/adb.c#L2305</a><br>
<br>
This comment appears to be the crux:<br>
<br>
/*%<br>
 * Examine the tail entry of the LRU list to see if it expires or is stale<br>
 * (unused for some period); if so, the name entry will be freed.  If the ADB<br>
 * is in the overmem condition, the tail and the next to tail entries<br>
 * will be unconditionally removed (unless they have an outstanding fetch).<br>
 * We don't care about a race on 'overmem' at the risk of causing some<br>
 * collateral damage or a small delay in starting cleanup, so we don't bother<br>
 * to lock ADB (if it's not locked).<br>
 *<br>
 * Name bucket must be locked; adb may be locked; no other locks held.<br>
 */<br>
static void<br>
check_stale_name(dns_adb_t *adb, int bucket, isc_stdtime_t now) {<br>
<br>
<br>
Now you know everything I know about BIND's cache eviction policy :-)<br>
<br>
Tony.<br>
-- <br>
f.anthony.n.finch  <<a href="mailto:dot@dotat.at" rel="noreferrer" target="_blank">dot@dotat.at</a>>  <a href="http://dotat.at/" rel="noreferrer noreferrer" target="_blank">http://dotat.at/</a><br>
North Rockall, Malin: Northwesterly 4 or 5, backing southerly 5 to 7 later.<br>
Rough. Fair. Good.<br>
<br>
</blockquote></div></div></div>
</div>