Re: [PATCH v2 13/21] packed_ref_cache: keep the `packed-refs` file mmapped if possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 19, 2017 at 08:22:21AM +0200, Michael Haggerty wrote:

> Keep a copy of the `packed-refs` file contents in memory for as long
> as a `packed_ref_cache` object is in use:
> 
> * If the system allows it, keep the `packed-refs` file mmapped.
> 
> * If not (either because the system doesn't support `mmap()` at all,
>   or because a file that is currently mmapped cannot be replaced via
>   `rename()`), then make a copy of the file's contents in
>   heap-allocated space, and keep that around instead.
> 
> We base the choice of behavior on a new build-time switch,
> `MMAP_PREVENTS_DELETE`. By default, this switch is set for Windows
> variants.
> 
> This whole change is still pointless, because we only read the
> `packed-refs` file contents immediately after instantiating the
> `packed_ref_cache`. But that will soon change.

The overall strategy for this compile-time knob makes sense, but one
thing confused me:

> +ifdef MMAP_PREVENTS_DELETE
> +	BASIC_CFLAGS += -DMMAP_PREVENTS_DELETE
> +else
> +	ifdef USE_WIN32_MMAP
> +		BASIC_CFLAGS += -DMMAP_PREVENTS_DELETE
> +	endif
> +endif

So setting the knob does what you'd expect. But if you don't set it,
then we still auto-tweak it based on the USE_WIN32_MMAP knob. Do we need
that? It seems like we set our new knob in config.mak.uname any time
we'd set USE_WIN32_MMAP. So this only has an effect in two cases:

 1. You aren't on Windows, but you set USE_WIN32_MMAP yourself.

 2. You are on Windows, but you manually unset MMAP_PREVENTS_DELETE.

I expect both cases are rare (and would probably involve somebody
actively debugging these knobs). Probably it's a minor convenience in
case 1, but in case 2 it would be actively confusing, I'd think.

> +enum mmap_strategy {
> +	/*
> +	 * Don't use mmap() at all for reading `packed-refs`.
> +	 */
> +	MMAP_NONE,
> +
> +	/*
> +	 * Can use mmap() for reading `packed-refs`, but the file must
> +	 * not remain mmapped. This is the usual option on Windows,
> +	 * where you cannot rename a new version of a file onto a file
> +	 * that is currently mmapped.
> +	 */
> +	MMAP_TEMPORARY,

I suspect you originally distinguished these cases so that NO_MMAP does
not read into a fake-mmap buffer, followed by us copying it into another
buffer. But AFAICT we handle the "NONE" and "TEMPORARY" cases exactly
the same (by just doing a read_in_full() into our own buffer). Do we
actually need separate strategies?

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux