]> granicus.if.org Git - imagemagick/commitdiff
Align small memory allocations on the cache line
authorCristy <urban-warrior@imagemagick.org>
Tue, 4 Apr 2017 11:51:41 +0000 (07:51 -0400)
committerCristy <urban-warrior@imagemagick.org>
Tue, 4 Apr 2017 11:51:41 +0000 (07:51 -0400)
MagickCore/memory.c

index 318f7274f6e2bf83949ce4b3bddb4e86ba931c6a..985ab26a3bfd42689a33b428aaaa47eb7c0c9405 100644 (file)
@@ -220,7 +220,7 @@ static MagickBooleanType
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  AcquireAlignedMemory() returns a pointer to a block of memory at least size
-%  bytes whose address is aligned on a page boundary.
+%  bytes whose address is aligned on a cache line or page boundary.
 %
 %  The format of the AcquireAlignedMemory method is:
 %
@@ -249,8 +249,10 @@ MagickExport void *AcquireAlignedMemory(const size_t count,const size_t quantum)
   if (HeapOverflowSanityCheck(count,quantum) != MagickFalse)
     return((void *) NULL);
   memory=NULL;
-  alignment=GetMagickPageSize();
   size=count*quantum;
+  alignment=CACHE_LINE_SIZE;
+  if (size > (GetMagickPageSize() >> 1))
+    alignment=GetMagickPageSize();
   extent=AlignedExtent(size,CACHE_LINE_SIZE);
   if ((size == 0) || (extent < size))
     return((void *) NULL);