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

Re: [PATCH 2/4] map_loose_object_1: attempt to handle ENOMEM from mmap

From
Jeff King <peff@peff.net>
Date
Jun 30, 2021, 02:41 UTC
Message-ID
<YNvZ3lA6J8DIx2r4@coredump.intra.peff.net>
In-Reply-To
<20210629081108.28657-3-e@80x24.org>
On Tue, Jun 29, 2021 at 08:11:06AM +0000, Eric Wong wrote:
Show 8 quoted lines
> This benefits unprivileged users who lack permissions to raise
> the `sys.vm.max_map_count' sysctl and/or RLIMIT_DATA resource
> limit.
> 
> Multi-threaded callers to map_loose_object_1 (e.g. "git grep")
> appear to guard against thread-safety problems.  Other
> multi-core aware pieces of code (e.g. parallel-checkout) uses
> child processes

This one makes me slightly more nervous than the last, because we don't know if somebody higher up the call stack might be expecting to use that window again.

I _think_ this one is OK, because we would never read a loose object in the process of reading a packed one. I thought we might in some rare cases with corruption (e.g., B is a delta against A; we fail to read A because it's corrupt, so we look elsewhere for a copy). I don't think the current code is quite that clever, though. If B were corrupted, we'd look elsewhere for a duplicate, but that logic doesn't apply in the middle of a delta resolution (even though there are corruption cases it would help recover from).

So I don't think this is introducing any bugs. But it worries me a bit that it creates an opportunity for a subtle and hard-to-trigger situation if we do change seemingly-unrelated code.

But looking more carefully at unuse_one_window(), I think the worst case is a slight performance drop, as we unmap the window and then re-map when somebody higher up the call-stack needs it again. My real worry was that we could trigger a case where somebody was holding onto a pointer to the bytes. But I think use_pack() will mark those bytes via inuse_cnt, and then unuse_one_window() will never drop a window that has a non-zero inuse_count.

So in that sense all of your patches should be correct without thinking too hard no them. Sure, a performance drop from having to re-map the window later isn't great, but if the alternative in each case is calling die(), it's a strict improvement.

-Peff
Previous: Eric WongNext: Ævar Arnfjörð Bjarmason
Message 3 of 15 in “gracefully handling mmap failures”
  1. 0/4 gracefully handling mmap failuresEric Wong, Jun 29, 2021
  2. 2/4 map_loose_object_1: attempt to handle ENOMEM from mmapEric Wong, Jun 29, 2021
  3. Jeff KingJun 30, 2021
  4. Ævar Arnfjörð BjarmasonJun 30, 2021
  5. 1/4 use_pack: attempt to handle ENOMEM from mmapEric Wong, Jun 29, 2021
  6. Jeff KingJun 30, 2021
  7. 3/4 check_packed_git_idx: attempt to handle ENOMEM from mmapEric Wong, Jun 29, 2021
  8. 3/4 check_packed_git_idx: attempt to handle ENOMEM from mmapEric Wong, Jun 29, 2021
  9. Junio C HamanoJun 29, 2021
  10. Eric WongJun 29, 2021
  11. 4/4 xmmap: inform Linux users of tuning knobs on ENOMEMEric Wong, Jun 29, 2021
  12. xmmap: inform Linux users of tuning knobs on ENOMEMEric Wong, Jun 30, 2021
  13. Jeff KingJun 30, 2021
  14. Eric WongJun 30, 2021
  15. Jeff KingJun 30, 2021

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.