#1 2010-11-23 09:16:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

SynScaleMM - fast scaling memory manager for Delphi

We just released a new unit to the source code repository.

It's a simple, small and compact MM, built on top of the main Memory Manager(FastMM4 is a good candidate, standard since Delphi 2007), architectured in order to scale on multi core CPU's (which is what FastMM4 is lacking).

Original code is ScaleMM - Fast scaling memory manager for Delphi by André Mussche.

Modifications/fork to SynScaleMM:
  - Based on http://code.google.com/p/scalemm r8 revision, from Nov 19, 2010;
  - Compiles from Delphi 6 up to Delphi XE;
  - Some pascal code converted to faster asm;
  - Some code refactoring, a lot of comments added;
  - Added (experimental) medium block handling from 2048 bytes up to 16384;
  - Released under MPL 1.1/GPL 2.0/LGPL 2.1 tri-license.

See http://synopse.info/forum/viewtopic.php?pid=771#p771

Offline

#2 2010-12-03 10:10:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

Refreshed version of SynScaleMM.

Now could be used on production.
Scales very well on multi-core CPUs, with thread-intensive real applications (like servers).

See this picture (taken from ScaleMM site in google code):
FastMM4|TopMM|SynScaleMM&chdlp=b&chls=2,4,1|1|1&chma=5,0,5,25&chtt=Scaling+comparison&nonsense=something_that_ends_with.png

In this graph, horizontal scale is the number of threads, and vertical scale is the execution time (the lower, the better).

Offline

#3 2010-12-04 15:36:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

In another benchmark:

chart?chxl=1:|Borland+MM|FastMM4|ScaleMM+1|ScaleMM+2&chxr=0,0,34000|1,5,100&chxt=y,x&chbh=a&chs=480x225&cht=bvg&chco=A2C180,3D7930,FF9900&chds=-5,34000,0,34000,0,34000&chd=t:18000,15000,32000,34000|0,6000,0,19400|0,3400,0,13000&chdl=Delphi+7+Enhanced+RTL|Delphi+2007|Delphi+2010&chtt=Delphi+Memory+Manager+scaling

Graph groups are the following:
1. Borland's MM (only for Delphi 7);
2. FastMM4;
3. SynScaleMM over Borland's MM (only for Delphi 7);
4. SynScaleMM over FastMM4.

The higher, the better.

See http://synopse.info/forum/viewtopic.php?pid=892#p892 for explanations.

Offline

#4 2010-12-04 16:54:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

To download this unit, just go to our source code repository:

http://synopse.info/fossil/finfo?name=SynScaleMM.pas

Log in as anonymous, then select the wanted version (the upper the later in the list), then click on the "Download" link topmost of the page.

Offline

#5 2010-12-06 15:43:01

visli
Member
Registered: 2010-12-06
Posts: 3

Re: SynScaleMM - fast scaling memory manager for Delphi

Need memory leaks report function.

Offline

#6 2010-12-06 16:47:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

visli wrote:

Need memory leaks report function.

That's a good observation.
If you need memory leak reporting and debugging, use FastMM4 in FullDebugMode, with the external library.

Then, when your application has no memory leak, just include the SynScaleMM in your .dpr uses clause, and check about speed enhancements in multi-thread.

Even FastMM4 has in fact two part of code: one optimized for production (written mostly in asm), one slower but more complete for debugging and memory leak reporting.

I don't want to reinvent the wheel, so FastMM4 memory leak reporting sounds perfect to me, and there is no plan to add such a feature to SynScaleMM in the future.
wink

Offline

#7 2010-12-06 19:20:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

I've uploaded a new version of SynScaleMM.
See http://synopse.info/fossil/finfo?name=SynScaleMM.pas

It's now synchronized with r19 revision, from Dec 6, 2010, with some enhancements proper to SynScaleMM. In particular, I tried to clean 5 points of implementation against this r19 revision of ScaleMM.

For example, there is a new SPINWAITBACKOFF conditional, which is defined by default, in order to follow the Backing Off Locks with Spin-Wait Loops, as stated by Intel documentation.

Now seems working with C_ARRAYSIZE = 32... I've cleaned some Scale_Getmem() and Scale_Freemem() calls.

Offline

#8 2011-03-12 18:52:28

hpw
Member
Registered: 2011-03-10
Posts: 2

Re: SynScaleMM - fast scaling memory manager for Delphi

Hi,

I made simple benchmark test programm specialliy for FastMM4 & TBBMM using 4 threads (Delphi 2007 on dual core)...

Just using some special benches the benchmark application crashes using lastest SyncScaleMM O:(

How to drop/send this simple test bench to get ride of GPF's...

Hp

Offline

#9 2011-03-13 12:25:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

1) are you sure you put SynScaleMM as the first unit in your .dpr file?

2) you can send to me some source code by email when clicking on the "Email" button below my name, left side of every post of mine

Offline

#10 2011-03-13 15:02:40

hpw
Member
Registered: 2011-03-10
Posts: 2

Re: SynScaleMM - fast scaling memory manager for Delphi

Hi,

yes it's the only one...no FastMM4 used!

will send it...

Hp

Offline

#11 2011-03-20 09:56:01

marven
Member
Registered: 2011-03-20
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

I've created a calculation intensive application in Delphi. Previously it was running ok at a Quad core PC at about 60-70% of the max. cpu capacity.
Yesterday I've assembled a heavily overclocked I7-990x system. I was anxious to get my software running, only to find out that the performance dropped to about 16% on all 12 cores ater a minute or so......
After a bit of googling I found your memory manager, installed it and was able to get the maximum performance (100%) out of all cores, a speed improvement of 625% !!
That really made my day smile

