From: Maxim Grigoriev <maxim@tensilica.com>
To: gdb-patches@sources.redhat.com
Subject: [PATCH] Remote FILEIO: newly allocated file descriptors have to be initialized.
Date: Thu, 09 Aug 2007 23:42:00 -0000 [thread overview]
Message-ID: <46BBA65F.7040106@hq.tensilica.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]
This patch has to be approved before I can commit it.
Extra file descriptor array entries don't get initialized when increasing array size.
On the test case :
#define FILENAME "test" /* name of a file that exists */
#include <stdio.h>
#include <fcntl.h>
main()
{
int i;
printf( "Opening many files...\n" );
for (i = 0; i < 20; i++) {
int fd = open(FILENAME, O_RDONLY);
printf( "(%02d) Got fd = %d\n", i, fd);
}
}
we end up wasting more memory space than we need :
Opening many files...
(00) Got fd = 3
(01) Got fd = 4
(02) Got fd = 5
(03) Got fd = 6
(04) Got fd = 7
(05) Got fd = 8
(06) Got fd = 9
(07) Got fd = 10
(08) Got fd = 14
(09) Got fd = 19
(10) Got fd = 20
(11) Got fd = 26
(12) Got fd = 30
(13) Got fd = 40
(14) Got fd = 50
(15) Got fd = 60
(16) Got fd = 70
(17) Got fd = 80
(18) Got fd = 90
(19) Got fd = 97
With this fix, it looks better:
Opening many files...
(00) Got fd = 3
(01) Got fd = 4
(02) Got fd = 5
(03) Got fd = 6
(04) Got fd = 7
(05) Got fd = 8
(06) Got fd = 9
(07) Got fd = 10
(08) Got fd = 11
(09) Got fd = 12
(10) Got fd = 13
(11) Got fd = 14
(12) Got fd = 15
(13) Got fd = 16
(14) Got fd = 17
(15) Got fd = 18
(16) Got fd = 19
(17) Got fd = 20
(18) Got fd = 21
(19) Got fd = 22
Thanks,
-- Maxim
[-- Attachment #2: remote_fileio_resize_fd_map.diff --]
[-- Type: text/x-patch, Size: 938 bytes --]
2007-08-09 Maxim Grigoriev <maxim2405@gmail.com>
* remote-fileio.c (remote_fileio_resize_fd_map): Initialize newly
allocated file descriptors.
Index: remote-fileio.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-fileio.c,v
retrieving revision 1.24
diff -u -r1.24 remote-fileio.c
--- remote-fileio.c 5 Aug 2007 01:04:31 -0000 1.24
+++ remote-fileio.c 9 Aug 2007 23:14:43 -0000
@@ -70,12 +70,16 @@
static int
remote_fileio_resize_fd_map (void)
{
+ int i = remote_fio_data.fd_map_size;
+
if (!remote_fio_data.fd_map)
return remote_fileio_init_fd_map ();
remote_fio_data.fd_map_size += 10;
remote_fio_data.fd_map =
(int *) xrealloc (remote_fio_data.fd_map,
remote_fio_data.fd_map_size * sizeof (int));
+ for (; i < remote_fio_data.fd_map_size; i++)
+ remote_fio_data.fd_map[i] = FIO_FD_INVALID;
return remote_fio_data.fd_map_size - 10;
}
next reply other threads:[~2007-08-09 23:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-09 23:42 Maxim Grigoriev [this message]
2007-08-10 2:40 ` Daniel Jacobowitz
2007-08-10 17:56 ` [commit] " Maxim Grigoriev
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=46BBA65F.7040106@hq.tensilica.com \
--to=maxim@tensilica.com \
--cc=gdb-patches@sources.redhat.com \
/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