Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1CE6D200C21 for ; Mon, 20 Feb 2017 15:51:22 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1B7E5160B73; Mon, 20 Feb 2017 14:51:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4F40C160B62 for ; Mon, 20 Feb 2017 15:51:21 +0100 (CET) Received: (qmail 29216 invoked by uid 500); 20 Feb 2017 14:51:19 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 29112 invoked by uid 99); 20 Feb 2017 14:51:19 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Feb 2017 14:51:19 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id D261BC0258 for ; Mon, 20 Feb 2017 14:51:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.1 X-Spam-Level: X-Spam-Status: No, score=-3.1 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RP_MATCHES_RCVD=-2.999, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=greenbytes.de header.b=GtHmDVo9; dkim=pass (1024-bit key) header.d=greenbytes.de header.b=f6Ym8f7o Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id qc1-CRiRw2_i for ; Mon, 20 Feb 2017 14:51:17 +0000 (UTC) Received: from mail.greenbytes.de (mail.greenbytes.de [5.10.171.186]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 22BE55F4A8 for ; Mon, 20 Feb 2017 14:51:17 +0000 (UTC) Received: by mail.greenbytes.de (Postfix, from userid 117) id 5E37A15A33F4; Mon, 20 Feb 2017 15:51:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=greenbytes.de; s=mail; t=1487602272; bh=rd8mGPQrcF3+ZOWH4XHr76fuwhSMq8JLGk/k79p6MfY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=GtHmDVo97uQL0PnIe441J2ct9NxQgj72hTEK4nV0dKVbuPnBzSd+YxRfu/DKinucV dguVN0OO9ljs4DLcPyRbod5DarVpIPm8RiX0/k+nGxmhH8mymfawcXVaJ/lWhvQ/o/ a0LEZTvXlOHDRfebJPqS5veNJQtyQEfcrEFIJe14= Received: from delight.greenbytes.de (unknown [192.168.1.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.greenbytes.de (Postfix) with ESMTPSA id 6242215A0470; Mon, 20 Feb 2017 15:51:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=greenbytes.de; s=mail; t=1487602271; bh=rd8mGPQrcF3+ZOWH4XHr76fuwhSMq8JLGk/k79p6MfY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=f6Ym8f7oML5GWOeX1zIfcr9SQ9H/2IaSp6tJ9MGAQQ+S8fbloVZHWBCqOfEFdAtG+ ccKTvEUxPofUVQNsW7zc5H7vyBbvlCH3zfkUK3tCnzJE6Y60xpIoc+dUstKDPj0YyT ax0Iv4feK8dHxcNR/WxJ6xZtC/dgQOvZyv7yOcbY= Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: Re: svn commit: r1783755 - /httpd/httpd/trunk/server/mpm/event/event.c From: Stefan Eissing In-Reply-To: Date: Mon, 20 Feb 2017 15:51:41 +0100 Cc: APR Developer List Content-Transfer-Encoding: quoted-printable Message-Id: <30337B28-34C6-4C65-A60F-2BB2C6BBA63F@greenbytes.de> References: <20170220133804.A904B3A00A3@svn01-us-west.apache.org> To: dev@httpd.apache.org X-Mailer: Apple Mail (2.3259) archived-at: Mon, 20 Feb 2017 14:51:22 -0000 > Am 20.02.2017 um 15:16 schrieb Jim Jagielski : >=20 > The below got me thinking... >=20 > Right now, the pool allocator mutex is only used when, well, > allocator_alloc() is called, which means that sometimes > apr_palloc(), for example, can be thread-safeish and sometimes > not, depending on whether or not the active node has enough > space. >=20 > For 1.6 and later, it might be nice to actually protect the > adjustment of the active node, et.al. to, if a mutex is present, > always be thread-safe... that is, always when we "alloc" memory, > even when/if we do/don't called allocator_alloc(). >=20 > Thoughts? So, apr_p*alloc() calls would be thread-safe if a mutex is set in the underlying allocator? Hmm, at what cost? would be my question. In regard to thread safety of apr_allocator, there is still something I do not understand. Observations: 1. When I remove the own allocator in h2_mplx, so it inherits the now protected one from the master connection, all runs fine. 2. When I remove the own allocator from the slave connections also, in h2_conn, so that slave conns also use the protected allocator from the master conn, things break. E.g. strange behaviour up to crashes under load. Which indicates that I have not fully understood the contract of these things, or there is a hidden assumptions in regard to conn_rec->pool. hidden to me, at least. Can someone shed light on this? >=20 >> On Feb 20, 2017, at 8:38 AM, ylavic@apache.org wrote: >>=20 >> Author: ylavic >> Date: Mon Feb 20 13:38:03 2017 >> New Revision: 1783755 >>=20 >> URL: http://svn.apache.org/viewvc?rev=3D1783755&view=3Drev >> Log: >> mpm_event: use a mutex for ptrans' allocator to be safe with = concurrent >> creation and destruction of its subpools, like with mod_http2. >>=20 >>=20 >> Modified: >> httpd/httpd/trunk/server/mpm/event/event.c >>=20 >> Modified: httpd/httpd/trunk/server/mpm/event/event.c >> URL: = http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/event/event.c?re= v=3D1783755&r1=3D1783754&r2=3D1783755&view=3Ddiff >> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D >> --- httpd/httpd/trunk/server/mpm/event/event.c (original) >> +++ httpd/httpd/trunk/server/mpm/event/event.c Mon Feb 20 13:38:03 = 2017 >> @@ -2096,6 +2096,7 @@ static void * APR_THREAD_FUNC listener_t >> } >> if (!listeners_disabled) { >> void *csd =3D NULL; >> + apr_thread_mutex_t *mutex; >> ap_listen_rec *lr =3D (ap_listen_rec *) pt->baton; >> apr_pool_t *ptrans; /* Pool for = per-transaction stuff */ >> ap_pop_pool(&ptrans, worker_queue_info); >> @@ -2105,20 +2106,44 @@ static void * APR_THREAD_FUNC listener_t >> apr_allocator_t *allocator; >>=20 >> apr_allocator_create(&allocator); >> - apr_allocator_max_free_set(allocator, >> - ap_max_mem_free); >> + apr_allocator_max_free_set(allocator, = ap_max_mem_free); >> apr_pool_create_ex(&ptrans, pconf, NULL, = allocator); >> - apr_allocator_owner_set(allocator, ptrans); >> if (ptrans =3D=3D NULL) { >> ap_log_error(APLOG_MARK, APLOG_CRIT, rc, >> ap_server_conf, = APLOGNO(03097) >> "Failed to create transaction = pool"); >> + apr_allocator_destroy(allocator); >> signal_threads(ST_GRACEFUL); >> return NULL; >> } >> + apr_allocator_owner_set(allocator, ptrans); >> } >> apr_pool_tag(ptrans, "transaction"); >>=20 >> + /* We need a mutex in the allocator to = synchronize ptrans' >> + * children creations/destructions, but this = mutex ought to >> + * live in ptrans itself to avoid leaks, hence = it's cleared >> + * in ap_push_pool(). We could recycle some = pconf's mutexes >> + * like we do for ptrans subpools, but that'd = need another >> + * synchronization mechanism, whereas creating a = pthread >> + * mutex (unix here!) is really as simple/fast = as a static >> + * PTHREAD_MUTEX_INIT assignment, so let's not = bother and >> + * create the mutex for each ptrans (recycled or = not). >> + */ >> + rc =3D apr_thread_mutex_create(&mutex, >> + = APR_THREAD_MUTEX_DEFAULT, >> + ptrans); >> + if (rc !=3D APR_SUCCESS) { >> + ap_log_error(APLOG_MARK, APLOG_CRIT, rc, >> + ap_server_conf, APLOGNO() >> + "Failed to create transaction = pool mutex"); >> + ap_push_pool(worker_queue_info, ptrans); >> + signal_threads(ST_GRACEFUL); >> + return NULL; >> + } >> + = apr_allocator_mutex_set(apr_pool_allocator_get(ptrans), >> + mutex); >> + >> get_worker(&have_idle_worker, 1, = &workers_were_busy); >> rc =3D lr->accept_func(&csd, lr, ptrans); >>=20 >>=20 >>=20 >=20 Stefan Eissing bytes GmbH Hafenstrasse 16 48155 M=C3=BCnster www.greenbytes.de