From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: Erik Faye-Lund <kusmabite@gmail.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
Ramsay Jones <ramsay@ramsay1.demon.co.uk>,
Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: What's cooking in git.git (Apr 2012, #06; Sun, 15)
Date: Sat, 21 Apr 2012 12:46:36 +0700 [thread overview]
Message-ID: <20120421054636.GA6849@do> (raw)
In-Reply-To: <20120421030018.GA32687@do>
On Sat, Apr 21, 2012 at 10:00:18AM +0700, Nguyen Thai Ngoc Duy wrote:
> > I don't know our use-cases, but I'd be a lot happier if I could find a
> > safe way to have it not update the file-pointer. Just reading it and
> > setting it back again would be racy.
>
> Replace pread() in index-pack to pread_weak() because we know we don't
> care about file offset in index-pack. Define pread_weak as pread
> normally. Windows port can provide its own pread_weak version, which
> can freely move file offset.
Or we could avoid sharing pack_fd file handle, making pread's
thread-safety irrelevant. This does not give any performance
improvements on linux (I guess linux vfs does not hold per-file
locks), so I'm not interested. If you guys want multithread index-pack
on Windows, go for it.
-- 8< --
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index c1c3c81..051325a 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -50,6 +50,7 @@ struct thread_local {
#endif
struct base_data *base_cache;
size_t base_cache_used;
+ int pack_fd;
};
/*
@@ -89,7 +90,8 @@ static off_t consumed_bytes;
static unsigned deepest_delta;
static git_SHA_CTX input_ctx;
static uint32_t input_crc32;
-static int input_fd, output_fd, pack_fd;
+static const char *curr_pack;
+static int input_fd, output_fd;
#ifndef NO_PTHREADS
@@ -126,16 +128,23 @@ static inline void unlock_mutex(pthread_mutex_t *mutex)
*/
static void init_thread(void)
{
+ int i;
init_recursive_mutex(&read_mutex);
pthread_mutex_init(&counter_mutex, NULL);
pthread_mutex_init(&work_mutex, NULL);
pthread_key_create(&key, NULL);
thread_data = xcalloc(nr_threads, sizeof(*thread_data));
+ for (i = 0; i < nr_threads; i++) {
+ thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
+ if (thread_data[i].pack_fd == -1)
+ die_errno("unable to open %s", curr_pack);
+ }
threads_active = 1;
}
static void cleanup_thread(void)
{
+ int i;
if (!threads_active)
return;
threads_active = 0;
@@ -143,6 +152,8 @@ static void cleanup_thread(void)
pthread_mutex_destroy(&counter_mutex);
pthread_mutex_destroy(&work_mutex);
pthread_key_delete(key);
+ for (i = 0; i < nr_threads; i++)
+ close(thread_data[i].pack_fd);
free(thread_data);
}
@@ -267,13 +278,13 @@ static const char *open_pack_file(const char *pack_name)
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
if (output_fd < 0)
die_errno("unable to create '%s'", pack_name);
- pack_fd = output_fd;
+ nothread_data.pack_fd = output_fd;
} else {
input_fd = open(pack_name, O_RDONLY);
if (input_fd < 0)
die_errno("cannot open packfile '%s'", pack_name);
output_fd = -1;
- pack_fd = input_fd;
+ nothread_data.pack_fd = input_fd;
}
git_SHA1_Init(&input_ctx);
return pack_name;
@@ -479,7 +490,7 @@ static void *get_data_from_pack(struct object_entry *obj)
do {
ssize_t n = (len < 64*1024) ? len : 64*1024;
- n = pread(pack_fd, inbuf, n, from);
+ n = pread(get_thread_data()->pack_fd, inbuf, n, from);
if (n < 0)
die_errno("cannot pread pack file");
if (!n)
@@ -1237,7 +1248,7 @@ static void show_pack_info(int stat_only)
int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, stat = 0;
- const char *curr_pack, *curr_index;
+ const char *curr_index;
const char *index_name = NULL, *pack_name = NULL;
const char *keep_name = NULL, *keep_msg = NULL;
char *index_name_buf = NULL, *keep_name_buf = NULL;
-- 8< --
--
Duy
prev parent reply other threads:[~2012-04-21 5:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-16 6:44 What's cooking in git.git (Apr 2012, #06; Sun, 15) Junio C Hamano
2012-04-16 9:07 ` Nelson Benitez Leon
2012-04-16 8:20 ` Junio C Hamano
2012-04-16 11:24 ` Nelson Benitez Leon
2012-04-16 15:03 ` Junio C Hamano
2012-04-18 7:15 ` Johannes Sixt
2012-04-18 19:53 ` Ramsay Jones
2012-04-19 6:16 ` Johannes Sixt
2012-04-19 6:45 ` Johannes Sixt
2012-04-19 7:02 ` Nguyen Thai Ngoc Duy
2012-04-19 9:36 ` Nguyen Thai Ngoc Duy
2012-04-19 12:58 ` Erik Faye-Lund
2012-04-19 13:18 ` Nguyen Thai Ngoc Duy
2012-04-19 13:31 ` Erik Faye-Lund
2012-04-19 13:38 ` Nguyen Thai Ngoc Duy
2012-04-19 13:48 ` Johannes Sixt
2012-04-19 13:52 ` Erik Faye-Lund
2012-04-21 3:00 ` Nguyen Thai Ngoc Duy
2012-04-21 5:46 ` Nguyen Thai Ngoc Duy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120421054636.GA6849@do \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=kusmabite@gmail.com \
--cc=ramsay@ramsay1.demon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).