From: Simon Rowe Subject: [PATCH V2] xs: set read_thread stacksize Date: Thu, 31 May 2012 08:39:19 +0100 Message-ID: <2d0a29ab3f917df16804.1338449959@drall.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: simon.rowe@eu.citrix.com List-Id: xen-devel@lists.xenproject.org xs_watch() creates a thread to wake watchers using default attributes. The stacksize can be quite large (8 MB on Linux), applications that link against xenstore end up having a larger memory footprint than necessary. Signed-off-by: Simon Rowe --- Changed since v1: * remove test for _POSIX_THREAD_ATTR_STACKSIZE * use define for constant diff -r 52ffce7a036e -r 2d0a29ab3f91 tools/xenstore/xs.c --- a/tools/xenstore/xs.c Tue May 29 11:36:36 2012 +0100 +++ b/tools/xenstore/xs.c Wed May 30 13:41:07 2012 +0100 @@ -702,14 +702,29 @@ bool xs_watch(struct xs_handle *h, const struct iovec iov[2]; #ifdef USE_PTHREAD +#define READ_THREAD_STACKSIZE (16 * 1024) + /* We dynamically create a reader thread on demand. */ mutex_lock(&h->request_mutex); if (!h->read_thr_exists) { - if (pthread_create(&h->read_thr, NULL, read_thread, h) != 0) { + pthread_attr_t attr; + + if (pthread_attr_init(&attr) != 0) { + mutex_unlock(&h->request_mutex); + return false; + } + if (pthread_attr_setstacksize(&attr, READ_THREAD_STACKSIZE) != 0) { + pthread_attr_destroy(&attr); + mutex_unlock(&h->request_mutex); + return false; + } + if (pthread_create(&h->read_thr, &attr, read_thread, h) != 0) { + pthread_attr_destroy(&attr); mutex_unlock(&h->request_mutex); return false; } h->read_thr_exists = 1; + pthread_attr_destroy(&attr); } mutex_unlock(&h->request_mutex); #endif