# [PATCH] - Improving multi-threaded scalability by using emalloc/efree/estrdup instead of malloc/free/strdup in virtual_cwd APIs

- Thread: https://externals.io/message/46070
- Original archive: https://news-web.php.net/php.internals/46070
- Started by Arvind Srinivasan on 2009-11-17T13:34:54+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #46070 — Arvind Srinivasan — 2009-11-17T13:34:54+00:00

URL: https://externals.io/message/46070#46070

Using malloc/free in a multi-threaded process limits its scalability
because of the process-wide lock inside malloc/free. The scalability
of the PHP engine in a multi-threaded process can be improved by
reducing the use of malloc/free/strdup  and instead using
emalloc/efree/estrdup wherever possible (at least in the main request
processing code paths).

The code paths in TSRM/tsrm_virtual_cwd.c are invoked quite frequently
and they use malloc/free/strdup. I'd like to submit the following
patches (based on the PHP6 source tree) for review that incorporate
the use of emalloc/efree/estrdup in the virtual_cwd code paths. In
order to use emalloc/efree I had to relocate tsrm_virtual_cwd.c from
the TSRM directory to the Zend directory. I've split the change into 3
patches in order to make the changes easy to see

Avoid name clash between global and local variable
(http://bugs.php.net/bug.php?id=50101)
http://bitbucket.org/arvi/arviq/src/tip/arvi-08-namespace

Rename TSRM/tsrm_virtual_cwd.[ch] to Zend/zend_virtual_cwd.[ch]
http://bitbucket.org/arvi/arviq/src/tip/arvi-08-virtual_cwd

Replace malloc/free/strdup with emalloc/efree/estrdup
http://bitbucket.org/arvi/arviq/src/tip/arvi-08-virtual_cwd-emalloc

Thanks,
Arvi
