From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 1AC701F66E for ; Thu, 13 Aug 2020 09:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726419AbgHMJGg (ORCPT ); Thu, 13 Aug 2020 05:06:36 -0400 Received: from cloud.peff.net ([104.130.231.41]:57446 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726048AbgHMJGg (ORCPT ); Thu, 13 Aug 2020 05:06:36 -0400 Received: (qmail 17209 invoked by uid 109); 13 Aug 2020 09:06:36 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 13 Aug 2020 09:06:36 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 11538 invoked by uid 111); 13 Aug 2020 09:06:35 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 13 Aug 2020 05:06:35 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 13 Aug 2020 05:06:35 -0400 From: Jeff King To: Junio C Hamano Cc: =?utf-8?B?UmVuw6k=?= Scharfe , Git Mailing List , Chris Torek , Johannes Sixt , Derrick Stolee Subject: Re: [PATCH v2] midx: use buffered I/O to talk to pack-objects Message-ID: <20200813090635.GC3092220@coredump.intra.peff.net> References: <9162c1cb-36fd-3203-ec58-4bd1501938d0@web.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Wed, Aug 12, 2020 at 01:28:22PM -0700, Junio C Hamano wrote: > René Scharfe writes: > > > nth_midxed_object_oid(&oid, m, i); > > - xwrite(cmd.in, oid_to_hex(&oid), the_hash_algo->hexsz); > > - xwrite(cmd.in, "\n", 1); > > + fprintf(cmd_in, "%s\n", oid_to_hex(&oid)); > > I do think it is silly to send an object name and terminating LF in > two different system calls per object. > > The original uses xwrite() so that it does not have to worry about > having to restart interrupted system calls and such. Do we need to > do that ourselves now or does the stdio layer take care of it for > us? I think we're OK in this instance because we are not expecting writes to happen at any given moment. We might do a partial write() for any given fprintf(), but we're OK as long as by the fflush() at the end everything is written. For more general cases where we do care about ordering (e.g., if we were interleaving writes and reads with something like cat-file), we'd need to fflush() after each write. And I'd expect fflush() to retry across partial write() or EINTR anyway as a quality-of-implementation thing. Which doesn't make it true, but glibc empirically seems to behave that way, and I think we'd be better off adding a transparent wrapper to fflush() on any system that doesn't. -Peff