Skip to content

ext/session: start to implement GH-14019#17575

Open
devnexen wants to merge 5 commits intophp:masterfrom
devnexen:session_mem_rewrite
Open

ext/session: start to implement GH-14019#17575
devnexen wants to merge 5 commits intophp:masterfrom
devnexen:session_mem_rewrite

Conversation

@devnexen
Copy link
Copy Markdown
Member

No description provided.

@NattyNarwhal
Copy link
Copy Markdown
Member

Stupid question: why glib? Could we get away with using the internals HashTable with shared memory?

@devnexen
Copy link
Copy Markdown
Member Author

the glib hashtable implementation is multiplatform, solid and fast so it lessen the burden of implementation.

@devnexen devnexen force-pushed the session_mem_rewrite branch from f8bd3cf to d4c9c26 Compare January 4, 2026 08:05
@devnexen devnexen marked this pull request as ready for review January 4, 2026 08:28
@devnexen devnexen requested a review from Girgias as a code owner January 4, 2026 08:28
Copy link
Copy Markdown
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable, but I'm not a ZTS specialist, I would like @arnaud-lb opinion on the ZTS aspect. :)

Comment thread ext/session/mod_mm.c Outdated
@@ -270,7 +180,7 @@ PHP_MINIT_FUNCTION(ps_mm)
char *ps_mm_path, euid[30];
zend_result ret;

ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1);
ps_mm_instance = calloc(1, sizeof(*ps_mm_instance));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be ecalloc() or must it be the system malloc?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm not sure we can use zendmm that early but I ll try later

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be a persistent allocator (system one or pecalloc(..., true))

@Girgias Girgias requested a review from arnaud-lb January 9, 2026 00:37
Comment thread ext/session/mod_mm.c
@@ -16,10 +16,10 @@

#include "php.h"

#ifdef HAVE_LIBMM
#ifdef HAVE_LIBGLIB
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need similar changes in ext/session/session.c, otherwise mod_mm is not enabled.

Comment thread ext/session/mod_mm.c Outdated
static zend_result ps_mm_initialize(ps_mm *data, const char *path)
{
data->owner = getpid();
data->mm = mm_create(0, path);
data->mm = g_mapped_file_new(path, TRUE, NULL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on my machine when path doesn't exist

Comment thread ext/session/mod_mm.c Outdated
if (!data->mm) {
return FAILURE;
}

data->hash_cnt = 0;
data->hash_max = 511;
data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *));
data->hash = g_hash_table_new(ps_mm_hash, ps_mm_key_equals);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with glib, does the call to g_mapped_file_new() above imply that every g_ function will use that mapped file for allocation?

@arnaud-lb
Copy link
Copy Markdown
Member

The approach for ZTS supports seems fine, but I don't understand how this is using shared memory. Could you clarify @devnexen?

@devnexen
Copy link
Copy Markdown
Member Author

devnexen commented Jan 9, 2026

I think I may have been "extra zealous" regarding ZTS but I ll look after your remarks sometime this week end

@devnexen devnexen force-pushed the session_mem_rewrite branch from bde5ddf to d29d438 Compare January 10, 2026 15:47
@jorgsowa
Copy link
Copy Markdown
Contributor

Is there a chance it may land in PHP 8.6? libmm is very outdated. Also it needs rebase, because mod_mm.c file has been changed.

@devnexen devnexen force-pushed the session_mem_rewrite branch from d29d438 to bdbc671 Compare April 14, 2026 19:07
@devnexen devnexen marked this pull request as draft April 14, 2026 19:24
@devnexen
Copy link
Copy Markdown
Member Author

Is there a chance it may land in PHP 8.6? libmm is very outdated. Also it needs rebase, because mod_mm.c file has been changed.

Since you re into the session extension, I added a TODO as a possible follow-up if you re interested.

@devnexen devnexen marked this pull request as ready for review April 14, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants