Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp522207rdh; Sat, 23 Sep 2023 23:45:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQvjx3hhiDZ1+dicNiKAaPmyFp2ryWQPxJpWXAY0bESDCWPVFXYy8bVU6bdN2I8TGPBlsy X-Received: by 2002:a17:902:ec82:b0:1bb:c06e:647a with SMTP id x2-20020a170902ec8200b001bbc06e647amr4628078plg.53.1695537952507; Sat, 23 Sep 2023 23:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695537952; cv=none; d=google.com; s=arc-20160816; b=eE7MKdCc/8+8Pcv87ldckINeiaJYpLOnt9Pv4lacZN/1LpGeN3RnYG9Kx9eigGeZ6R 4118IYM5QcgOQeZK7DZ1xh+z3KiklY+129moQpNv7HKgDMlwbtnoEC6JlxIascJrWSD6 2daLqn73Mq/z3PhMssM5O7wWKbJwzognKk6nu5MaSPJqoS1me06L69VKfc0OLea9fUzg e2Qgz62HEssIoynkXp2OgroVvyzsxhLwoa6odMgepKiYCbiYyrDkGXrp+/FfIYpz/3/d 86+IioYy+ymITHeuR+dgNBbFtdV+QmIGvF8bEEWoGQ2HKWLJSkZbbGZUaIR54+GaIcTj 4c8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KDFc9Ol/EE4RqD0zI5Zpzlegr8hS7WyFmPJjMKXneoc=; fh=afYMwUwQgWuCClk7vY78oZAASp3ePtW+3UFV/ny9sjM=; b=edWHeAUAk2/qWq2G/PPAMFrDGhq73dgoLkXg1nQkZuMFXnCxiTFz2y9ThhuLFzptUq I1NjETQUwCsqaKGHeE/PaqZbzEUNo3I9D8dLKXZp2KrPm3pDm9iDvJbXxAllpZCtHqp2 zNdplosKBfVcg9+NWDBN2234X4RWEGlz6fCs3RqriQp7S2QDG7bzPU6MH92rZaDYMu3M dKzJ0Yky0gU5z3b2oY9ctChB8EEnkxMDFUmaJxuDqS7CZ58KBiuSDW706xqH81QpMme1 Yc0LyUo/OL4nclRp+wZXLu5gZEGFUVUgs2pNJ6r25CXAZIrZM5/yscV7RQdKZz3UxpnS L5zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mit.edu header.s=outgoing header.b=AX+5gB1K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h14-20020a170902f7ce00b001bbc80a2a3asi6890381plw.299.2023.09.23.23.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 23:45:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@mit.edu header.s=outgoing header.b=AX+5gB1K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 57C4081D68F3; Sat, 23 Sep 2023 12:31:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbjIWTbK (ORCPT + 99 others); Sat, 23 Sep 2023 15:31:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbjIWTbJ (ORCPT ); Sat, 23 Sep 2023 15:31:09 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5FCB83 for ; Sat, 23 Sep 2023 12:31:02 -0700 (PDT) Received: from letrec.thunk.org (c-73-8-226-230.hsd1.il.comcast.net [73.8.226.230]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 38NJUgVM032361 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 23 Sep 2023 15:30:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1695497445; bh=KDFc9Ol/EE4RqD0zI5Zpzlegr8hS7WyFmPJjMKXneoc=; h=Date:From:Subject:Message-ID:MIME-Version:Content-Type; b=AX+5gB1KNdF6ofn0VcwbFPgwhMQ4RCjr/KzTwhuKLSy8sCDHKxVLa+3UnZ5Kz37+k NnE4UYGFuE/l+yuJ5JT1/9Bz11ogR51H+20nq1CUn7liPK1qOwFDfgzaDV4UXNCKsK NDq9U3kD3BzssvQPk5QRyp5w+gQfH+YGML2M8jT5qTNc4vRq5ZNbAiIzceV2v2gmzE ZkoLWA2cAhgE3kmcHSbv0gW61r8XOGsVWIRHged9k+qIRm0M5ZfAU9+NNPnspi3V5J GQ5ucDzKY8cYLG1aOLqPvUpXQmL5CSCBzw6JFR6fG/lwyZV02rP7w9SnsU2Eo744GR lEC3ogs/nYBgw== Received: by letrec.thunk.org (Postfix, from userid 15806) id 1BC5E8C036B; Sat, 23 Sep 2023 15:30:42 -0400 (EDT) Date: Sat, 23 Sep 2023 15:30:42 -0400 From: "Theodore Ts'o" To: Linus Torvalds Cc: Amir Goldstein , Jeff Layton , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , "Darrick J. Wong" Subject: Re: [GIT PULL v2] timestamp fixes Message-ID: References: <20230921-umgekehrt-buden-a8718451ef7c@brauner> <0d006954b698cb1cea3a93c1662b5913a0ded3b1.camel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sat, 23 Sep 2023 12:31:18 -0700 (PDT) On Sat, Sep 23, 2023 at 10:48:51AM -0700, Linus Torvalds wrote: > > I feel like 100ns is a much more reasonable resolution, and is quite > close to a single system call (think "one thousand cycles at 10GHz"). FWIW, UUID's (which originally came from Apollo Domain/OS in the 1980's, before getting adopted by OSF/DCE, and then by Linux and Microsoft) use a 100ns granularity. And the smart folks at Apollo figured this out some 4 decades ago, and *no* they didn't use units of a single nanosecond. :-) 100ns granularity is also what what ext4 uses for our on-disk format --- 2**30 just enough to cover 100ns granularity (with only 7% of wasted number space), and those two bits are enough for us to encode timestamps into 2446 using a 64-bit timestamp (and what we do past 2446 is pretty much something I'm happy to let someone else deal with, as I expect I'll be long dead by then.) (And if someone does happen to event some kind of life-extension technology, I'm happy to fix it up... later. :-) > That said, we don't have to do powers-of-ten. In fact, in many ways, > it would probably be a good idea to think of the fractional seconds in > powers of two. That tends to make it cheaper to do conversions, > without having to do a full 64-bit divide (a constant divide turns > into a fancy multiply, but it's still painful on 32-bit > architectures). It depends on what conversion we need to do. If we're converting to userspace's timespec64 data structure, which is denominated in nanosecods, it's actually much easier to use decimal 100ns units: #define EXT4_EPOCH_BITS 2 #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1) #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS) static inline __le32 ext4_encode_extra_time(struct timespec64 *time) { u32 extra =((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK; return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS)); } static inline void ext4_decode_extra_time(struct timespec64 *time, __le32 extra) { if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32; time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS; } > Of course, I might have screwed up the above conversion functions, > they are untested garbage, but they look close enough to being in the > right ballpark. We actually have kunit tests for ext4_encode_extra_time() and ext4_decode_extra_time(), mainly because people *have* screwed it up when making architecture-specific optimizations or when making global sweeps of VFS code. :-) - Ted