Re: [PATCH 01/10] pkt-line: use stack rather than static buffer in packet_write_gently()
- From
Jeff King <peff@peff.net>
- Date
- Jan 13, 2021, 13:29 UTC
- Message-ID
- <X/71qByO5jSceIFn@coredump.intra.peff.net>
- In-Reply-To
- <1155a45cf64afb237204429cd4ff2e74f5f7602a.1610465492.git.gitgitgadget@gmail.com>
On Tue, Jan 12, 2021 at 03:31:23PM +0000, Jeff Hostetler via GitGitGadget wrote:
> Teach packet_write_gently() to use a stack buffer rather than a static > buffer when composing the packet line message. This helps get us ready > for threaded operations.
Sounds like a good goal, but...
Show 5 quoted lines
> static int packet_write_gently(const int fd_out, const char *buf, size_t size)
> {
> - static char packet_write_buffer[LARGE_PACKET_MAX];
> + char packet_write_buffer[LARGE_PACKET_MAX];
> size_t packet_size;64k is awfully big for the stack, especially if you are thinking about having threads. I know we've run into issues around that size before (though I don't offhand recall whether there was any recursion involved).
We might need to use thread-local storage here. Heap would also obviously work, but I don't think we'd want a new allocation per write (or maybe it wouldn't matter; we're making a syscall, so a malloc() may not be that big a deal in terms of performance).
-Peff