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

[PATCH (experimental)] preload-index: make parallel IO configurable

From
Karsten Blees <karsten.blees@gmail.com>
Date
Jun 24, 2014, 22:54 UTC
Message-ID
<53AA01AE.8010707@gmail.com>
In-Reply-To
<53AA0129.1080109@gmail.com>

Make the amount of IO parallelism configurable (i.e. number of separate index sections to be processed in parallel).

Defining PARALLEL_IO = 20 restores approximately the IO pattern of the original preload_index() implementation. Best performance is achieved with PARALLEL_IO = 1 (i.e. sequential IO).

Signed-off-by: Karsten Blees <blees@dcon.de>
---
Applies on top of "preload-index: optimize for sequential IO".
 preload-index.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/preload-index.c b/preload-index.c
index 6ac368d..5fe5521 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -23,6 +23,7 @@ static void preload_index(struct index_state *index,
  */
 #define MAX_PARALLEL (20)
 #define THREAD_COST (500)
+#define PARALLEL_IO (1)
 
 struct thread_data {
 	pthread_t pthread;
@@ -38,23 +39,34 @@ static void *preload_thread(void *_data)
 	struct thread_data *p = _data;
 	struct index_state *index = p->index;
 	struct cache_def cache;
+	int blocks = DIV_ROUND_UP(index->cache_nr, THREAD_COST);
+	int step = DIV_ROUND_UP(blocks, PARALLEL_IO);
 
 	memset(&cache, 0, sizeof(cache));
 	for (;;) {
 		/* get next batch of entries to check */
 		pthread_mutex_lock(p->pmutex);
 		nr = *p->pnr;
-		*p->pnr += THREAD_COST;
+		(*p->pnr)++;
 		pthread_mutex_unlock(p->pmutex);
 
+		/* break loop if no more work to do */
+		if (nr >= blocks + PARALLEL_IO - 1)
+			break;
+
+		/*
+		 * rearrange iteration order, i.e. with PARALLEL_IO = 2,
+		 * [0, 1, 2, 3, 4, 5, 6, 7] becomes [0, 4, 1, 5, 2, 6, 3, 7]
+		 */
+		nr = (nr / PARALLEL_IO) + (nr % PARALLEL_IO) * step;
+		if (nr >= blocks)
+			continue;
+		nr *= THREAD_COST;
+
 		max_nr = nr + THREAD_COST;
 		if (max_nr > index->cache_nr)
 			max_nr = index->cache_nr;
 
-		/* break loop if no more work to do */
-		if (nr >= max_nr)
-			break;
-
 		for (; nr < max_nr; nr++) {
 			struct cache_entry *ce = index->cache[nr];
 			struct stat st;
-- 
1.9.4.msysgit.0.1.gc8a51b4
Previous: Karsten BleesNext: Karsten Blees
Message 3 of 9 in “Git-status / preload_index() performance”
  1. Karsten BleesJun 24, 2014
  2. preload-index: optimize for sequential IOKarsten Blees, Jun 24, 2014
  3. preload-index: make parallel IO configurableKarsten Blees, Jun 24, 2014
  4. test git-status performanceKarsten Blees, Jun 24, 2014
  5. Duy NguyenJun 26, 2014
  6. Duy NguyenJul 26, 2014
  7. Duy NguyenJul 26, 2014
  8. David TurnerJun 24, 2014
  9. Karsten BleesJun 24, 2014

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.