git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: pack-objects: Fix segfault when object count is less than thread count

From
Sergey Vlasov <vsu@altlinux.ru>
Date
Jan 21, 2008, 17:40 UTC
Message-ID
<20080121174052.GA4627@atlas.home>
In-Reply-To
<alpine.LFD.1.00.0801211103480.20753@xanadu.home>
On Mon, Jan 21, 2008 at 11:07:15AM -0500, Nicolas Pitre wrote:
Show 27 quoted lines
> On Mon, 21 Jan 2008, Sergey Vlasov wrote:
> 
> > When partitioning the work amongst threads, dividing the number of
> > objects by the number of threads may return 0 when there are less
> > objects than threads; this will cause the subsequent code to segfault
> > when accessing list[sub_size-1].  Fix this by ensuring that sub_size
> > is not zero if there is at least one object to process.
> 
> No.  Forcing one object in a thread is counter productive since it won't 
> have anything to delta against.  Instead, the thread should be allowed 
> to have zero objects and let the other threads have more.
> 
> This patch would be a proper fix:
> 
> diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
> index ec10238..d3efeff 100644
> --- a/builtin-pack-objects.c
> +++ b/builtin-pack-objects.c
> @@ -1672,7 +1672,8 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
>  		p[i].data_ready = 0;
>  
>  		/* try to split chunks on "path" boundaries */
> -		while (sub_size < list_size && list[sub_size]->hash &&
> +		while (sub_size && sub_size < list_size &&
> +		       list[sub_size]->hash &&
>  		       list[sub_size]->hash == list[sub_size-1]->hash)
>  			sub_size++;

Actually there will not be any significant differences - with my patch the object distribution between threads will be 1, 1, ..., 0, 0..., and with your patch it would be 0, 0, ..., 1, 1, ... (unless the objects had the same hash, in which case they would be passed to a single thread in both cases).

We could even introduce some limit on the number of objects below which multithreaded packing is not attempted, so that packing a small number of objects would be more efficient.

Previous: Nicolas PitreNext: Nicolas Pitre
Message 5 of 6 in “pack-objects: Fix segfault when object count is less than thread count”
  1. Sergey VlasovJan 21, 2008
  2. Johannes SixtJan 21, 2008
  3. Nicolas PitreJan 21, 2008
  4. Nicolas PitreJan 21, 2008
  5. Sergey VlasovJan 21, 2008
  6. Nicolas PitreJan 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.