From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH v3 3/9] read-cache: allow to keep mmap'd memory after reading Date: Mon, 28 Jul 2014 19:03:09 +0700 Message-ID: <1406548995-28549-4-git-send-email-pclouds@gmail.com> References: <1406548995-28549-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Mon Jul 28 14:04:10 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XBjez-0002vh-R6 for gcvg-git-2@plane.gmane.org; Mon, 28 Jul 2014 14:04:10 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752599AbaG1MEG convert rfc822-to-quoted-printable (ORCPT ); Mon, 28 Jul 2014 08:04:06 -0400 Received: from mail-pd0-f180.google.com ([209.85.192.180]:55560 "EHLO mail-pd0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbaG1MEE (ORCPT ); Mon, 28 Jul 2014 08:04:04 -0400 Received: by mail-pd0-f180.google.com with SMTP id y13so9828997pdi.39 for ; Mon, 28 Jul 2014 05:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=GZVt2SdrVjU7iSmUgpcKVDZ/2QTThQK4RAtA4Pp1tF0=; b=zRoAeI5tVC+KpgJ6h5KNXAoVjMxILZPlO/sac9eShtxPgu1cIbqHhFRsUGwULhBrVY i3RD/U89ywl71eYmR1SPLYNOjJqXBgIgNhtnEtXCkl02HQq62GL4e8kaMcFWu01GzWQ3 yYOQGydJXPymiUQjsv8p/nfiuU7T9mZHkUlkfYrowD1wIE4o+FsaPwtN531AZdyHm/LJ xDZORt2l5Bp9AoViAXyXmxgt6gJdQlcztpaeQDkkfWGlpTnTt6/5virLrW1PXqajfTE9 eyFUGQppYYBcatrG4EU7V/YIlMvI290oUJy0IbYK1uAf3D8heXWIYvX7XNAAKaTgyYZD Ey4w== X-Received: by 10.70.126.98 with SMTP id mx2mr27084890pdb.41.1406549043686; Mon, 28 Jul 2014 05:04:03 -0700 (PDT) Received: from lanh ([115.73.211.176]) by mx.google.com with ESMTPSA id fm8sm66172506pab.28.2014.07.28.05.04.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jul 2014 05:04:03 -0700 (PDT) Received: by lanh (sSMTP sendmail emulation); Mon, 28 Jul 2014 19:04:06 +0700 X-Mailer: git-send-email 2.1.0.rc0.66.gb9187ad In-Reply-To: <1406548995-28549-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- cache.h | 3 +++ read-cache.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index 1c84227..978e53d 100644 --- a/cache.h +++ b/cache.h @@ -306,10 +306,13 @@ struct index_state { struct split_index *split_index; struct cache_time timestamp; unsigned name_hash_initialized : 1, + keep_mmap : 1, initialized : 1; struct hashmap name_hash; struct hashmap dir_hash; unsigned char sha1[20]; + void *mmap; + size_t mmap_size; }; =20 extern struct index_state the_index; diff --git a/read-cache.c b/read-cache.c index 949270b..b679781 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1498,6 +1498,10 @@ int do_read_index(struct index_state *istate, co= nst char *path, int must_exist) mmap =3D xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, = fd, 0); if (mmap =3D=3D MAP_FAILED) die_errno("unable to map index file"); + if (istate->keep_mmap) { + istate->mmap =3D mmap; + istate->mmap_size =3D mmap_size; + } close(fd); =20 hdr =3D mmap; @@ -1550,10 +1554,12 @@ int do_read_index(struct index_state *istate, c= onst char *path, int must_exist) src_offset +=3D 8; src_offset +=3D extsize; } - munmap(mmap, mmap_size); + if (!istate->keep_mmap) + munmap(mmap, mmap_size); return istate->cache_nr; =20 unmap: + istate->mmap =3D NULL; munmap(mmap, mmap_size); die("index file corrupt"); } @@ -1579,6 +1585,7 @@ int read_index_from(struct index_state *istate, c= onst char *path) discard_index(split_index->base); else split_index->base =3D xcalloc(1, sizeof(*split_index->base)); + split_index->base->keep_mmap =3D istate->keep_mmap; ret =3D do_read_index(split_index->base, git_path("sharedindex.%s", sha1_to_hex(split_index->base_sha1)), 1); @@ -1621,6 +1628,10 @@ int discard_index(struct index_state *istate) free(istate->cache); istate->cache =3D NULL; istate->cache_alloc =3D 0; + if (istate->keep_mmap && istate->mmap) { + munmap(istate->mmap, istate->mmap_size); + istate->mmap =3D NULL; + } discard_split_index(istate); return 0; } --=20 2.1.0.rc0.66.gb9187ad