One thing I noticed though: often when a calculation finished an access violation was triggered.
Initially I thought the overclocking made my system unstable, but it also ocurred on other systems.
Once I enabled the {$define PURE_PASCAL} compiler switch the program seems to be running stable again. Maybe there's a glitch in the assembly code?
I'll continue testing today and let you now how it works out.

Thanks again!

Offline

#12 2011-03-21 12:31:34

marven
Member
Registered: 2011-03-20
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

Update:

I've tested my system all day yesterday, and everything still seems stable. smile

Offline

#13 2011-03-21 13:22:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

What if you undefine PURE_PASCAL and SCALE_INJECT_OFFSET ?

Offline

#14 2011-04-06 13:06:33

marven
Member
Registered: 2011-03-20
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

Same result as before, the calculation becomes unstable (Access violation) in 3 of the 5 runs that I did.
While using pure pascal i did another 6 runs which all went fine

Last edited by marven (2011-04-06 13:07:24)

Offline

#15 2011-04-10 21:25:23

cstuffer
Member
Registered: 2010-07-21
Posts: 11

Re: SynScaleMM - fast scaling memory manager for Delphi

Hello,

Is there some performances degradation to define "PURE_PASCAL" ??

If yes.. is this noticable ?
(I mean in a real life application)

Thank you
Carl

Offline

#16 2011-04-11 05:51:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

PURE_PASCAL is slower than the asm version.
But if you need multi-thread scaling, it could be a safe solution.

For performance, it will depend on the application.
So use your application, take a clock, and guess what's the better for your purpose.

Offline

#17 2011-09-05 14:20:22

marven
Member
Registered: 2011-03-20
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

I've just installed the new version of Delphi (XE2) and SynscaleMM no longer seems to work.
The error reported by delphi is "SynScaleMM.pas(1736): E2010 Incompatible types: 'NativeInt' and 'Integer'"

Apparently the compiler expects a NativeInt instead of an Integer for variable aSize in  "function Scale_GetMem(aSize: Integer): Pointer;"
Is this something you can easily fix?

Offline

#18 2014-10-17 13:02:36

newage
Member
Registered: 2014-10-17
Posts: 1

Re: SynScaleMM - fast scaling memory manager for Delphi

Do you plan to fix instability issues with the latest SVN version?

Using MemoryManagerBV201 two test are failing: TManyThreadsTest and TStringThreadTest.

Offline

#19 2014-10-17 16:12:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

We do not use it in production, so we are not very inclined to spend time in this unit yet...
SynScaleMM is a Proff Of Concept, IMHO.
But we never did find any issue in our own code yet.

Perhaps the SAPMM unit is a better alternative.
See https://code.google.com/p/sapmm/

Offline

#20 2016-08-09 11:18:50

Amber
Member
Registered: 2016-08-09
Posts: 1

Re: SynScaleMM - fast scaling memory manager for Delphi

For those who need a paper written perfectly. http://bigessaywriter.com/blog/the-secr … ect-memory This blog is truly awesome. There are articles, provided by excellent writers.

Offline

#21 2017-05-06 16:36:35

enrcas
Member
Registered: 2013-06-16
Posts: 20

Re: SynScaleMM - fast scaling memory manager for Delphi

hi, i today loaed some old code and remember i used synscalemm years ago.

Is this still any advantage? I am using Delphi Berlin 10.1 right now. I think not use today?

Offline

#22 2018-01-17 02:37:17

obl918
Member
Registered: 2018-01-17
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

Starting with Delphi Tokyo 10.2.2, there is an instability with this. Seems that a change in the RTL might be the cause. With significant thread creation, there are access violations on TMonitor.Destroy and also in GetMonitor... I am wondering if anyone else is experiencing this and what might be done to resolve it. It is not very simple to experiment with changes in system.pas. :-(  Didn't have any trouble in Tokyo 10.2.1.

Offline

#23 2018-01-17 05:15:44

obl918
Member
Registered: 2018-01-17
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

Turns out this is a bug in System.pas.  I worked out the fix, but it requires rebuilding system.pas.

You might vote for the report here so they will hopefully release a hotfix. Pretty major bug for anyone using a different memory manager from GETMEM.INC.

https://quality.embarcadero.com/browse/RSP-19777

Offline

#24 2018-01-17 09:02:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

Weird bug, which shows that they don't have any regression test with external memory manager.

Or... don't use TMonitor, but explicit critical sections, for locking resources.
We never use TMonitor, since it was a bloated feature, to our understanding - and is not compatible with FPC or older versions of Delphi.

Offline

#25 2018-01-17 13:43:27

obl918
Member
Registered: 2018-01-17
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

TMonitor is being used many places in rtl now. I just did a search for TMonitor.Enter under source\rtl\sys -- there's a lot! If you use a third party memory manager and do any multi-thread code in 10.2.2, you can only avoid the bug if TMonitor.Enter is never called on a locked object...

Offline

#26 2018-01-17 14:33:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: SynScaleMM - fast scaling memory manager for Delphi

You may try to patch SysAllocMem() to call AllocMem() instead at runtime.
See the patching routines in SynCommons.pas.

Offline

#27 2018-01-17 16:55:25

obl918
Member
Registered: 2018-01-17
Posts: 4

Re: SynScaleMM - fast scaling memory manager for Delphi

Thanks. That was one approach I considered. But it looks like the changes were intended to avoid conditions where these pointers are freed after the memory manager is unregistered from system.pas, so rather than patch it at runtime to force it to go through my MM, I just recompiled system.pas to fix the bug...

Last edited by obl918 (2018-01-17 16:56:11)

Offline

Board footer

Powered by FluxBB