1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

* allocatestack.c (queue_stack): Move freeing of surplus stacks to...

(free_stacks): ...here.
	(__free_stack_cache): New function.
	* pthreadP.h: Declare __free_stack_cache.
	* sysdeps/pthread/pthread-functions.h (pthread_functions): Add
	ptr_freeres.
	* init.c (pthread_functions): Initialize ptr_freeres.
	* sysdeps/unix/sysv/linux/libc_pthread_init.c (freeres_libptread):
	New freeres function.
This commit is contained in:
Ulrich Drepper
2006-08-23 17:47:19 +00:00
parent 9a464a6eff
commit ba408f8465
6 changed files with 72 additions and 35 deletions

View File

@ -1,3 +1,15 @@
2006-08-23 Ulrich Drepper <drepper@redhat.com>
* allocatestack.c (queue_stack): Move freeing of surplus stacks to...
(free_stacks): ...here.
(__free_stack_cache): New function.
* pthreadP.h: Declare __free_stack_cache.
* sysdeps/pthread/pthread-functions.h (pthread_functions): Add
ptr_freeres.
* init.c (pthread_functions): Initialize ptr_freeres.
* sysdeps/unix/sysv/linux/libc_pthread_init.c (freeres_libptread):
New freeres function.
2006-07-30 Joseph S. Myers <joseph@codesourcery.com> 2006-07-30 Joseph S. Myers <joseph@codesourcery.com>
[BZ #3018] [BZ #3018]

View File

@ -211,22 +211,12 @@ get_cached_stack (size_t *sizep, void **memp)
} }
/* Add a stack frame which is not used anymore to the stack. Must be /* Free stacks until cache size is lower than LIMIT. */
called with the cache lock held. */ static void
static inline void free_stacks (size_t limit)
__attribute ((always_inline))
queue_stack (struct pthread *stack)
{ {
/* We unconditionally add the stack to the list. The memory may /* We reduce the size of the cache. Remove the last entries until
still be in use but it will not be reused until the kernel marks the size is below the limit. */
the stack as not used anymore. */
list_add (&stack->list, &stack_cache);
stack_cache_actsize += stack->stackblock_size;
if (__builtin_expect (stack_cache_actsize > stack_cache_maxsize, 0))
{
/* We reduce the size of the cache. Remove the last entries
until the size is below the limit. */
list_t *entry; list_t *entry;
list_t *prev; list_t *prev;
@ -247,17 +237,41 @@ queue_stack (struct pthread *stack)
/* Free the memory associated with the ELF TLS. */ /* Free the memory associated with the ELF TLS. */
_dl_deallocate_tls (TLS_TPADJ (curr), false); _dl_deallocate_tls (TLS_TPADJ (curr), false);
/* Remove this block. This should never fail. If it /* Remove this block. This should never fail. If it does
does something is really wrong. */ something is really wrong. */
if (munmap (curr->stackblock, curr->stackblock_size) != 0) if (munmap (curr->stackblock, curr->stackblock_size) != 0)
abort (); abort ();
/* Maybe we have freed enough. */ /* Maybe we have freed enough. */
if (stack_cache_actsize <= stack_cache_maxsize) if (stack_cache_actsize <= limit)
break; break;
} }
} }
} }
/* Add a stack frame which is not used anymore to the stack. Must be
called with the cache lock held. */
static inline void
__attribute ((always_inline))
queue_stack (struct pthread *stack)
{
/* We unconditionally add the stack to the list. The memory may
still be in use but it will not be reused until the kernel marks
the stack as not used anymore. */
list_add (&stack->list, &stack_cache);
stack_cache_actsize += stack->stackblock_size;
if (__builtin_expect (stack_cache_actsize > stack_cache_maxsize, 0))
free_stacks (stack_cache_maxsize);
}
/* This function is called indirectly from the freeres code in libc. */
void
__free_stack_cache (void)
{
free_stacks (0);
} }

View File

@ -136,7 +136,9 @@ static const struct pthread_functions pthread_functions =
.ptr_nthreads = &__nptl_nthreads, .ptr_nthreads = &__nptl_nthreads,
.ptr___pthread_unwind = &__pthread_unwind, .ptr___pthread_unwind = &__pthread_unwind,
.ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd, .ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd,
.ptr__nptl_setxid = __nptl_setxid .ptr__nptl_setxid = __nptl_setxid,
/* For now only the stack cache needs to be freed. */
.ptr_freeres = __free_stack_cache
}; };
# define ptr_pthread_functions &pthread_functions # define ptr_pthread_functions &pthread_functions
#else #else

View File

@ -543,6 +543,8 @@ extern void __nptl_deallocate_tsd (void) attribute_hidden;
extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden; extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden;
extern void __free_stack_cache (void) attribute_hidden;
#ifdef SHARED #ifdef SHARED
# define PTHREAD_STATIC_FN_REQUIRE(name) # define PTHREAD_STATIC_FN_REQUIRE(name)
#else #else

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. /* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
@ -95,6 +95,7 @@ struct pthread_functions
__attribute ((noreturn)) __cleanup_fct_attribute; __attribute ((noreturn)) __cleanup_fct_attribute;
void (*ptr__nptl_deallocate_tsd) (void); void (*ptr__nptl_deallocate_tsd) (void);
int (*ptr__nptl_setxid) (struct xid_command *); int (*ptr__nptl_setxid) (struct xid_command *);
void (*ptr_freeres) (void);
}; };
/* Variable in libc.so. */ /* Variable in libc.so. */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. /* Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@ -57,3 +57,9 @@ __libc_pthread_init (ptr, reclaim, functions)
return &__libc_multiple_threads; return &__libc_multiple_threads;
#endif #endif
} }
libc_freeres_fn (freeres_libptread)
{
__libc_pthread_functions.ptr_freeres ();
}