From owner-freebsd-arch@freebsd.org Wed Oct 7 21:02:41 2015 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DED799D14F7 for ; Wed, 7 Oct 2015 21:02:41 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [IPv6:2607:fc50:1000:7400:216:3eff:fe72:314f]) by mx1.freebsd.org (Postfix) with ESMTP id C8651F32 for ; Wed, 7 Oct 2015 21:02:41 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from marvin.beer.town (unknown [76.164.8.130]) by smtp.vangyzen.net (Postfix) with ESMTPSA id C62B456483 for ; Wed, 7 Oct 2015 16:02:40 -0500 (CDT) From: Eric van Gyzen Subject: RFC: Automatically Reloading /etc/resolv.conf X-Enigmail-Draft-Status: N1110 To: freebsd-arch@freebsd.org Message-ID: <5615886F.3060601@FreeBSD.org> Date: Wed, 7 Oct 2015 16:02:39 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Oct 2015 21:02:42 -0000 I would like to change the libc resolver to automatically reload /etc/resolv.conf when the latter changes. I would like to hear opinions about the implementation. Broadly, I see two approaches. == "stat" == When loading the file, record the mod time. Before each query, stat() the file to see if it has changed. Advantage: It uses no extra persistently allocated objects. Disadvantage: It incurs a stat() on every query. I don't see this as a major disadvantage, since the resolver already does a lot of work on every query. (For example, it creates and destroys a kqueue and a socket.) OpenBSD uses this approach. It also uses clock_gettime(CLOCK_MONOTONIC) to rate-limit the stat() calls to one per several seconds. == "kqueue" == When loading the file, open a kqueue and register for the appropriate events. Before each query, check for kevents. Advantage: The per-query overhead is fairly small. Disadvantage: This would persistently allocate an open file and a kqueue for every thread that ever uses the resolver, for the life of the thread. This seems fairly expensive. NetBSD uses this approach. It mitigates most of the space-cost by using a shared pool of res_state objects, instead of one per thread [that uses the resolver]. On each query, a thread allocates/borrows a res_state from the pool, uses it, and returns it. So, the number of objects is only the high water mark of the number of threads _concurrently_ issuing resolver queries. There are probably several variations on each theme, of course. I would appreciate your thoughts on these approaches and others I missed, as well as variations and details. FYI, I'm leaning toward the "stat" approach. Cheers, Eric