From owner-freebsd-fs@FreeBSD.ORG Mon Jan 31 12:00:16 2011 Return-Path: Delivered-To: freebsd-fs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7F54D106566B; Mon, 31 Jan 2011 12:00:16 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail06.syd.optusnet.com.au (mail06.syd.optusnet.com.au [211.29.132.187]) by mx1.freebsd.org (Postfix) with ESMTP id E9FC28FC13; Mon, 31 Jan 2011 12:00:15 +0000 (UTC) Received: from c122-106-165-206.carlnfd1.nsw.optusnet.com.au (c122-106-165-206.carlnfd1.nsw.optusnet.com.au [122.106.165.206]) by mail06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id p0VC06At032305 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 31 Jan 2011 23:00:08 +1100 Date: Mon, 31 Jan 2011 23:00:06 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Artem Belevich In-Reply-To: Message-ID: <20110131224103.M15650@besplex.bde.org> References: <4D443407.7010604@FreeBSD.org> <4D45F359.4040402@FreeBSD.org> <20110131160644.P2539@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-fs , Martin Matuska Subject: Re: ZFS: clock_t overflow in l2arc_feed_thread X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2011 12:00:16 -0000 On Mon, 31 Jan 2011, Artem Belevich wrote: > On Sun, Jan 30, 2011 at 9:25 PM, Bruce Evans wrote: > >> Also, there must be another bug for overflow to occur after only 24 days. >> clock_t is only specified for holding statclock ticks, which have a >> frequency of about 128 Hz, so 32-bit unsigned ints hold 388 days of ticks. > > clock_t is used in solaris code to hold LBOLT (rough equivalent of > *uptime() in FreeBSD). When the code was ported to FreeBSD, LBOLT was > implemented so that it holds uptime in HZ ticks. HZ happens to be > 1000, so clock_t as implemented on FreeBSD will overflow in 24 days. Certainly a bug. More than 1: - clock_t is for stathz ticks, but is abused to count hz ticks. - the type for hz ticks is plain int. This is even smaller than clock_t provided clock_t is correctly unsigned. It should be a larger type if hz is much larger than stathz. It worked better when hz was a little smaller than stathz, as it still needs to be so that it is not too easy to hide from the scheduler using timeouts to schedule yourself. When hz was 100, timeouts worked for 194 days, but now they only work for 24 days. - neither of these types can represent long times, but the time may be a long time and clock_t is abused to represent it. Plain int64_t might work. Many times are still represented as timevals, and the tvtohz() function is used to convert them to a timeout in hz ticks without overflow (long times are clamped to the maximum). Bruce