From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6425 invoked by alias); 9 Aug 2007 23:42:30 -0000 Received: (qmail 6121 invoked by uid 22791); 9 Aug 2007 23:42:28 -0000 X-Spam-Check-By: sourceware.org Received: from hq.tensilica.com (HELO mailapp.tensilica.com) (65.205.227.29) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 09 Aug 2007 23:42:25 +0000 Received: from localhost ([127.0.0.1]) by mailapp.tensilica.com with esmtp (Exim 4.34) id 1IJHe3-00010K-OH for gdb-patches@sources.redhat.com; Thu, 09 Aug 2007 16:42:23 -0700 Received: from mailapp.tensilica.com ([127.0.0.1]) by localhost (mailapp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00672-08 for ; Thu, 9 Aug 2007 16:42:23 -0700 (PDT) Received: from maxim_fc5.hq.tensilica.com ([192.168.11.68]) by mailapp.tensilica.com with esmtp (Exim 4.34) id 1IJHe3-00010E-Bn for gdb-patches@sources.redhat.com; Thu, 09 Aug 2007 16:42:23 -0700 Message-ID: <46BBA65F.7040106@hq.tensilica.com> Date: Thu, 09 Aug 2007 23:42:00 -0000 From: Maxim Grigoriev User-Agent: Thunderbird 1.5.0.9 (X11/20070102) MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [PATCH] Remote FILEIO: newly allocated file descriptors have to be initialized. Content-Type: multipart/mixed; boundary="------------080605080501000402090903" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-08/txt/msg00195.txt.bz2 This is a multi-part message in MIME format. --------------080605080501000402090903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1310 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 #include 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 --------------080605080501000402090903 Content-Type: text/x-patch; name="remote_fileio_resize_fd_map.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="remote_fileio_resize_fd_map.diff" Content-length: 938 2007-08-09 Maxim Grigoriev * 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; } --------------080605080501000402090903--