Skip to content

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented May 17, 2020

Also change one ZEND_DEBUG to PHP_DEBUG to be more consistent with the rest of the file

Another approach would be to change the #if MYSQLND_DEBUG_MEMORY to #if PHP_DEBUG which could then clean-up some other preprocessor macros which enable more behaviour if we are in a debug build.

#if ZEND_DEBUG
#if PHP_DEBUG
#else
#define __zend_orig_filename "/unknown/unknown"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this else necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this whole section needs to be dropped, thanks for pointing this out

@Girgias Girgias force-pushed the cleanup-mysqlnd-preprocessor branch from df24724 to e2ee6a6 Compare May 17, 2020 23:29
@cmb69
Copy link
Member

cmb69 commented May 18, 2020

Hmm, this has been introduced with commit 37418de, but looks somewhat unfinished. @andreyhristov?

@andreyhristov
Copy link

andreyhristov commented May 18, 2020

Why does it look unfinished (xcept for the possibility of a configure time switch)? The macro drives definition of debug functions and there is an alternative. Yes, it has been enabled for a while but it doesn't mean it can't be disabled.

{
#if MYSQLND_DEBUG_MEMORY == 1
	_mysqlnd_emalloc,
	_mysqlnd_pemalloc,
	_mysqlnd_ecalloc,
	_mysqlnd_pecalloc,
	_mysqlnd_erealloc,
	_mysqlnd_perealloc,
	_mysqlnd_efree,
	_mysqlnd_pefree,
	_mysqlnd_malloc,
	_mysqlnd_calloc,
	_mysqlnd_realloc,
	_mysqlnd_free,
	_mysqlnd_pememdup,
	_mysqlnd_pestrndup,
	_mysqlnd_pestrdup,
	_mysqlnd_sprintf,
	_mysqlnd_vsprintf,
	_mysqlnd_sprintf_free
#else
	mysqlnd_zend_mm_emalloc,
	mysqlnd_zend_mm_pemalloc,
	mysqlnd_zend_mm_ecalloc,
	mysqlnd_zend_mm_pecalloc,
	mysqlnd_zend_mm_erealloc,
	mysqlnd_zend_mm_perealloc,
	mysqlnd_zend_mm_efree,
	mysqlnd_zend_mm_pefree,
	mysqlnd_zend_mm_malloc,
	mysqlnd_zend_mm_calloc,
	mysqlnd_zend_mm_realloc,
	mysqlnd_zend_mm_free,
	mysqlnd_zend_mm_pememdup,
	mysqlnd_zend_mm_pestrndup,
	mysqlnd_zend_mm_pestrdup,
	_mysqlnd_sprintf,
	_mysqlnd_vsprintf,
	_mysqlnd_sprintf_free,
#endif
};

@nikic
Copy link
Member

nikic commented May 18, 2020

I think we'd be better off going the other way around here and dropping mnd_alloc flavors completely. Nowadays the most memory-hungry parts of mysqlnd no longer go through mnd_alloc (they're backed by zend_arena, which we don't want to parameterize over the allocator), so I think the usefulness of this functionality is pretty questionable at this point.

@andreyhristov
Copy link

It was built it to provide possibility to track and profile memory allocations. Does the zend_arena has this, I mean per extension/core to be able to track memory allocations - in look for possible leaks (C code) but also for who did what?

@nikic
Copy link
Member

nikic commented May 19, 2020

It was built it to provide possibility to track and profile memory allocations. Does the zend_arena has this, I mean per extension/core to be able to track memory allocations - in look for possible leaks (C code) but also for who did what?

No, it doesn't. My point was specifically that the largest memory allocations in mysqlnd already do not make use of this tracking functionality, so the benefit of retaining it seems somewhat dubious.

If we want to analyze memory allocation behavior, we use a memory profiler (I usually use massif).

@Girgias
Copy link
Member Author

Girgias commented May 19, 2020

I don't mind either way, but if we drop the mnd_alloc version, I'll rework this so that every call to the mysqlnd_zend_mm_* functions uses the corresponding function directly.

@nikic
Copy link
Member

nikic commented May 19, 2020

FWIW I also don't care strongly here and would be fine with just leaving the code alone entirely. It just seems like some complexity we could do without, and that nobody maintains.

We generally don't like working on mysqlnd code due to the large amount of unnecessary over-abstraction it contains, that makes all changes hard and prone to ABI breakage. Never ran into problems with the allocator functions in particular though.

@andreyhristov
Copy link

This "over-abstraction" allows software vendors to bend and change mysqlnd's behavior the way they it suits their needs.

@andreyhristov
Copy link

Also, tell the user to switch a flag or run the whole PHP binary under a profiler. Switch a flag and collect the information that can be then fed into a time series database and the health of the system can be traced, also anomaly detection is possible.

@github-actions
Copy link

github-actions bot commented Dec 6, 2022

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

@github-actions github-actions bot added the Stale label Dec 6, 2022
@github-actions github-actions bot closed this Dec 14, 2022
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.

6 participants