* [PATCH 0/2] packfile: small syscall reductions @ 2019-12-26 10:42 Eric Wong 2019-12-26 10:42 ` [PATCH 1/2] packfile: remove redundant fcntl F_GETFD/F_SETFD Eric Wong 2019-12-26 10:42 ` [PATCH 2/2] packfile: replace lseek+read with pread Eric Wong 0 siblings, 2 replies; 6+ messages in thread From: Eric Wong @ 2019-12-26 10:42 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Being an avid user of strace, redundant syscalls clutter up the output and bother me, so I removed some. Folks with CPU mitigations enabled might also benefit from fewer syscalls. Eric Wong (2): packfile: remove redundant fcntl F_GETFD/F_SETFD packfile: replace lseek+read with pread packfile.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] packfile: remove redundant fcntl F_GETFD/F_SETFD 2019-12-26 10:42 [PATCH 0/2] packfile: small syscall reductions Eric Wong @ 2019-12-26 10:42 ` Eric Wong 2019-12-26 10:42 ` [PATCH 2/2] packfile: replace lseek+read with pread Eric Wong 1 sibling, 0 replies; 6+ messages in thread From: Eric Wong @ 2019-12-26 10:42 UTC (permalink / raw) To: Junio C Hamano; +Cc: git git_open sets close-on-exec since cd66ada06588f797 ("sha1_file: open window into packfiles with O_CLOEXEC"). There's no reason to keep using fcntl to set the close-on-exec flag, anymore. Signed-off-by: Eric Wong <e@80x24.org> --- packfile.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packfile.c b/packfile.c index f0dc63e92f..1821cb7a3d 100644 --- a/packfile.c +++ b/packfile.c @@ -510,7 +510,6 @@ static int open_packed_git_1(struct packed_git *p) struct pack_header hdr; unsigned char hash[GIT_MAX_RAWSZ]; unsigned char *idx_hash; - long fd_flag; ssize_t read_result; const unsigned hashsz = the_hash_algo->rawsz; @@ -554,16 +553,6 @@ static int open_packed_git_1(struct packed_git *p) } else if (p->pack_size != st.st_size) return error("packfile %s size changed", p->pack_name); - /* We leave these file descriptors open with sliding mmap; - * there is no point keeping them open across exec(), though. - */ - fd_flag = fcntl(p->pack_fd, F_GETFD, 0); - if (fd_flag < 0) - return error("cannot determine file descriptor flags"); - fd_flag |= FD_CLOEXEC; - if (fcntl(p->pack_fd, F_SETFD, fd_flag) == -1) - return error("cannot set FD_CLOEXEC"); - /* Verify we recognize this pack file format. */ read_result = read_in_full(p->pack_fd, &hdr, sizeof(hdr)); if (read_result < 0) ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] packfile: replace lseek+read with pread 2019-12-26 10:42 [PATCH 0/2] packfile: small syscall reductions Eric Wong 2019-12-26 10:42 ` [PATCH 1/2] packfile: remove redundant fcntl F_GETFD/F_SETFD Eric Wong @ 2019-12-26 10:42 ` Eric Wong 2019-12-26 18:23 ` Junio C Hamano 1 sibling, 1 reply; 6+ messages in thread From: Eric Wong @ 2019-12-26 10:42 UTC (permalink / raw) To: Junio C Hamano; +Cc: git We already have pread emulation for portability, so there's there's no reason to make two syscalls where one suffices. Furthermore, readers of the packfile will be using mmap (or pread to emulate mmap), anyways, so the file description offset does not matter in this case. Signed-off-by: Eric Wong <e@80x24.org> --- packfile.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packfile.c b/packfile.c index 1821cb7a3d..7e7c04e4d8 100644 --- a/packfile.c +++ b/packfile.c @@ -576,9 +576,8 @@ static int open_packed_git_1(struct packed_git *p) " while index indicates %"PRIu32" objects", p->pack_name, ntohl(hdr.hdr_entries), p->num_objects); - if (lseek(p->pack_fd, p->pack_size - hashsz, SEEK_SET) == -1) - return error("end of packfile %s is unavailable", p->pack_name); - read_result = read_in_full(p->pack_fd, hash, hashsz); + read_result = pread_in_full(p->pack_fd, hash, hashsz, + p->pack_size - hashsz); if (read_result < 0) return error_errno("error reading from %s", p->pack_name); if (read_result != hashsz) ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] packfile: replace lseek+read with pread 2019-12-26 10:42 ` [PATCH 2/2] packfile: replace lseek+read with pread Eric Wong @ 2019-12-26 18:23 ` Junio C Hamano 2019-12-26 18:32 ` Junio C Hamano 2019-12-26 18:59 ` Eric Wong 0 siblings, 2 replies; 6+ messages in thread From: Junio C Hamano @ 2019-12-26 18:23 UTC (permalink / raw) To: Eric Wong; +Cc: git Eric Wong <e@80x24.org> writes: > We already have pread emulation for portability, so there's > there's no reason to make two syscalls where one suffices. > > Furthermore, readers of the packfile will be using mmap > (or pread to emulate mmap), anyways, so the file description > offset does not matter in this case. s/description/descriptor/ probably. After seeking to the packfile trailer and reading the pack id hash using lseek+read, this helper function does not read from the file descriptor, and the sole caller of it closes the file descriptor immediately after it returns, which means the read file offset after reading the packfile trailer does not matter. So this conversion is correct. Thanks for a careful analysis. Will queue both patches. > Signed-off-by: Eric Wong <e@80x24.org> > --- > packfile.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/packfile.c b/packfile.c > index 1821cb7a3d..7e7c04e4d8 100644 > --- a/packfile.c > +++ b/packfile.c > @@ -576,9 +576,8 @@ static int open_packed_git_1(struct packed_git *p) > " while index indicates %"PRIu32" objects", > p->pack_name, ntohl(hdr.hdr_entries), > p->num_objects); > - if (lseek(p->pack_fd, p->pack_size - hashsz, SEEK_SET) == -1) > - return error("end of packfile %s is unavailable", p->pack_name); > - read_result = read_in_full(p->pack_fd, hash, hashsz); > + read_result = pread_in_full(p->pack_fd, hash, hashsz, > + p->pack_size - hashsz); > if (read_result < 0) > return error_errno("error reading from %s", p->pack_name); > if (read_result != hashsz) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] packfile: replace lseek+read with pread 2019-12-26 18:23 ` Junio C Hamano @ 2019-12-26 18:32 ` Junio C Hamano 2019-12-26 18:59 ` Eric Wong 1 sibling, 0 replies; 6+ messages in thread From: Junio C Hamano @ 2019-12-26 18:32 UTC (permalink / raw) To: Eric Wong; +Cc: git Junio C Hamano <gitster@pobox.com> writes: > Eric Wong <e@80x24.org> writes: > >> We already have pread emulation for portability, so there's >> there's no reason to make two syscalls where one suffices. >> >> Furthermore, readers of the packfile will be using mmap >> (or pread to emulate mmap), anyways, so the file description >> offset does not matter in this case. > > s/description/descriptor/ probably. > > After seeking to the packfile trailer and reading the pack id hash > using lseek+read, this helper function does not read from the file > descriptor, and the sole caller of it closes the file descriptor > immediately after it returns, which means the read file offset after > reading the packfile trailer does not matter. Oops, that was not right. When we successfully open the packfile, we leave the file descriptor open, so we do need the "we never read using read(2) from the file descriptor" guarantee for this change to be correct. But we do have the guarantee, and existing code does depend on the guarantee, so the patch is good. Thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] packfile: replace lseek+read with pread 2019-12-26 18:23 ` Junio C Hamano 2019-12-26 18:32 ` Junio C Hamano @ 2019-12-26 18:59 ` Eric Wong 1 sibling, 0 replies; 6+ messages in thread From: Eric Wong @ 2019-12-26 18:59 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Junio C Hamano <gitster@pobox.com> wrote: > Eric Wong <e@80x24.org> writes: > > > > Furthermore, readers of the packfile will be using mmap > > (or pread to emulate mmap), anyways, so the file description > > offset does not matter in this case. > > s/description/descriptor/ probably. No, I meant "description" :) The offset is shared in case of dup{,2,3} syscalls, which only creates a new descriptor, not a new description. Both the Linux and POSIX lseek(2) manpages say "description". ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-12-26 18:59 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-12-26 10:42 [PATCH 0/2] packfile: small syscall reductions Eric Wong 2019-12-26 10:42 ` [PATCH 1/2] packfile: remove redundant fcntl F_GETFD/F_SETFD Eric Wong 2019-12-26 10:42 ` [PATCH 2/2] packfile: replace lseek+read with pread Eric Wong 2019-12-26 18:23 ` Junio C Hamano 2019-12-26 18:32 ` Junio C Hamano 2019-12-26 18:59 ` Eric Wong
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git 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 read-only IMAP folder(s) and NNTP newsgroup(s).