From patchwork Fri Sep 25 12:33:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11799673 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C45C6CB for ; Fri, 25 Sep 2020 12:33:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78DEA221EC for ; Fri, 25 Sep 2020 12:33:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="grby7MkV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728339AbgIYMdp (ORCPT ); Fri, 25 Sep 2020 08:33:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbgIYMdn (ORCPT ); Fri, 25 Sep 2020 08:33:43 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B4B6C0613CE for ; Fri, 25 Sep 2020 05:33:43 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id g4so3424158wrs.5 for ; Fri, 25 Sep 2020 05:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=4M7aBuZa+23SPS0EXGE8b/xKhtx/rwIrAZGhG9usDN8=; b=grby7MkVvdZvFVGH39zuPUSrH0k43lxKMGPv25fwWh1pdVnh3agr/TKB6mczX4MU7L huqWx6ZSU9VBR71qE5PkVbIUGS+o8qAiizKkTAi+bj0oIHr7Hn+lmTt1irIbVpozQQ0A 8Yq1g+mLZuxXZiUiqaOZL958yCf8H0ekapDrKNUt91SXGhqQduvXSGXdOekdVh9Hm194 XgLFJruj4sj7yKurd4UXI/IAWhJn/93XwGLnRn3jzZxnL5LqLVzRp2MBcqs54w37jDD5 XR+szB4GlT3mXe17DFvBCcTQOF0s+fnE1K4T7inGzwe+d2/spMf0KT/uwgCUBMUf00pM JNSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=4M7aBuZa+23SPS0EXGE8b/xKhtx/rwIrAZGhG9usDN8=; b=Og0JDDs1z78OXl5+rnSUAByrXhU74VaIkU8HDy7yWkxx50rY/CYP4GZDX6WCpODGNx T0TUvg7LpvGwiax2aVRWTwar/9+2hqdve+341NaE8Nf6EZgDUmRROHEnlFti0IRxB7CS vSuewAkpTSjqGQtqx5DjZVkuWntC5VC/aGlbKtVc87HvFWNthmZtfja9+pVgwo4tMgt1 AVPVjlKguro89ETzK8VXGJhSAE75sQKPXonk4U3D4DRB/mHuQCAlAIIGwgloSzq0GIx8 c9EZO1x9d38sIwHD+PGOdN/baZ2f6Vo2dF4onUJunfdig7MTV3IxvXffs+NdjyGsUgVx cPeA== X-Gm-Message-State: AOAM533PkVSDQb/+e3yjumEeb3wn6b6QZalL5PX4TRe8mDv2WmouLzac q7uDAXlHXi1Sqx/C2LJsL0lemFn4lA0= X-Google-Smtp-Source: ABdhPJzBknkPK+UGUXh+BrOXQeufBpDeu9llDhinnrECLK9D1JuKWi1qBVfv7t2vqrn23JnlZlDExw== X-Received: by 2002:adf:ef48:: with SMTP id c8mr4360990wrp.370.1601037221155; Fri, 25 Sep 2020 05:33:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q20sm2731519wmj.5.2020.09.25.05.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:40 -0700 (PDT) Message-Id: <7a62e224cfa4e353572d90ad2bdef0b9e348def4.1601037218.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:31 +0000 Subject: [PATCH v4 1/8] maintenance: add prefetch task Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When working with very large repositories, an incremental 'git fetch' command can download a large amount of data. If there are many other users pushing to a common repo, then this data can rival the initial pack-file size of a 'git clone' of a medium-size repo. Users may want to keep the data on their local repos as close as possible to the data on the remote repos by fetching periodically in the background. This can break up a large daily fetch into several smaller hourly fetches. The task is called "prefetch" because it is work done in advance of a foreground fetch to make that 'git fetch' command much faster. However, if we simply ran 'git fetch ' in the background, then the user running a foreground 'git fetch ' would lose some important feedback when a new branch appears or an existing branch updates. This is especially true if a remote branch is force-updated and this isn't noticed by the user because it occurred in the background. Further, the functionality of 'git push --force-with-lease' becomes suspect. When running 'git fetch ' in the background, use the following options for careful updating: 1. --no-tags prevents getting a new tag when a user wants to see the new tags appear in their foreground fetches. 2. --refmap= removes the configured refspec which usually updates refs/remotes//* with the refs advertised by the remote. While this looks confusing, this was documented and tested by b40a50264ac (fetch: document and test --refmap="", 2020-01-21), including this sentence in the documentation: Providing an empty `` to the `--refmap` option causes Git to ignore the configured refspecs and rely entirely on the refspecs supplied as command-line arguments. 3. By adding a new refspec "+refs/heads/*:refs/prefetch//*" we can ensure that we actually load the new values somewhere in our refspace while not updating refs/heads or refs/remotes. By storing these refs here, the commit-graph job will update the commit-graph with the commits from these hidden refs. 4. --prune will delete the refs/prefetch/ refs that no longer appear on the remote. 5. --no-write-fetch-head prevents updating FETCH_HEAD. We've been using this step as a critical background job in Scalar [1] (and VFS for Git). This solved a pain point that was showing up in user reports: fetching was a pain! Users do not like waiting to download the data that was created while they were away from their machines. After implementing background fetch, the foreground fetch commands sped up significantly because they mostly just update refs and download a small amount of new data. The effect is especially dramatic when paried with --no-show-forced-udpates (through fetch.showForcedUpdates=false). [1] https://github.com/microsoft/scalar/blob/master/Scalar.Common/Maintenance/FetchStep.cs Signed-off-by: Derrick Stolee --- Documentation/git-maintenance.txt | 15 +++++++++ builtin/gc.c | 51 +++++++++++++++++++++++++++++++ t/t7900-maintenance.sh | 26 ++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index 6abcb8255a..12668fccf7 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -47,6 +47,21 @@ commit-graph:: `commit-graph-chain` file. They will be deleted by a later run based on the expiration delay. +prefetch:: + The `prefetch` task updates the object directory with the latest + objects from all registered remotes. For each remote, a `git fetch` + command is run. The refmap is custom to avoid updating local or remote + branches (those in `refs/heads` or `refs/remotes`). Instead, the + remote refs are stored in `refs/prefetch//`. Also, tags are + not updated. ++ +This is done to avoid disrupting the remote-tracking branches. The end users +expect these refs to stay unmoved unless they initiate a fetch. With prefetch +task, however, the objects necessary to complete a later real fetch would +already be obtained, so the real fetch would go faster. In the ideal case, +it will just become an update to bunch of remote-tracking branches without +any object transfer. + gc:: Clean up unnecessary files and optimize the local repository. "GC" stands for "garbage collection," but this task performs many diff --git a/builtin/gc.c b/builtin/gc.c index 090959350e..5e469488f4 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -29,6 +29,7 @@ #include "tree.h" #include "promisor-remote.h" #include "refs.h" +#include "remote.h" #define FAILED_RUN "failed to run %s" @@ -816,6 +817,51 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts) return 0; } +static int fetch_remote(const char *remote, struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "fetch", remote, "--prune", "--no-tags", + "--no-write-fetch-head", "--recurse-submodules=no", + "--refmap=", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--quiet"); + + strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote); + + return !!run_command(&child); +} + +static int append_remote(struct remote *remote, void *cbdata) +{ + struct string_list *remotes = (struct string_list *)cbdata; + + string_list_append(remotes, remote->name); + return 0; +} + +static int maintenance_task_prefetch(struct maintenance_run_opts *opts) +{ + int result = 0; + struct string_list_item *item; + struct string_list remotes = STRING_LIST_INIT_DUP; + + if (for_each_remote(append_remote, &remotes)) { + error(_("failed to fill remotes")); + result = 1; + goto cleanup; + } + + for_each_string_list_item(item, &remotes) + result |= fetch_remote(item->string, opts); + +cleanup: + string_list_clear(&remotes, 0); + return result; +} + static int maintenance_task_gc(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; @@ -854,6 +900,7 @@ struct maintenance_task { }; enum maintenance_task_label { + TASK_PREFETCH, TASK_GC, TASK_COMMIT_GRAPH, @@ -862,6 +909,10 @@ enum maintenance_task_label { }; static struct maintenance_task tasks[] = { + [TASK_PREFETCH] = { + "prefetch", + maintenance_task_prefetch, + }, [TASK_GC] = { "gc", maintenance_task_gc, diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 53c883531e..045524e6ad 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -62,4 +62,30 @@ test_expect_success 'run --task duplicate' ' test_i18ngrep "cannot be selected multiple times" err ' +test_expect_success 'run --task=prefetch with no remotes' ' + git maintenance run --task=prefetch 2>err && + test_must_be_empty err +' + +test_expect_success 'prefetch multiple remotes' ' + git clone . clone1 && + git clone . clone2 && + git remote add remote1 "file://$(pwd)/clone1" && + git remote add remote2 "file://$(pwd)/clone2" && + git -C clone1 switch -c one && + git -C clone2 switch -c two && + test_commit -C clone1 one && + test_commit -C clone2 two && + GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null && + fetchargs="--prune --no-tags --no-write-fetch-head --recurse-submodules=no --refmap= --quiet" && + test_subcommand git fetch remote1 $fetchargs +refs/heads/\\*:refs/prefetch/remote1/\\* X-Patchwork-Id: 11799679 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CFFE6CB for ; Fri, 25 Sep 2020 12:33:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D9ED221EC for ; Fri, 25 Sep 2020 12:33:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M5YrNA5u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728369AbgIYMdq (ORCPT ); Fri, 25 Sep 2020 08:33:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbgIYMdo (ORCPT ); Fri, 25 Sep 2020 08:33:44 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC27EC0613D3 for ; Fri, 25 Sep 2020 05:33:43 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id a9so3125422wmm.2 for ; Fri, 25 Sep 2020 05:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=6Ngjsw8lFpJbAWCMKSZMZvZholuwlHMRCUkZ+A+ieRo=; b=M5YrNA5uTIJt8yEHtjBHAOVsFmotoVz/vdysQ9uGh7G2ha9Wv2+dmMF0HlDk7RZ9ar bS02wfBmO7leB9TvxvZ2tSoht2mT/HsA0XcqT8XvgSydRYZy705f4OZsINhkrZBuiI4K a10a3cU19micOLtfw6h6EtHN4A7nRr9jaOQoKSMBsSnEaiYolUUBlu5MnUSuAEHNSo/O m8ZVBYL5fb4G6XygiCojD5AAhQoxqViCZqBdwSW9JAP7Li7eEIwNuypUOfRvEDh8I0vD 63Ae2vtjrFXELCFI9y9nhtAts3muWVaLzndg/Rwepio1eTN+rd5NfXC3aTj52y8VX2LF UKAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=6Ngjsw8lFpJbAWCMKSZMZvZholuwlHMRCUkZ+A+ieRo=; b=sanG8G9JSHikaS/w4BKVOLlsQVkkQ9ucMdaGiTZgKC10x0CdLFMAT11WnX+IBbZmx4 L+oKyeRnUqBHDb7K0qPT8uTro7ituLz7MhPe/j8sujuOg7EmRLIFvyHM8Ucw6pMRInr/ BK84iQNPfwHnwE/8XSrvIK4frx43MVk7GGwm6EotBaemnx0Uwfr8hnIIIJs6eGRBTSjL Faa5AComfRWBCdlrywuJBiZKLszm59qMSJ2W4B3erxdaXk5mrvJV6oSRwQ4V3HXB4mjC /6z1Dzah/3mPlPJWEVuudRYR6oLyJd2xRuFhtOkQwZxZlywH/5tkxer3WLu2lkBSwcYh Nydw== X-Gm-Message-State: AOAM533w27Mju1t26zUmTS2LB1j7IxILqaIap5VXY6nIATGc/ZpTgSGE thkxVNdnbrXqziHxKdA4avAD4qe524s= X-Google-Smtp-Source: ABdhPJx6aGrd1gCou+4No4mEDnKGA5XmGcDLmUcfMEJptv3Ws1wdXlC9tm9IEF8CQ8l4cIUx8BWlbA== X-Received: by 2002:a7b:ca4a:: with SMTP id m10mr2929422wml.11.1601037222320; Fri, 25 Sep 2020 05:33:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d5sm2790976wrb.28.2020.09.25.05.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:41 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:32 +0000 Subject: [PATCH v4 2/8] maintenance: add loose-objects task Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee One goal of background maintenance jobs is to allow a user to disable auto-gc (gc.auto=0) but keep their repository in a clean state. Without any cleanup, loose objects will clutter the object database and slow operations. In addition, the loose objects will take up extra space because they are not stored with deltas against similar objects. Create a 'loose-objects' task for the 'git maintenance run' command. This helps clean up loose objects without disrupting concurrent Git commands using the following sequence of events: 1. Run 'git prune-packed' to delete any loose objects that exist in a pack-file. Concurrent commands will prefer the packed version of the object to the loose version. (Of course, there are exceptions for commands that specifically care about the location of an object. These are rare for a user to run on purpose, and we hope a user that has selected background maintenance will not be trying to do foreground maintenance.) 2. Run 'git pack-objects' on a batch of loose objects. These objects are grouped by scanning the loose object directories in lexicographic order until listing all loose objects -or- reaching 50,000 objects. This is more than enough if the loose objects are created only by a user doing normal development. We noticed users with _millions_ of loose objects because VFS for Git downloads blobs on-demand when a file read operation requires populating a virtual file. This step is based on a similar step in Scalar [1] and VFS for Git. [1] https://github.com/microsoft/scalar/blob/master/Scalar.Common/Maintenance/LooseObjectsStep.cs Signed-off-by: Derrick Stolee --- Documentation/git-maintenance.txt | 15 +++++ builtin/gc.c | 97 +++++++++++++++++++++++++++++++ t/t7900-maintenance.sh | 39 +++++++++++++ 3 files changed, 151 insertions(+) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index 12668fccf7..fc95eb594f 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -70,6 +70,21 @@ gc:: be disruptive in some situations, as it deletes stale data. See linkgit:git-gc[1] for more details on garbage collection in Git. +loose-objects:: + The `loose-objects` job cleans up loose objects and places them into + pack-files. In order to prevent race conditions with concurrent Git + commands, it follows a two-step process. First, it deletes any loose + objects that already exist in a pack-file; concurrent Git processes + will examine the pack-file for the object data instead of the loose + object. Second, it creates a new pack-file (starting with "loose-") + containing a batch of loose objects. The batch size is limited to 50 + thousand objects to prevent the job from taking too long on a + repository with many loose objects. The `gc` task writes unreachable + objects as loose objects to be cleaned up by a later step only if + they are not re-added to a pack-file; for this reason it is not + advisable to enable both the `loose-objects` and `gc` tasks at the + same time. + OPTIONS ------- --auto:: diff --git a/builtin/gc.c b/builtin/gc.c index 5e469488f4..c9db8555b9 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -880,6 +880,98 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts) return run_command(&child); } +static int prune_packed(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_push(&child.args, "prune-packed"); + + if (opts->quiet) + strvec_push(&child.args, "--quiet"); + + return !!run_command(&child); +} + +struct write_loose_object_data { + FILE *in; + int count; + int batch_size; +}; + +static int bail_on_loose(const struct object_id *oid, + const char *path, + void *data) +{ + return 1; +} + +static int write_loose_object_to_stdin(const struct object_id *oid, + const char *path, + void *data) +{ + struct write_loose_object_data *d = (struct write_loose_object_data *)data; + + fprintf(d->in, "%s\n", oid_to_hex(oid)); + + return ++(d->count) > d->batch_size; +} + +static int pack_loose(struct maintenance_run_opts *opts) +{ + struct repository *r = the_repository; + int result = 0; + struct write_loose_object_data data; + struct child_process pack_proc = CHILD_PROCESS_INIT; + + /* + * Do not start pack-objects process + * if there are no loose objects. + */ + if (!for_each_loose_file_in_objdir(r->objects->odb->path, + bail_on_loose, + NULL, NULL, NULL)) + return 0; + + pack_proc.git_cmd = 1; + + strvec_push(&pack_proc.args, "pack-objects"); + if (opts->quiet) + strvec_push(&pack_proc.args, "--quiet"); + strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path); + + pack_proc.in = -1; + + if (start_command(&pack_proc)) { + error(_("failed to start 'git pack-objects' process")); + return 1; + } + + data.in = xfdopen(pack_proc.in, "w"); + data.count = 0; + data.batch_size = 50000; + + for_each_loose_file_in_objdir(r->objects->odb->path, + write_loose_object_to_stdin, + NULL, + NULL, + &data); + + fclose(data.in); + + if (finish_command(&pack_proc)) { + error(_("failed to finish 'git pack-objects' process")); + result = 1; + } + + return result; +} + +static int maintenance_task_loose_objects(struct maintenance_run_opts *opts) +{ + return prune_packed(opts) || pack_loose(opts); +} + typedef int maintenance_task_fn(struct maintenance_run_opts *opts); /* @@ -901,6 +993,7 @@ struct maintenance_task { enum maintenance_task_label { TASK_PREFETCH, + TASK_LOOSE_OBJECTS, TASK_GC, TASK_COMMIT_GRAPH, @@ -913,6 +1006,10 @@ static struct maintenance_task tasks[] = { "prefetch", maintenance_task_prefetch, }, + [TASK_LOOSE_OBJECTS] = { + "loose-objects", + maintenance_task_loose_objects, + }, [TASK_GC] = { "gc", maintenance_task_gc, diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 045524e6ad..b3fc7c8670 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -88,4 +88,43 @@ test_expect_success 'prefetch multiple remotes' ' test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two ' +test_expect_success 'loose-objects task' ' + # Repack everything so we know the state of the object dir + git repack -adk && + + # Hack to stop maintenance from running during "git commit" + echo in use >.git/objects/maintenance.lock && + + # Assuming that "git commit" creates at least one loose object + test_commit create-loose-object && + rm .git/objects/maintenance.lock && + + ls .git/objects >obj-dir-before && + test_file_not_empty obj-dir-before && + ls .git/objects/pack/*.pack >packs-before && + test_line_count = 1 packs-before && + + # The first run creates a pack-file + # but does not delete loose objects. + git maintenance run --task=loose-objects && + ls .git/objects >obj-dir-between && + test_cmp obj-dir-before obj-dir-between && + ls .git/objects/pack/*.pack >packs-between && + test_line_count = 2 packs-between && + ls .git/objects/pack/loose-*.pack >loose-packs && + test_line_count = 1 loose-packs && + + # The second run deletes loose objects + # but does not create a pack-file. + git maintenance run --task=loose-objects && + ls .git/objects >obj-dir-after && + cat >expect <<-\EOF && + info + pack + EOF + test_cmp expect obj-dir-after && + ls .git/objects/pack/*.pack >packs-after && + test_cmp packs-between packs-after +' + test_done From patchwork Fri Sep 25 12:33:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11799675 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 624AC6CB for ; Fri, 25 Sep 2020 12:33:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F80F221EC for ; Fri, 25 Sep 2020 12:33:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HM171Njt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728385AbgIYMdr (ORCPT ); Fri, 25 Sep 2020 08:33:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbgIYMdq (ORCPT ); Fri, 25 Sep 2020 08:33:46 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6E3C0613CE for ; Fri, 25 Sep 2020 05:33:45 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id z1so3440702wrt.3 for ; Fri, 25 Sep 2020 05:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IFn8sXqu3y7CJ2B6xvw1fX294ScrkHS7U4HmAuCJPps=; b=HM171NjtP4NqinQ2QFQKPdTTI89w6TNxOqp2SWH4xYMUX5v9HYND6CVLXZwtBrc4UM tGx6CY2AdyXah99/50j/7CUUwvESyMPLYynLkc/zr1OF+rdlZKKfTxlBYx5lRrXlCL+Q YIG/NYece7dwIDUSnkXpvn5faywN1JzMWj99KMWekL9ZzZe4pFaZMlEcDTyU8fYBaG1r riPYsgWIcSfqWuSDqz7wQG5f6ONEMWSW5bDpiNoFVKk7PMn/fCRwPH4AV89xu1vGXkXy rffyFm7fXsUQqd+UFFA9pJ27VSVdpWXIilpcrxq22oZTGz9ea+FO6RlR0DyPsmibGnlj ypzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IFn8sXqu3y7CJ2B6xvw1fX294ScrkHS7U4HmAuCJPps=; b=K69NjghR3VKjHDG1Mr5hfeWtzmoAD90Hj0y1fzJEsgli26p5Kh9LG/S/x2UqFF1kC0 ADzriPYx5O3tP7z3Zaik4pCEuLQ7KHBU5nSkO4Z9fLGvKCJct0Zu2TJ1p8wV7UG1tAa1 yzL3QfzJobJ2xPmRbs5nY89fI+1mKbPrZYye86Gt9yXqQsqVhOnBqJxdyS+HgoMM6+W3 5L/QfNKyaUItoCU67VfG/6j4WtaAEc5iKjMg55y69PgE0lWqTZm2JzYGpR8z0U+sgmZ1 gs8OmSQGDJVinPWN+Sbpk2HbKx+wpk7resrT04l6cfrDhAJdb37zqGw6Q+uqWH1GYsxH l+Yg== X-Gm-Message-State: AOAM533Ac0f3hCyL90BZEUCHEZccKmThQ8F6lZDiPTTOD8yoQcY/Q/8z dlZ/6merzY9wzDG2MizhZsDSvIDKgjs= X-Google-Smtp-Source: ABdhPJySD/JIg788hqTl2j2DpgoXgIQgKAAU2ltg9xi/nmg2tZMl/wh5Jd/LKmgR+/44wCMK3gg2Ow== X-Received: by 2002:adf:9b8b:: with SMTP id d11mr4562305wrc.71.1601037223168; Fri, 25 Sep 2020 05:33:43 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k6sm2695494wmf.30.2020.09.25.05.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:42 -0700 (PDT) Message-Id: <931fff4883a3da26a296af69a9c5ccc3a5037d71.1601037218.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:33 +0000 Subject: [PATCH v4 3/8] maintenance: create auto condition for loose-objects Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The loose-objects task deletes loose objects that already exist in a pack-file, then place the remaining loose objects into a new pack-file. If this step runs all the time, then we risk creating pack-files with very few objects with every 'git commit' process. To prevent overwhelming the packs directory with small pack-files, place a minimum number of objects to justify the task. The 'maintenance.loose-objects.auto' config option specifies a minimum number of loose objects to justify the task to run under the '--auto' option. This defaults to 100 loose objects. Setting the value to zero will prevent the step from running under '--auto' while a negative value will force it to run every time. Signed-off-by: Derrick Stolee --- Documentation/config/maintenance.txt | 9 +++++++++ builtin/gc.c | 30 ++++++++++++++++++++++++++++ t/t7900-maintenance.sh | 22 ++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt index 7cc6700d57..c31613be62 100644 --- a/Documentation/config/maintenance.txt +++ b/Documentation/config/maintenance.txt @@ -14,3 +14,12 @@ maintenance.commit-graph.auto:: reachable commits that are not in the commit-graph file is at least the value of `maintenance.commit-graph.auto`. The default value is 100. + +maintenance.loose-objects.auto:: + This integer config option controls how often the `loose-objects` task + should be run as part of `git maintenance run --auto`. If zero, then + the `loose-objects` task will not run with the `--auto` option. A + negative value will force the task to run every time. Otherwise, a + positive value implies the command should run when the number of + loose objects is at least the value of `maintenance.loose-objects.auto`. + The default value is 100. diff --git a/builtin/gc.c b/builtin/gc.c index c9db8555b9..4403827481 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -899,6 +899,35 @@ struct write_loose_object_data { int batch_size; }; +static int loose_object_auto_limit = 100; + +static int loose_object_count(const struct object_id *oid, + const char *path, + void *data) +{ + int *count = (int*)data; + if (++(*count) >= loose_object_auto_limit) + return 1; + return 0; +} + +static int loose_object_auto_condition(void) +{ + int count = 0; + + git_config_get_int("maintenance.loose-objects.auto", + &loose_object_auto_limit); + + if (!loose_object_auto_limit) + return 0; + if (loose_object_auto_limit < 0) + return 1; + + return for_each_loose_file_in_objdir(the_repository->objects->odb->path, + loose_object_count, + NULL, NULL, &count); +} + static int bail_on_loose(const struct object_id *oid, const char *path, void *data) @@ -1009,6 +1038,7 @@ static struct maintenance_task tasks[] = { [TASK_LOOSE_OBJECTS] = { "loose-objects", maintenance_task_loose_objects, + loose_object_auto_condition, }, [TASK_GC] = { "gc", diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index b3fc7c8670..27565c55a2 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -127,4 +127,26 @@ test_expect_success 'loose-objects task' ' test_cmp packs-between packs-after ' +test_expect_success 'maintenance.loose-objects.auto' ' + git repack -adk && + GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \ + git -c maintenance.loose-objects.auto=1 maintenance \ + run --auto --task=loose-objects 2>/dev/null && + test_subcommand ! git prune-packed --quiet /dev/null && + test_subcommand ! git prune-packed --quiet /dev/null && + test_subcommand git prune-packed --quiet /dev/null && + test_subcommand git prune-packed --quiet X-Patchwork-Id: 11799677 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D7256CB for ; Fri, 25 Sep 2020 12:33:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D07F221EC for ; Fri, 25 Sep 2020 12:33:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u6HcbF4X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728382AbgIYMdr (ORCPT ); Fri, 25 Sep 2020 08:33:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728353AbgIYMdq (ORCPT ); Fri, 25 Sep 2020 08:33:46 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5E66C0613D3 for ; Fri, 25 Sep 2020 05:33:45 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id e2so3122853wme.1 for ; Fri, 25 Sep 2020 05:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Ry0hpw+x89x8hU9nQ5fnnsze4ID6eAXp+p+08m26Kb4=; b=u6HcbF4XKdonJ1XI5R/6EizjwMO8eshPL09M5E2dzkXDUJGP2KUjIUOVYo3CZ0EXbV cJon2C9YpyBBnO8DIFZeuywV8kKJxzpdZbvA34+GMjJ2sA0CqimXg6Uvz8CFxj3IZPJA ti685QhKSVdxFpF6dSWp5bte/cznDKqSaq/zLzXiZ3hWH3EipfPvSt72B/PY7lCsOgnc PGZs19FgHu4Qy1iRZ3ZfWvVb7dfRjalnNZq5RegMaIZmNap1f/vv6LoNvZaVB0o9h5jl 8hLbfOBI9DUzB6NqNSMi3x5a8knEy9mYXhwC7tS/eo2wM/3LPQ8CGaxG6K2NP3LyXtIR m8OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Ry0hpw+x89x8hU9nQ5fnnsze4ID6eAXp+p+08m26Kb4=; b=YQgYZobhv+8N6bZ8zAZDRmjRHMVLaHDlnRpVlB/8H6Z6mQqPMOypwSVtDPkCp5FzNQ 4cHm4RGO7SUR+PIXqZOjNKLDDlRiF8DhhQ+DN4UgnvVpO9h5trRWIK29Zc53BrwxHZXY KSHBqkYdiz3LWrrRzHSSeojy1xA+ir110+Jtf0Q6KxgF5QMFL0ySPRTjeJ1nZAfWzwj7 19VGLd2Eo6vcNWffqscSTr0j1O7JUb1mv+oUVW4u44TosHW4LboIJ+fmEp9WX778XeW/ MHUfhiVhIfSvwxtLPaTu5F2ERh3VzhEbX3Ap+5r1i+tfmxQPoZ+wJhoNcnGR5FT6/xLx 1mKA== X-Gm-Message-State: AOAM531uzfy4gh8bsOnmFvSzQRl1N+V3mOgX9U4AwGUdwazGGoQukCAl ibcmXg2/exOsHrvFsvHF2Ezm0gvB13g= X-Google-Smtp-Source: ABdhPJyKs3XseOdT0AvXCrXPqML4A9gjm1+WGPdPRYhIHSpGHjYlrOMcLhL2fhpJPb3R1RyAMRWZ0g== X-Received: by 2002:a1c:4d4:: with SMTP id 203mr3005614wme.102.1601037224344; Fri, 25 Sep 2020 05:33:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y1sm2826009wmi.36.2020.09.25.05.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:43 -0700 (PDT) Message-Id: <0fe2036aa84794a3c592f294eceb8df76a637207.1601037218.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:34 +0000 Subject: [PATCH v4 4/8] midx: enable core.multiPackIndex by default Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The core.multiPackIndex setting has been around since c4d25228ebb (config: create core.multiPackIndex setting, 2018-07-12), but has been disabled by default. If a user wishes to use the multi-pack-index feature, then they must enable this config and run 'git multi-pack-index write'. The multi-pack-index feature is relatively stable now, so make the config option true by default. For users that do not use a multi-pack-index, the only extra cost will be a file lookup to see if a multi-pack-index file exists (once per process, per object directory). Also, this config option will be referenced by an upcoming "incremental-repack" task in the maintenance builtin, so move the config option into the repository settings struct. Note that if GIT_TEST_MULTI_PACK_INDEX=1, then we want to ignore the config option and treat core.multiPackIndex as enabled. Signed-off-by: Derrick Stolee --- Documentation/config/core.txt | 4 ++-- midx.c | 11 +++-------- repo-settings.c | 6 ++++++ repository.h | 2 ++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt index 74619a9c03..86c91d5381 100644 --- a/Documentation/config/core.txt +++ b/Documentation/config/core.txt @@ -606,8 +606,8 @@ core.useReplaceRefs:: core.multiPackIndex:: Use the multi-pack-index file to track multiple packfiles using a - single index. See link:technical/multi-pack-index.html[the - multi-pack-index design document]. + single index. See linkgit:git-multi-pack-index[1] for more + information. Defaults to true. core.sparseCheckout:: Enable "sparse checkout" feature. See linkgit:git-sparse-checkout[1] diff --git a/midx.c b/midx.c index a5fb797ede..ef499cf504 100644 --- a/midx.c +++ b/midx.c @@ -10,6 +10,7 @@ #include "progress.h" #include "trace2.h" #include "run-command.h" +#include "repository.h" #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */ #define MIDX_VERSION 1 @@ -384,15 +385,9 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i { struct multi_pack_index *m; struct multi_pack_index *m_search; - int config_value; - static int env_value = -1; - if (env_value < 0) - env_value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0); - - if (!env_value && - (repo_config_get_bool(r, "core.multipackindex", &config_value) || - !config_value)) + prepare_repo_settings(r); + if (!r->settings.core_multi_pack_index) return 0; for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next) diff --git a/repo-settings.c b/repo-settings.c index 0918408b34..5bd2c22726 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "repository.h" +#include "midx.h" #define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0) @@ -47,6 +48,11 @@ void prepare_repo_settings(struct repository *r) r->settings.pack_use_sparse = value; UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1); + value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0); + if (value || !repo_config_get_bool(r, "core.multipackindex", &value)) + r->settings.core_multi_pack_index = value; + UPDATE_DEFAULT_BOOL(r->settings.core_multi_pack_index, 1); + if (!repo_config_get_bool(r, "feature.manyfiles", &value) && value) { UPDATE_DEFAULT_BOOL(r->settings.index_version, 4); UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE); diff --git a/repository.h b/repository.h index 3c1f7d54bd..3901ce0b65 100644 --- a/repository.h +++ b/repository.h @@ -37,6 +37,8 @@ struct repo_settings { int pack_use_sparse; enum fetch_negotiation_setting fetch_negotiation_algorithm; + + int core_multi_pack_index; }; struct repository { From patchwork Fri Sep 25 12:33:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11799683 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83CC86CB for ; Fri, 25 Sep 2020 12:33:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61D61221EC for ; Fri, 25 Sep 2020 12:33:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JkxYn4sJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728407AbgIYMdu (ORCPT ); Fri, 25 Sep 2020 08:33:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbgIYMdr (ORCPT ); Fri, 25 Sep 2020 08:33:47 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD080C0613CE for ; Fri, 25 Sep 2020 05:33:46 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id e16so3455188wrm.2 for ; Fri, 25 Sep 2020 05:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ddgOxQAf9A7kFmL2ILUM2HpYvMuwscp0rEU6vEGE8Rg=; b=JkxYn4sJj/JIB+ZCEhsK4MsQd401RndDnSiSx+jbpDJC06yxtcLe0dcO3+xE0uOCs/ wBf7iW/at6Nb9/9DuImYPp91c4RNvt1e2cesKLQER9MiBj4zvHvlhyGstVIKErbCMgq8 BGEUXn9CcQmcwczyqyaS2IhM9YbqJvjQnv1oSLG3vJNrmvOSW2U69xLTHF2/fBfLImrQ SUNZQurYPn08HvWd0hruEFHntvPCTNRdyMA1ZjLOCrqWjLUQ4fw9ckFXKUvlMF0uBfho VNOHldEQgO384r1Qhl8QoUJn/CvhGV3J0OLGIqSbVqkipYf/2bNKvStjoZTnH2/p6QOX 843A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ddgOxQAf9A7kFmL2ILUM2HpYvMuwscp0rEU6vEGE8Rg=; b=XG0sOZGTglnn6J7TQsYXiKMoWwujFDnDQnv/DlMzWAOIknkXS2rYIr9/AOv3+Qtk0j maUCteDcej417R2BhGpGdwU7vu+6vkSEPgQPME3ZBcPVcf6mgaq+42QdgcL9Yxp6ab66 LnZmUmZVyLU5fkKm0XM71AX2SeNWFXEzmN9zG/MKkYKyIC2A0Xc3utoayghv/TR//xLu diKG1AuH9nOrWApmhe1WmbZQU5G9A/5YHLpJFnPEJBIpwqYQ3kUMBYoUqh6SnMa3QfPt GJsxn6koOncZtuGEPj3DRB5DGJBpRIM7GhdDdY2SWtYjzjQieVNB2gKV+9oEZs9kVOGf wYPg== X-Gm-Message-State: AOAM5305+xN0uXkd4t001kg4yZ2uCx2Di5T9XEkp+uPbChyHcabmZgkJ MY8pyqp9AbgCTq/g8H0qAL46+30WTIY= X-Google-Smtp-Source: ABdhPJwK2P9a3DPcumd5IMSGO6tbuZ9unPPSK0AJlpFUGMRbPkQp9V0AVaDfP/uXAd9qrbAqmNxXKw== X-Received: by 2002:adf:8481:: with SMTP id 1mr4126787wrg.231.1601037225161; Fri, 25 Sep 2020 05:33:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c16sm3045899wrx.31.2020.09.25.05.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:44 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:35 +0000 Subject: [PATCH v4 5/8] midx: use start_delayed_progress() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee Now that the multi-pack-index may be written as part of auto maintenance at the end of a command, reduce the progress output when the operations are quick. Use start_delayed_progress() instead of start_progress(). Update t5319-multi-pack-index.sh to use GIT_PROGRESS_DELAY=0 now that the progress indicators are conditional. Signed-off-by: Derrick Stolee --- midx.c | 10 +++++----- t/t5319-multi-pack-index.sh | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/midx.c b/midx.c index ef499cf504..aa37d5da86 100644 --- a/midx.c +++ b/midx.c @@ -832,7 +832,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * packs.pack_paths_checked = 0; if (flags & MIDX_PROGRESS) - packs.progress = start_progress(_("Adding packfiles to multi-pack-index"), 0); + packs.progress = start_delayed_progress(_("Adding packfiles to multi-pack-index"), 0); else packs.progress = NULL; @@ -969,7 +969,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * } if (flags & MIDX_PROGRESS) - progress = start_progress(_("Writing chunks to multi-pack-index"), + progress = start_delayed_progress(_("Writing chunks to multi-pack-index"), num_chunks); for (i = 0; i < num_chunks; i++) { if (written != chunk_offsets[i]) @@ -1104,7 +1104,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag return 0; if (flags & MIDX_PROGRESS) - progress = start_progress(_("Looking for referenced packfiles"), + progress = start_delayed_progress(_("Looking for referenced packfiles"), m->num_packs); for (i = 0; i < m->num_packs; i++) { if (prepare_midx_pack(r, m, i)) @@ -1225,7 +1225,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla count = xcalloc(m->num_packs, sizeof(uint32_t)); if (flags & MIDX_PROGRESS) - progress = start_progress(_("Counting referenced objects"), + progress = start_delayed_progress(_("Counting referenced objects"), m->num_objects); for (i = 0; i < m->num_objects; i++) { int pack_int_id = nth_midxed_pack_int_id(m, i); @@ -1235,7 +1235,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla stop_progress(&progress); if (flags & MIDX_PROGRESS) - progress = start_progress(_("Finding and deleting unreferenced packfiles"), + progress = start_delayed_progress(_("Finding and deleting unreferenced packfiles"), m->num_packs); for (i = 0; i < m->num_packs; i++) { char *pack_name; diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index 7dfff0f8f4..ec87f616c6 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -171,12 +171,12 @@ test_expect_success 'write progress off for redirected stderr' ' ' test_expect_success 'write force progress on for stderr' ' - git multi-pack-index --object-dir=$objdir --progress write 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress write 2>err && test_file_not_empty err ' test_expect_success 'write with the --no-progress option' ' - git multi-pack-index --object-dir=$objdir --no-progress write 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress write 2>err && test_line_count = 0 err ' @@ -333,17 +333,17 @@ test_expect_success 'git-fsck incorrect offset' ' ' test_expect_success 'repack progress off for redirected stderr' ' - git multi-pack-index --object-dir=$objdir repack 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err && test_line_count = 0 err ' test_expect_success 'repack force progress on for stderr' ' - git multi-pack-index --object-dir=$objdir --progress repack 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress repack 2>err && test_file_not_empty err ' test_expect_success 'repack with the --no-progress option' ' - git multi-pack-index --object-dir=$objdir --no-progress repack 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err && test_line_count = 0 err ' @@ -487,7 +487,7 @@ test_expect_success 'expire progress off for redirected stderr' ' test_expect_success 'expire force progress on for stderr' ' ( cd dup && - git multi-pack-index --progress expire 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --progress expire 2>err && test_file_not_empty err ) ' @@ -495,7 +495,7 @@ test_expect_success 'expire force progress on for stderr' ' test_expect_success 'expire with the --no-progress option' ' ( cd dup && - git multi-pack-index --no-progress expire 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --no-progress expire 2>err && test_line_count = 0 err ) ' From patchwork Fri Sep 25 12:33:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11799689 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D366A6CA for ; Fri, 25 Sep 2020 12:33:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7B4B221EC for ; Fri, 25 Sep 2020 12:33:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g2SoVgSE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728425AbgIYMdx (ORCPT ); Fri, 25 Sep 2020 08:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728408AbgIYMdv (ORCPT ); Fri, 25 Sep 2020 08:33:51 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C01B9C0613CE for ; Fri, 25 Sep 2020 05:33:50 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id x23so2872402wmi.3 for ; Fri, 25 Sep 2020 05:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=QIbMubR6XPTcLJCCXZ/cPVJHClgQk4CRkOlHS0Kbmsk=; b=g2SoVgSEs8233Fu83xlHiz32UZaClBHgWUN3s94JcY6fOAZHshRDDYFi08KWoGQ7OF 3YrwkdHZJfu4lJmERfBtNJRS0NQummXbtDMZ/lrX9zpBDBzGDpe4aDCi3+7A0PXbyMTj HKbpZC2TefUtOvlpeDSVJIOYmgmGNBWxjh1OIEnJnPsiY22jtpAwJhdJoxjkrRKksmdG whmrX+Aw4RfztiA8X/UP7U/lyUPS4EUeELl90ZUruXmqjUSNedQ98M+/kFaG9RMJ1ZQk LSjmFRV4rLdLoegIrffh8Luudv7mp9I6Ar/a7ajEVwKoBuIxlV/18ojPwWKIcJ6VvrHh Tmsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=QIbMubR6XPTcLJCCXZ/cPVJHClgQk4CRkOlHS0Kbmsk=; b=OU0aax+XYYjNPvUDYe089lBxLIEFPJJjYd+2VmjfukpaacxnVkUEB6nnwBXU6WK5xA E/oA+k5R9SuolDIFHxIm0Q/H9N0xZhyXi4Ak7qd81/p23I8oOAyQSSuj1mP6ZG0wmmvg SXkX2QN0+O7sRdasvJl1u1FcOW9KnNuIZFHq8cqkECvj5I15N4clh0zvs3D9Etl5rCP3 YSVqL0w11iWz5sovr4eSVwmpAhIYyFxj9NORnxvNdtjp1vEo6J+PVJgVtWWHKXLENHdw g2ALjGLXS2FiHDO78HZJHatFSf8CIFh1ijc8yp7uKtOom4wdfvvteP28HLzAcevzxhC1 i4aQ== X-Gm-Message-State: AOAM531lMAlxCep1waPoAKTOORi2UzZU412tLo19sgU4ldeYTt24uCYZ Z+E5ItZhr9GAjjQ0/i8iU/eTu+vAnDQ= X-Google-Smtp-Source: ABdhPJzWuxsdZp7fkkUGgHgyl/BX6ue8ZiMby4tGeXGH99UOKRaYIdO2m1mAVj1+n+dcUUFPidX7Kg== X-Received: by 2002:a1c:7d55:: with SMTP id y82mr2933772wmc.100.1601037226089; Fri, 25 Sep 2020 05:33:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q12sm2713279wrs.48.2020.09.25.05.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:45 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:36 +0000 Subject: [PATCH v4 6/8] maintenance: add incremental-repack task Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The previous change cleaned up loose objects using the 'loose-objects' that can be run safely in the background. Add a similar job that performs similar cleanups for pack-files. One issue with running 'git repack' is that it is designed to repack all pack-files into a single pack-file. While this is the most space-efficient way to store object data, it is not time or memory efficient. This becomes extremely important if the repo is so large that a user struggles to store two copies of the pack on their disk. Instead, perform an "incremental" repack by collecting a few small pack-files into a new pack-file. The multi-pack-index facilitates this process ever since 'git multi-pack-index expire' was added in 19575c7 (multi-pack-index: implement 'expire' subcommand, 2019-06-10) and 'git multi-pack-index repack' was added in ce1e4a1 (midx: implement midx_repack(), 2019-06-10). The 'incremental-repack' task runs the following steps: 1. 'git multi-pack-index write' creates a multi-pack-index file if one did not exist, and otherwise will update the multi-pack-index with any new pack-files that appeared since the last write. This is particularly relevant with the background fetch job. When the multi-pack-index sees two copies of the same object, it stores the offset data into the newer pack-file. This means that some old pack-files could become "unreferenced" which I will use to mean "a pack-file that is in the pack-file list of the multi-pack-index but none of the objects in the multi-pack-index reference a location inside that pack-file." 2. 'git multi-pack-index expire' deletes any unreferenced pack-files and updaes the multi-pack-index to drop those pack-files from the list. This is safe to do as concurrent Git processes will see the multi-pack-index and not open those packs when looking for object contents. (Similar to the 'loose-objects' job, there are some Git commands that open pack-files regardless of the multi-pack-index, but they are rarely used. Further, a user that self-selects to use background operations would likely refrain from using those commands.) 3. 'git multi-pack-index repack --bacth-size=' collects a set of pack-files that are listed in the multi-pack-index and creates a new pack-file containing the objects whose offsets are listed by the multi-pack-index to be in those objects. The set of pack- files is selected greedily by sorting the pack-files by modified time and adding a pack-file to the set if its "expected size" is smaller than the batch size until the total expected size of the selected pack-files is at least the batch size. The "expected size" is calculated by taking the size of the pack-file divided by the number of objects in the pack-file and multiplied by the number of objects from the multi-pack-index with offset in that pack-file. The expected size approximates how much data from that pack-file will contribute to the resulting pack-file size. The intention is that the resulting pack-file will be close in size to the provided batch size. The next run of the incremental-repack task will delete these repacked pack-files during the 'expire' step. In this version, the batch size is set to "0" which ignores the size restrictions when selecting the pack-files. It instead selects all pack-files and repacks all packed objects into a single pack-file. This will be updated in the next change, but it requires doing some calculations that are better isolated to a separate change. These steps are based on a similar background maintenance step in Scalar (and VFS for Git) [1]. This was incredibly effective for users of the Windows OS repository. After using the same VFS for Git repository for over a year, some users had _thousands_ of pack-files that combined to up to 250 GB of data. We noticed a few users were running into the open file descriptor limits (due in part to a bug in the multi-pack-index fixed by af96fe3 (midx: add packs to packed_git linked list, 2019-04-29). These pack-files were mostly small since they contained the commits and trees that were pushed to the origin in a given hour. The GVFS protocol includes a "prefetch" step that asks for pre-computed pack- files containing commits and trees by timestamp. These pack-files were grouped into "daily" pack-files once a day for up to 30 days. If a user did not request prefetch packs for over 30 days, then they would get the entire history of commits and trees in a new, large pack-file. This led to a large number of pack-files that had poor delta compression. By running this pack-file maintenance step once per day, these repos with thousands of packs spanning 200+ GB dropped to dozens of pack- files spanning 30-50 GB. This was done all without removing objects from the system and using a constant batch size of two gigabytes. Once the work was done to reduce the pack-files to small sizes, the batch size of two gigabytes means that not every run triggers a repack operation, so the following run will not expire a pack-file. This has kept these repos in a "clean" state. [1] https://github.com/microsoft/scalar/blob/master/Scalar.Common/Maintenance/PackfileMaintenanceStep.cs Signed-off-by: Derrick Stolee --- Documentation/git-maintenance.txt | 18 ++++++++ builtin/gc.c | 76 +++++++++++++++++++++++++++++++ t/t5319-multi-pack-index.sh | 1 + t/t7900-maintenance.sh | 38 ++++++++++++++++ 4 files changed, 133 insertions(+) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index fc95eb594f..3f5d8946b4 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -85,6 +85,24 @@ loose-objects:: advisable to enable both the `loose-objects` and `gc` tasks at the same time. +incremental-repack:: + The `incremental-repack` job repacks the object directory + using the `multi-pack-index` feature. In order to prevent race + conditions with concurrent Git commands, it follows a two-step + process. First, it calls `git multi-pack-index expire` to delete + pack-files unreferenced by the `multi-pack-index` file. Second, it + calls `git multi-pack-index repack` to select several small + pack-files and repack them into a bigger one, and then update the + `multi-pack-index` entries that refer to the small pack-files to + refer to the new pack-file. This prepares those small pack-files + for deletion upon the next run of `git multi-pack-index expire`. + The selection of the small pack-files is such that the expected + size of the big pack-file is at least the batch size; see the + `--batch-size` option for the `repack` subcommand in + linkgit:git-multi-pack-index[1]. The default batch-size is zero, + which is a special case that attempts to repack all pack-files + into a single pack-file. + OPTIONS ------- --auto:: diff --git a/builtin/gc.c b/builtin/gc.c index 4403827481..5f877b097a 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1001,6 +1001,77 @@ static int maintenance_task_loose_objects(struct maintenance_run_opts *opts) return prune_packed(opts) || pack_loose(opts); } +static int multi_pack_index_write(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "multi-pack-index", "write", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--no-progress"); + + if (run_command(&child)) + return error(_("failed to write multi-pack-index")); + + return 0; +} + +static int multi_pack_index_expire(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "multi-pack-index", "expire", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--no-progress"); + + close_object_store(the_repository->objects); + + if (run_command(&child)) + return error(_("'git multi-pack-index expire' failed")); + + return 0; +} + +static int multi_pack_index_repack(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "multi-pack-index", "repack", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--no-progress"); + + strvec_push(&child.args, "--batch-size=0"); + + close_object_store(the_repository->objects); + + if (run_command(&child)) + return error(_("'git multi-pack-index repack' failed")); + + return 0; +} + +static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts) +{ + prepare_repo_settings(the_repository); + if (!the_repository->settings.core_multi_pack_index) { + warning(_("skipping incremental-repack task because core.multiPackIndex is disabled")); + return 0; + } + + if (multi_pack_index_write(opts)) + return 1; + if (multi_pack_index_expire(opts)) + return 1; + if (multi_pack_index_repack(opts)) + return 1; + return 0; +} + typedef int maintenance_task_fn(struct maintenance_run_opts *opts); /* @@ -1023,6 +1094,7 @@ struct maintenance_task { enum maintenance_task_label { TASK_PREFETCH, TASK_LOOSE_OBJECTS, + TASK_INCREMENTAL_REPACK, TASK_GC, TASK_COMMIT_GRAPH, @@ -1040,6 +1112,10 @@ static struct maintenance_task tasks[] = { maintenance_task_loose_objects, loose_object_auto_condition, }, + [TASK_INCREMENTAL_REPACK] = { + "incremental-repack", + maintenance_task_incremental_repack, + }, [TASK_GC] = { "gc", maintenance_task_gc, diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index ec87f616c6..2f942ee1fa 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -3,6 +3,7 @@ test_description='multi-pack-indexes' . ./test-lib.sh +GIT_TEST_MULTI_PACK_INDEX=0 objdir=.git/objects midx_read_expect () { diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 27565c55a2..a2db2291b0 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -5,6 +5,7 @@ test_description='git maintenance builtin' . ./test-lib.sh GIT_TEST_COMMIT_GRAPH=0 +GIT_TEST_MULTI_PACK_INDEX=0 test_expect_success 'help text' ' test_expect_code 129 git maintenance -h 2>err && @@ -149,4 +150,41 @@ test_expect_success 'maintenance.loose-objects.auto' ' test_subcommand git prune-packed --quiet packs-before && + test_line_count = 3 packs-before && + + # the job repacks the two into a new pack, but does not + # delete the old ones. + git maintenance run --task=incremental-repack && + ls $packDir/*.pack >packs-between && + test_line_count = 4 packs-between && + + # the job deletes the two old packs, and does not write + # a new one because only one pack remains. + git maintenance run --task=incremental-repack && + ls .git/objects/pack/*.pack >packs-after && + test_line_count = 1 packs-after +' + test_done From patchwork Fri Sep 25 12:33:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11799685 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99A146CB for ; Fri, 25 Sep 2020 12:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7480F21D91 for ; Fri, 25 Sep 2020 12:33:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YSKwtzso" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728414AbgIYMdv (ORCPT ); Fri, 25 Sep 2020 08:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbgIYMds (ORCPT ); Fri, 25 Sep 2020 08:33:48 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7692FC0613CE for ; Fri, 25 Sep 2020 05:33:48 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id w5so3404878wrp.8 for ; Fri, 25 Sep 2020 05:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=mLlzQzqhmLMuWlvzwdcUhGaHdx1mdNT/YofPN6ovyOY=; b=YSKwtzsoxaoxM0DkOJZXFgVR+d5uTM/LaMLU+2Kh/Z8KlJtwKnDo4va2IvfoJu5049 NDgvmWRmwcHWWLTM1bf59SKMo2F43zalhUYhLP0PSg/U+CCLA4NfKQg7z1wpMKzaGDVD N95C5h/+5zj5M/B9Lp8RkItawhkyUJqT145EMQuh69VrdfBMG53xN0ecNXiby7k/CALs e7uBN+62sV6M10aq3NYSd6SXwuzGaGBdsgMlY384rDucdkatqTR+G/mdgHAAs9DgsKP8 w0W2ue01IGpewBSVdsNHEnPovYj/77DOkAPDac0JpuF0mI9Be9cnszhS9d9LiKa1Eakk NJbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=mLlzQzqhmLMuWlvzwdcUhGaHdx1mdNT/YofPN6ovyOY=; b=LdJzBFrIGlE6BdgnBxJEZZSyzah+N2CJpqcIfz/R0TXeb/FiLOl3qGCxTx382lmvNI Xc0q37f9+7zU1siUzlVtQBOBEy8YYiyUV84+SYbvzVXDaFBM1kGq5/+P4PHnB6nWQUgg YHnnSN1g4cN0DCpNXG0lmF3ZsjW2pfqUbNN3iJT5PLesakAdGjLi9m7bIEmI689WFFBu fWaLvVsxugZzE2+KSdOPhd0fbtPBGfsSgeBKvSvK/TIKfL9kQ9AeHL8WuHIVuRjyNZEK pkJzPht4QRN+by33/L+86LeVHX/raQ5Vov6lKPZp7cJrnRjsBO8dGv0MTEF3gKQat4wm zt8g== X-Gm-Message-State: AOAM531kG4j4GXWvP/KwM5H0cBWs/V+AMVICb9vGrVuCyNeOJcqsVSha jNAB1XF//m4NK8A3buJ5SdQ/hc04Cu4= X-Google-Smtp-Source: ABdhPJx5l8lG7AH9kdLPpC/FIGLxZ6ClmlOLU5LiqbUo5vcXV8kpmJJOmqQ26x8zHfIWc9QLegCbuw== X-Received: by 2002:adf:c3cc:: with SMTP id d12mr4315341wrg.399.1601037226987; Fri, 25 Sep 2020 05:33:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o4sm2705373wrv.86.2020.09.25.05.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:46 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:37 +0000 Subject: [PATCH v4 7/8] maintenance: auto-size incremental-repack batch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When repacking during the 'incremental-repack' task, we use the --batch-size option in 'git multi-pack-index repack'. The initial setting used --batch-size=0 to repack everything into a single pack-file. This is not sustainable for a large repository. The amount of work required is also likely to use too many system resources for a background job. Update the 'incremental-repack' task by dynamically computing a --batch-size option based on the current pack-file structure. The dynamic default size is computed with this idea in mind for a client repository that was cloned from a very large remote: there is likely one "big" pack-file that was created at clone time. Thus, do not try repacking it as it is likely packed efficiently by the server. Instead, we select the second-largest pack-file, and create a batch size that is one larger than that pack-file. If there are three or more pack-files, then this guarantees that at least two will be combined into a new pack-file. Of course, this means that the second-largest pack-file size is likely to grow over time and may eventually surpass the initially-cloned pack-file. Recall that the pack-file batch is selected in a greedy manner: the packs are considered from oldest to newest and are selected if they have size smaller than the batch size until the total selected size is larger than the batch size. Thus, that oldest "clone" pack will be first to repack after the new data creates a pack larger than that. We also want to place some limits on how large these pack-files become, in order to bound the amount of time spent repacking. A maximum batch-size of two gigabytes means that large repositories will never be packed into a single pack-file using this job, but also that repack is rather expensive. This is a trade-off that is valuable to have if the maintenance is being run automatically or in the background. Users who truly want to optimize for space and performance (and are willing to pay the upfront cost of a full repack) can use the 'gc' task to do so. Create a test for this two gigabyte limit by creating an EXPENSIVE test that generates two pack-files of roughly 2.5 gigabytes in size, then performs an incremental repack. Check that the --batch-size argument in the subcommand uses the hard-coded maximum. Helped-by: Chris Torek Reported-by: Son Luong Ngoc Signed-off-by: Derrick Stolee --- builtin/gc.c | 43 +++++++++++++++++++++++++++++++++++++++++- t/t7900-maintenance.sh | 36 +++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 5f877b097a..8d22361fa9 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1035,6 +1035,46 @@ static int multi_pack_index_expire(struct maintenance_run_opts *opts) return 0; } +#define TWO_GIGABYTES (INT32_MAX) + +static off_t get_auto_pack_size(void) +{ + /* + * The "auto" value is special: we optimize for + * one large pack-file (i.e. from a clone) and + * expect the rest to be small and they can be + * repacked quickly. + * + * The strategy we select here is to select a + * size that is one more than the second largest + * pack-file. This ensures that we will repack + * at least two packs if there are three or more + * packs. + */ + off_t max_size = 0; + off_t second_largest_size = 0; + off_t result_size; + struct packed_git *p; + struct repository *r = the_repository; + + reprepare_packed_git(r); + for (p = get_all_packs(r); p; p = p->next) { + if (p->pack_size > max_size) { + second_largest_size = max_size; + max_size = p->pack_size; + } else if (p->pack_size > second_largest_size) + second_largest_size = p->pack_size; + } + + result_size = second_largest_size + 1; + + /* But limit ourselves to a batch size of 2g */ + if (result_size > TWO_GIGABYTES) + result_size = TWO_GIGABYTES; + + return result_size; +} + static int multi_pack_index_repack(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; @@ -1045,7 +1085,8 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts) if (opts->quiet) strvec_push(&child.args, "--no-progress"); - strvec_push(&child.args, "--batch-size=0"); + strvec_pushf(&child.args, "--batch-size=%"PRIuMAX, + (uintmax_t)get_auto_pack_size()); close_object_store(the_repository->objects); diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index a2db2291b0..9e6ea23f35 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -181,10 +181,42 @@ test_expect_success 'incremental-repack task' ' test_line_count = 4 packs-between && # the job deletes the two old packs, and does not write - # a new one because only one pack remains. + # a new one because the batch size is not high enough to + # pack the largest pack-file. git maintenance run --task=incremental-repack && ls .git/objects/pack/*.pack >packs-after && - test_line_count = 1 packs-after + test_line_count = 2 packs-after +' + +test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' + for i in $(test_seq 1 5) + do + test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || + return 1 + done && + git add big && + git commit -m "Add big file (1)" && + + # ensure any possible loose objects are in a pack-file + git maintenance run --task=loose-objects && + + rm big && + for i in $(test_seq 6 10) + do + test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || + return 1 + done && + git add big && + git commit -m "Add big file (2)" && + + # ensure any possible loose objects are in a pack-file + git maintenance run --task=loose-objects && + + # Now run the incremental-repack task and check the batch-size + GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \ + --task=incremental-repack 2>/dev/null && + test_subcommand git multi-pack-index repack \ + --no-progress --batch-size=2147483647 X-Patchwork-Id: 11799687 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9AA466CA for ; Fri, 25 Sep 2020 12:33:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71F3A21D91 for ; Fri, 25 Sep 2020 12:33:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VUoaD1Zy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728417AbgIYMdw (ORCPT ); Fri, 25 Sep 2020 08:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728395AbgIYMdt (ORCPT ); Fri, 25 Sep 2020 08:33:49 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2CFC0613CE for ; Fri, 25 Sep 2020 05:33:49 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id z1so3440950wrt.3 for ; Fri, 25 Sep 2020 05:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ruMiJL9Ly9Neub2HM8SpytEdeFbyLqbh92U2YY1sLdc=; b=VUoaD1ZyfyKEKPNKg0JW18Hl/m/wQaGSl8Q04UMss8Yul1xt+EO8Na4QpRZHKhCdxO +iJjrhIzyQRrkWokS8UoKvMc+RIcCjdn7fB8kyEhGu04HDK5NSTYsNP8CzYijWDnd01+ 2Zc9yXAjoqiVCQtdn/XlYilKmEdYk0rKGZmHszirX3SmFxI7YhHWavB44/9jdajZnE2a Zanahms8K/bC7kH+e0gu6RxaBkx6mwYdj7swcXgpdt0OIAov7C5A2DH3FTfwHoChSvs0 pY31fcQ9R2RnH0BrYWpJcfkUOb/8pYaQTpsnZUBwtMs6PuDtjINsSGbmTZiJ+oULWGkT jAFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ruMiJL9Ly9Neub2HM8SpytEdeFbyLqbh92U2YY1sLdc=; b=iFz03jIxvQUAE5aw5eZ/IEjmupzLRHNQUHU3EsFBkVQF3dRVnIg8J+UBd88xQ6tpAX iWn73GkN95LkZlUCb+YonHfjPrNvfQdW3GWpV/UVcIPVu344DxovFEkFuDQa4Dik3rqP UoIKAjPLxmMCDtqLCtSvd7V7n9qbAzYO26qQWR28mNUnbzmx2ClC2x8wPwBrSBNSNpnG eWf4wc8LFFu7msRUg0RmbmDvOAlvVj5lyM5WEU7f8476zGSS9OlYCJK/+XRrgtC4zDur f8lJoD+n/A0LDs6tKBtbnWsaH8PyRbPwxfhGOlDgp+Ho6LAHPECk9L9I7KWIwvCrtpID B74g== X-Gm-Message-State: AOAM533BzBushx79rfI7F2h5OvKjcNx7hk0JRSkhi+6nef4q6qqqXM5/ KWMYNbt3IqQjglcjdCuZnl+gHKoiAGw= X-Google-Smtp-Source: ABdhPJzv7685A/2vLi87e72fL9yZriGxPC8P49y5NoGNZwUIGw7xDwZaNxJU2ihycGRM5A/F3b+24Q== X-Received: by 2002:adf:b74a:: with SMTP id n10mr4152215wre.140.1601037227872; Fri, 25 Sep 2020 05:33:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 9sm2680005wmf.7.2020.09.25.05.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:33:47 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Fri, 25 Sep 2020 12:33:38 +0000 Subject: [PATCH v4 8/8] maintenance: add incremental-repack auto condition Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: sandals@crustytoothpaste.net, steadmon@google.com, jrnieder@gmail.com, peff@peff.net, congdanhqx@gmail.com, phillip.wood123@gmail.com, emilyshaffer@google.com, sluongng@gmail.com, jonathantanmy@google.com, Jonathan Tan , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The incremental-repack task updates the multi-pack-index by deleting pack- files that have been replaced with new packs, then repacking a batch of small pack-files into a larger pack-file. This incremental repack is faster than rewriting all object data, but is slower than some other maintenance activities. The 'maintenance.incremental-repack.auto' config option specifies how many pack-files should exist outside of the multi-pack-index before running the step. These pack-files could be created by 'git fetch' commands or by the loose-objects task. The default value is 10. Setting the option to zero disables the task with the '--auto' option, and a negative value makes the task run every time. Signed-off-by: Derrick Stolee --- Documentation/config/maintenance.txt | 9 ++++++++ builtin/gc.c | 31 ++++++++++++++++++++++++++++ t/t7900-maintenance.sh | 28 +++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt index c31613be62..a0706d8f09 100644 --- a/Documentation/config/maintenance.txt +++ b/Documentation/config/maintenance.txt @@ -23,3 +23,12 @@ maintenance.loose-objects.auto:: positive value implies the command should run when the number of loose objects is at least the value of `maintenance.loose-objects.auto`. The default value is 100. + +maintenance.incremental-repack.auto:: + This integer config option controls how often the `incremental-repack` + task should be run as part of `git maintenance run --auto`. If zero, + then the `incremental-repack` task will not run with the `--auto` + option. A negative value will force the task to run every time. + Otherwise, a positive value implies the command should run when the + number of pack-files not in the multi-pack-index is at least the value + of `maintenance.incremental-repack.auto`. The default value is 10. diff --git a/builtin/gc.c b/builtin/gc.c index 8d22361fa9..2b99596ec8 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -30,6 +30,7 @@ #include "promisor-remote.h" #include "refs.h" #include "remote.h" +#include "object-store.h" #define FAILED_RUN "failed to run %s" @@ -1001,6 +1002,35 @@ static int maintenance_task_loose_objects(struct maintenance_run_opts *opts) return prune_packed(opts) || pack_loose(opts); } +static int incremental_repack_auto_condition(void) +{ + struct packed_git *p; + int enabled; + int incremental_repack_auto_limit = 10; + int count = 0; + + if (git_config_get_bool("core.multiPackIndex", &enabled) || + !enabled) + return 0; + + git_config_get_int("maintenance.incremental-repack.auto", + &incremental_repack_auto_limit); + + if (!incremental_repack_auto_limit) + return 0; + if (incremental_repack_auto_limit < 0) + return 1; + + for (p = get_packed_git(the_repository); + count < incremental_repack_auto_limit && p; + p = p->next) { + if (!p->multi_pack_index) + count++; + } + + return count >= incremental_repack_auto_limit; +} + static int multi_pack_index_write(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; @@ -1156,6 +1186,7 @@ static struct maintenance_task tasks[] = { [TASK_INCREMENTAL_REPACK] = { "incremental-repack", maintenance_task_incremental_repack, + incremental_repack_auto_condition, }, [TASK_GC] = { "gc", diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 9e6ea23f35..55116c2f04 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -219,4 +219,32 @@ test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' --no-progress --batch-size=2147483647 /dev/null && + test_subcommand ! git multi-pack-index write --no-progress /dev/null && + test_subcommand ! git multi-pack-index write --no-progress /dev/null && + test_subcommand git multi-pack-index write --no-progress