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

Re: What's cooking in git.git (Aug 2016, #02; Thu, 4)

From
EWEric Wong <e@80x24.org>
Date
Aug 5, 2016, 08:26 UTC
Message-ID
<20160805082630.GA29383@starla>
In-Reply-To
<20160805081103.t5f4bapmia6vircg@sigill.intra.peff.net>
Jeff King <peff@peff.net> wrote:
Show 16 quoted lines
> On Fri, Aug 05, 2016 at 08:02:31AM +0000, Eric Wong wrote:
> 
> > > I just introduced another doubly-linked list in [1]. It adds some MRU
> > > features on top of the list, but it could in theory be built on top of a
> > > generic doubly-linked list.
> > 
> > Yes, and you'd be avoiding the extra mallocs and be able to use
> > list_entry (aka `container_of`) so it could be faster, too.
> 
> I'm not sure which mallocs you mean. I allocate one struct per node,
> which seems like a requirement for a linked list. If you mean holding an
> extra list struct around an existing pointer (rather than shoving the
> prev/next pointers into the pointed-to- item), then yes, we could do
> that. But it feels like a bit dirty, since the point of the list is
> explicitly to provide an alternate ordering over an existing set of
> items.

This pattern to avoid that one malloc-per-node using list_entry (container_of) is actually a common idiom in the Linux kernel and Userspace RCU (URCU). Fwiw, I find it less error-prone and easier-to-follow than the "void *"-first-element thing we do with hashmap.

Show 15 quoted lines
> It also doesn't make a big difference for my use case. All I really care
> about is the speed of delete-from-middle-and-insert-at-front, which is
> trivially O(1) and involves no mallocs.
> 
> > I was thinking packed_git could also be a doubly-linked list
> > anyways since it would allow easier removal of unlinked pack
> > entries.  My use case would be long-running "cat-file --batch"
> > processes being able to detect unlinked packs after someone
> > else runs GC.
> 
> We never remove packed_git structs, but it is not because of the list
> data structure. We may be holding open mmaps to packs that are deleted
> and continue using them. And in some cases other code may even hold
> pointers to our packed_git structs. So you'd have to figure out some
> memory ownership questions first.
Yes, it's easier to replace a running process once in a while :)
Previous: Jeff KingNext: Jeff King
Message 14 of 17 in “What's cooking in git.git (Aug 2016, #02; Thu, 4)”
  1. Junio C HamanoAug 4, 2016
  2. Mike HommeyAug 4, 2016
  3. Junio C HamanoAug 4, 2016
  4. Mike HommeyAug 4, 2016
  5. Torsten BögershausenAug 8, 2016
  6. Mike HommeyAug 8, 2016
  7. Philip OakleyAug 4, 2016
  8. Junio C HamanoAug 4, 2016
  9. Eric WongAug 4, 2016
  10. Junio C HamanoAug 5, 2016
  11. Jeff KingAug 5, 2016
  12. Eric WongAug 5, 2016
  13. Jeff KingAug 5, 2016
  14. Eric WongAug 5, 2016
  15. Jeff KingAug 5, 2016
  16. Eric WongAug 5, 2016
  17. Johannes SchindelinAug 7, 2016

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.