amd64/141130: rpc may causes high cpu usage

liujb liujb at
Thu Dec 3 09:20:04 UTC 2009

>Number:         141130
>Category:       amd64
>Synopsis:       rpc may causes high cpu usage
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-amd64
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 03 09:20:04 UTC 2009
>Originator:     liujb
>Release:        FreeBSD7.0
array networks
In svc_getreqset function, high-number fd will not be handled.
Data is still in receiving buffer, so rpc lib will be called 
frequently, which leads high cpu usage.  

It's because fd_mask is unsinged long, which is 64-bits in amd64,
but ffs only handles 32bit int. The high fd will be ingored, 
and jump out of the second for loop.

Please read my comments in the following source code.

        fd_set *readfds;
        int bit, fd;
        fd_mask mask, *maskp;
        int sock;

        assert(readfds != NULL);

        maskp = readfds->fds_bits;
        for (sock = 0; sock < FD_SETSIZE; sock += NFDBITS) {
            for (mask = *maskp++; (bit = ffs(mask)) != 0;    
                                         -->should be ffsl
                mask ^= (1 << (bit - 1))) {                  
                         -->1 should be (long)1
                /* sock has input waiting */
                fd = sock + bit - 1;

Open a rpc connection with a high number file description.
The fix should be take care of the long type of fd_mask in i386 and amd64, 
also should pay attention to other places using ffs.


More information about the freebsd-amd64 mailing list