Unbound package : 6core bug/patch



  • Hello,

    we are runnung 2 firewalls on 6cores … seems that still nobody run in this bug so here the problem/fix:

    number_threads and some other values base on number-threads must be something 2^n ... so 1, 2,4 core are good but not 6core...
    Since firewalls run perhaps only on 2-4 core this 6core patch would be enough:

    --- /usr/local/pkg/unbound.inc.orig    2013-02-23 21:54:41.000000000 +0100
    +++ /usr/local/pkg/unbound.inc  2013-02-23 21:56:35.000000000 +0100
    @@ -614,5 +614,7 @@
            // Use 1 (disable threading) if for some reason this sysctl fails.
            $numprocs = intval(trim(/sbin/sysctl kern.smp.cpus | /usr/bin/cut -d" " -f2));
    -      if($numprocs > 0)
    +      if($numprocs > 4)
    +              $optimization['number_threads'] = "num-threads: 4";
    +      elseif($numprocs > 0)
                    $optimization['number_threads'] = "num-threads: {$numprocs}";
            else

    But we can perhaps also modify it to support 8cores ?
    I guess that then it could be (not tested):

    if($numprocs > 0)
                    $optimization['number_threads'] = "num-threads: " . floor(log($numprocs,2));
            else

    Bests

    Reiner



  • nice catch.

    were getting ready to test some 6 and 8 core pfsense boxes in our lab.
    and getting 10GigE working.. that will be a challenge im sure.

    were at 75% utilization on alot of our links the the internet that are Gigabit.



  • Hi,

    thanks to package mantainer to add the fix…

    Problem: latest update 1.4.19_01 wanted to make it a better fix and got a new bug instead :D

    Open Questions:

    1. what happens if numprocs get 0 ?
        0> num-threads is set to 1 (make this else sense?)
        But the 4 values are 0 ... (even... 2^0 is ... not 0 ;))
    --- /usr/local/pkg/unbound.inc.orig	2013-02-19 23:09:11.000000000 +0100
    +++ /usr/local/pkg/unbound.inc	2013-02-26 22:29:33.000000000 +0100
    @@ -617,11 +617,11 @@
     		$optimization['number_threads'] = "num-threads: {$numprocs}";
     	else
     		$optimization['number_threads'] = "num-threads: 1";
    
     	// Slabs to help reduce lock contention.
    -	if ($numprocs > 4) {
    +	if ($numprocs < 4) {
     		$optimization['msg_cache_slabs'] = "msg-cache-slabs: {$numprocs}";
     		$optimization['rrset_cache_slabs'] = "rrset-cache-slabs: {$numprocs}";
     		$optimization['infra_cache_slabs'] = "infra-cache-slabs: {$numprocs}";
     		$optimization['key_cache_slabs'] = "key-cache-slabs: {$numprocs}";
     	} else {
    @@ -960,6 +960,6 @@
     		$aclid++;
    
     	return $aclid;
     }
    

    Better Fix (now also tested, works… sets 4 on my sixcore platform... octacore would be 8 ...;))

    --- /usr/local/pkg/unbound.inc.orig	2013-02-19 23:09:11.000000000 +0100
    +++ /usr/local/pkg/unbound.inc	2013-02-26 22:50:05.000000000 +0100
    @@ -620,15 +620,8 @@
    
     	// Slabs to help reduce lock contention.
    -	if ($numprocs > 4) {
    -		$optimization['msg_cache_slabs'] = "msg-cache-slabs: {$numprocs}";
    -		$optimization['rrset_cache_slabs'] = "rrset-cache-slabs: {$numprocs}";
    -		$optimization['infra_cache_slabs'] = "infra-cache-slabs: {$numprocs}";
    -		$optimization['key_cache_slabs'] = "key-cache-slabs: {$numprocs}";
    -	} else {
    -		$optimization['msg_cache_slabs'] = "msg-cache-slabs: 4";
    -		$optimization['rrset_cache_slabs'] = "rrset-cache-slabs: 4";
    -		$optimization['infra_cache_slabs'] = "infra-cache-slabs: 4";
    -		$optimization['key_cache_slabs'] = "key-cache-slabs: 4";
    -	}
    +	$optimization['msg_cache_slabs'] = "msg-cache-slabs: "     . pow(2,floor(log($numprocs,2)));
    +	$optimization['rrset_cache_slabs'] = "rrset-cache-slabs: " . pow(2,floor(log($numprocs,2)));
    +	$optimization['infra_cache_slabs'] = "infra-cache-slabs: " . pow(2,floor(log($numprocs,2)));
    +	$optimization['key_cache_slabs'] = "key-cache-slabs: "     . pow(2,floor(log($numprocs,2)));
    
     	// Memory usage - default is 4Mb if nothing has been selected
    


  • ping… its boring to take care after each reboot/sometimes unbound hangs/restart in runtime if the patch is still applied...



  • The fastest way to get this code included would be to submit a pull request at GitHub

    https://github.com/pfsense



  • @dhatz:

    The fastest way to get this code included would be to submit a pull request at GitHub

    https://github.com/pfsense

    ok, I find Github a little suspicious with some behavior…

    I guess I must clone the whole repository, check out my clone, add the patch locally,  push the request then to githuib ... and finally I can submit a pull request to pfSense package repo ?
    And for held my own fork "uptodate" for later patches I must add the 2 Githup repos to my local repo ?
    Is there perhaps a nice howto for it ? I didn't seen one from Github directly :(



  • Added in the latest Unbound package - thanks @Reiner030