MAJOR: stream-interface: dynamically allocate the applet context

From now on, a call to stream_int_register_handler() causes a call
to si_alloc_appctx() and returns an initialized appctx for the
current stream interface. If one was previously allocated, it is
released. If the stream interface was attached to a connection, it
is released as well.

The appctx are allocated from the same pools as the connections, because
they're substantially smaller in size, and we can't have both a connection
and an appctx on an interface at any moment.

In case of memory shortage, the call may return NULL, which is already
handled by all consumers of stream_int_register_handler().

The field appctx was removed from the stream interface since we only
rely on the endpoint now. On 32-bit, the stream_interface size went down
from 108 to 44 bytes. On 64-bit, it went down from 144 to 64 bytes. This
represents a memory saving of 160 bytes per session.

It seems that a later improvement could be to move the call to
stream_int_register_handler() to session.c for most cases.
This commit is contained in:
Willy Tarreau
2013-12-01 11:31:38 +01:00
parent 1fbe1c9ec8
commit 0a23bcb8be
3 changed files with 97 additions and 18 deletions

View File

@@ -352,9 +352,15 @@ static void stream_int_chk_snd(struct stream_interface *si)
*/
struct appctx *stream_int_register_handler(struct stream_interface *si, struct si_applet *app)
{
struct appctx *appctx;
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner);
si_attach_applet(si, app);
appctx = si_alloc_appctx(si);
if (!si)
return NULL;
appctx_set_applet(appctx, app);
si->flags |= SI_FL_WAIT_DATA;
return si_appctx(si);
}