[Libsysio-commit] strided-io: libsysio/src file.c fs.c init.c inode.c
Brought to you by:
lward
|
From: Lee W. <lw...@us...> - 2004-01-27 21:34:49
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2222/src Modified Files: Tag: strided-io file.c fs.c init.c inode.c Log Message: Added --with-zero-sum-memory which causes _sysio_shutdown to have various global (variable sized) tables deallocated at shutdown time. This in order to make *all* memory dynamically allocated during the run is free'd. This is really a debugging only option. These tables, normally, need not be freed. Once that was accomplished valgrind was run. No errors/leaks are reported now. Index: file.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/file.c,v retrieving revision 1.6.6.1 retrieving revision 1.6.6.2 diff -u -w -b -B -p -r1.6.6.1 -r1.6.6.2 --- file.c 23 Jan 2004 15:21:26 -0000 1.6.6.1 +++ file.c 27 Jan 2004 21:33:44 -0000 1.6.6.2 @@ -148,6 +148,16 @@ fd_grow(size_t n) return 0; } +#if ZERO_SUM_MEMORY +void +_sysio_fd_shutdown() +{ + + free(_sysio_oftab); + _sysio_oftab_size = 0; +} +#endif + /* * Find a free slot in the open files table. */ Index: fs.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/fs.c,v retrieving revision 1.8 retrieving revision 1.8.16.1 diff -u -w -b -B -p -r1.8 -r1.8.16.1 --- fs.c 24 Apr 2003 02:15:29 -0000 1.8 +++ fs.c 27 Jan 2004 21:33:44 -0000 1.8.16.1 @@ -105,6 +105,22 @@ _sysio_fssw_register(const char *name, s return 0; } +#if ZERO_SUM_MEMORY +/* + * Shutdown + */ +void +_sysio_fssw_shutdown() +{ + struct fsswent *fssw; + + while ((fssw = fsswitch.lh_first)) { + LIST_REMOVE(fssw, fssw_link); + free(fssw); + } +} +#endif + /* * Allocate and initialize a new file system record. */ Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.3.16.1 retrieving revision 1.3.16.2 diff -u -w -b -B -p -r1.3.16.1 -r1.3.16.2 --- init.c 26 Jan 2004 16:27:47 -0000 1.3.16.1 +++ init.c 27 Jan 2004 21:33:44 -0000 1.3.16.2 @@ -52,6 +52,10 @@ #include "file.h" #include "dev.h" +#if ZERO_SUM_MEMORY +#include "fs.h" +#endif + #ifdef STDFD_DEV #include "stdfd.h" #endif @@ -113,4 +117,10 @@ _sysio_shutdown() if (!(_sysio_fd_close_all() == 0 && _sysio_unmount_all() == 0)) abort(); + +#if ZERO_SUM_MEMORY + _sysio_fd_shutdown(); + _sysio_i_shutdown(); + _sysio_fssw_shutdown(); +#endif } Index: inode.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/inode.c,v retrieving revision 1.11.6.3 retrieving revision 1.11.6.4 diff -u -w -b -B -p -r1.11.6.3 -r1.11.6.4 --- inode.c 27 Jan 2004 19:42:00 -0000 1.11.6.3 +++ inode.c 27 Jan 2004 21:33:44 -0000 1.11.6.4 @@ -96,6 +96,24 @@ static size_t n_names = 0; static size_t max_names = (2 * NAMES_TABLE_LEN); /* + * Number of pnodes to grab per memory allocation when filling the + * free list. + */ +#define PNODES_PER_CHUNK ((8 * 1024) / sizeof(struct pnode) - 2) + +#if ZERO_SUM_MEMORY +/* + * Allocation information for pnodes bulk allocation. + */ +struct pnodes_block { + LIST_ENTRY(pnodes_block) pnblk_links; + struct pnode pnblk_nodes[PNODES_PER_CHUNK]; +}; + +static LIST_HEAD( ,pnodes_block) pnblocks; +#endif + +/* * List of all path-nodes (aliases) referenced by any tree. */ struct pnodes_head _sysio_pnodes; @@ -124,6 +142,9 @@ _sysio_i_init() for (i = 0; i < NAMES_TABLE_LEN; i++) LIST_INIT(&names[i]); +#if ZERO_SUM_MEMORY + LIST_INIT(&pnblocks); +#endif TAILQ_INIT(&_sysio_pnodes); LIST_INIT(&free_pnodes); @@ -439,19 +460,46 @@ static void more_pnodes() { size_t n; +#if ZERO_SUM_MEMORY + struct pnodes_block *pnblk; +#endif struct pnode *pno; - n = (8 * 1024) / sizeof(struct pnode); /* numbers! */ - assert(n); - pno = malloc(n * sizeof(struct pnode)); +#if ZERO_SUM_MEMORY + pnblk = malloc(sizeof(struct pnodes_block)); + pno = NULL; + if (pnblk) { + LIST_INSERT_HEAD(&pnblocks, pnblk, pnblk_links); + pno = pnblk->pnblk_nodes; + } +#else + pno = malloc(PNODES_PER_CHUNK * sizeof(struct pnode)); +#endif if (!pno) return; + n = PNODES_PER_CHUNK; do { LIST_INSERT_HEAD(&free_pnodes, pno, p_links); pno++; } while (--n); } +#if ZERO_SUM_MEMORY +/* + * Shutdown + */ +void +_sysio_i_shutdown() +{ + struct pnodes_block *pnblk; + + while ((pnblk = pnblocks.lh_first)) { + LIST_REMOVE(pnblk, pnblk_links); + free(pnblk); + } +} +#endif + /* * Allocate, initialize and establish appropriate links for new path (alias) * node. |