Bug report & possible patch: Wrong memory allocation when using BerkeleyDB in concurrent processes

When using the BerkeleyDB shared environment in parallel processes, the processes get "out of memory" error, even when there is plenty of free memory available. This results in possible database corruption.
Typical use case when this bug manifests is when BerkeleyDB is used by rpm, which is installing an rpm package into custom location, or calls another rpm instance during the installation process.
The bug seems to originate in the env/env_region.c file: (version of the file from BDB 4.7.25, although the culprit code is the same in newer versions too):
330     /*
331      * Allocate room for REGION structures plus overhead.
332      *
333      * XXX
334      * Overhead is so high because encryption passwds, replication vote
335      * arrays and the thread control block table are all stored in the
336      * base environment region.  This is a bug, at the least replication
337      * should have its own region.
338      *
339      * Allocate space for thread info blocks.  Max is only advisory,
340      * so we allocate 25% more.
341      */
342     memset(&tregion, 0, sizeof(tregion));
343     nregions = __memp_max_regions(env) + 10;
344     size = nregions * sizeof(REGION);
345     size += dbenv->passwd_len;
346     size += (dbenv->thr_max + dbenv->thr_max / 4) *
347         __env_alloc_size(sizeof(DB_THREAD_INFO));
348     size += env->thr_nbucket * __env_alloc_size(sizeof(DB_HASHTAB));
349     size += 16 * 1024;
350     tregion.size = size;
Usage from the rpm's perspective:
The line 346 calculates how much memory we need for structures DB_THREAD_INFO. We allocate structure DB_THREAD_INFO for every process calling db4 library. We don't deallocate these structures but when number of processes is greater than dbenv->thr_max then we try to reuse some structure for process that is already dead (or doesn't use db4 no longer). But we have DB_THREAD_INFOs in hash buckets and we can reuse DB_THREAD_INFO only if it is in the same hash bucket as new DB_TREAD_INFO. So line 346 should contain:
346     size += env->thr_nbucket * (dbenv->thr_max + dbenv->thr_max / 4) *
347         __env_alloc_size(sizeof(DB_THREAD_INFO));
Why we don't encounter this problem earlier? There are some magic reserves as you can see on line 349 and some other additional space is created by alligning to blocks. But if we have two processes running at the same time and these processes end up in the same hash bucket and we repeat this proces many times to fill all hash buckets with two DB_THREAD_INFOs then we have 2 * env->thr_nbucket(37) = 74 DB_THREAD_INFOs, which is much more than dbenv->thr_max(8) + dbenv->thr_max(8) / 4 = 10 and plus allocation from dbc_put, we are out of memory.
And how we will create two processes that end up in the same hash bucket. We can start one process (rpm -i) and then in scriptlet we start many processes (rpm -q ...) in loop and one of them will be in the same hash bucket as the first process (rpm -i).
I would like to know your opinion on this issue, and if the proposed fix would be acceptable.
Thanks in advance for answers.

The attached patch for db-4.7 makes two changes:
  it allows enough for each bucket to have the configured number of threads, and
  it initializes env->thr_nbuckets, which previously had not been initialized.
Please let us know how it works for you.
Regards,
Charles

Similar Messages

  • Memory allocation when using multiple instances of a static array.

    Hi,
    I have question regarding the amount of memory allocated using multiple instances of a class that has declared a static array, e.g.:
    package staticTest;
    import javacard.framework.*;
    public class StaticClass
         static byte[] staticArray;
         public StaticClass()
              staticArray = new byte[100];
    /* Another class */
    package statictest;
    import javacard.framework.*;
    public class MyApplet extends javacard.framework.Applet
         StaticClass staticLibA, staticLibB;
         public MyApplet()
              /* Here we use two instances */
              staticLibA = new StaticClass();          
              staticLibB = new StaticClass();
         public static void install(byte[] bArray, short bOffset, byte bLength)
              (new MyApplet()).register(bArray, (short)(bOffset + 1), bArray[bOffset]);
         public void process(APDU apdu)
              byte[] buf = apdu.getBuffer();
              switch(buf[ISO7816.OFFSET_INS])
    }When downloading and installing this applet on a gemXpresso 211 PKis (that has a ' Get free EEPROM memory' function) the card reports that the amount of memory is increased by a approx 100 bytes every time a new staticLibX is added in the MyApplet constructor. Is this correct? If yes, can someone explain to me how to declare a static array that only allocates memory once and are being shared by the instances.
    Best regards,
    Jonas N

    Hi!
    I have another issue about static variable. The following is my sample code:
    ========================================
    package com.Test01;
    import javacard.framework.*;
    import javacard.security.*;
    import javacardx.crypto.Cipher;
    public class Test01 extends Applet {
         OwnerPIN Pin;
         static DESKey[] keys;
    protected Test01(byte[] buffer, short offset, byte length) {     
    keys = new DESKey[4];
    length = 0;
    while (length < 4) {
         keys[length] = (DESKey)KeyBuilder.buildKey((byte)3, (short)0x80, false);
         length = (byte)(length + 1);
    public static void install(byte buffer[], short offset, byte length) {     
    new Test01(buffer, offset, length);
    ===========================================================
    If there are two instances, A and B, created in the package.
    My issue:
    1. Are keys[0]~ keys [3] kept while B is deleted?
    2. Does each instance have itsown object while "keys[length] = (DESKey)KeyBuilder.buildKey((byte)3, (short)0x80, false);"?
    3. follow item 2, if A and B share the same object, is the object kept while B is deleted?
    Thank you
    Best regards,
    kantie

  • Bug Report... Catalyst crashes when using type tool

    FC is crashing nearly everytime I use the type tool or import type from AI or PS. It happens after import when I select the text to modify. I am running FC Beta 2 and am on Mac OSX 10.6.1. (the properties panel under common blanks out (doesn't show anything ie. X:, Y: W:, H:, Etc...) right before it crashes.)

    Thought i'd post back here.. I think I have fixed the type tool issue in Catalyst. Since I am a designer by trade I had about 2500 fonts enabled on my machine... I usually dont have them all enabled but I just bought my new computer and didnt even think about it... so I disabled a good chunk, at least half, and the type tool is working fine so far.... it's only been about an hour or so since ive done it so, not sure if its 100% solution, but at least it has helped...
    Might want to check the amount of fonts you have enabled when working with catalyst... keep it to a minimum.

  • High Virtual memory usage when using Pages 2.0.2

    Hey there,
    I was just wondering whether there had been any other reports of unusually high memory usage when using Pages 2.0.2, specifically Virtual memory. I am running iWork 06 on the Mac listed below and Pages has been running really slowly recently. I checked the Activity Monitor and Pages is using hardly any Physical memory but loads of Virtual memory (so much so that the Page outs are almost as high as the Page ins (roughly 51500 page ins / 51000 page outs).
    Any known problems, solutions or comments for this problem? Thanks in advance

    I don't know if this is specifically what you're seeing, but all Cocoa applications, such as Pages, have an effectively infinite Undo. If you have any document that you've been working on for a long time without closing, that could be responsible for a large amount of memory usage.
    While it's good practice to save on a regular basis, if you're making large amounts of changes it's also a good idea to close and reopen your document every once in awhile, simply to clear the undo. I've heard of some people seeing sluggish behavior after working on a document for several days, which cleared up when the document was closed and reopened.
    Titanium PowerBook   Mac OS X (10.4.8)  

  • Memory problems when using alias channel strips (3.0.2)

    I'm having memory issues when using alias channel strips.  What is happening is I create one instance of the plugin, say Massive.  Then make a bunch of other alias on different patches.  When looking at the memory usage everytime I add and alais it increases the memory usage by an amount the same as the origional plugin.  ie. add 3 alias and you have 3 times more memory usage.  See attached photos.
    Original plugin instance ~80mb memory usage
    Adding 3 Alias channel strips.  ~330mb memory usage
    By comparison here is the usage by adding 3 brand new instance of the plugins. ~160mb memory usage
    By comparison it is using less memory by having 4 seperate instances of the plugin compared to using 3 alias's of the origional.  This doesn't make sense since the whole point of an alias is to save memory by only loading one instance of the plugin. 
    Anyone have any thoughts?
    Jon

    What's interesting is that if I, starting with a blank concert, add a Massive to a patch and then make an alias the memory is as you say. But if I make a duplicate of the inital patch and then make alias's of that the memory is lower.
    Are you seeing the same with the built-in plug-ins?

  • HT4437 Is it possible to zoom in photos when using airplay? It seems not to work at all. I can only zoom in if i use mirroring and even then i have to reconnect mirroring each time I chage an albumor even go from the photo to the album level.

    Is it possible to zoom in photos when using airplay? It seems not to work at all. I can only zoom in if i use mirroring and even then i have to reconnect mirroring each time I chage an albumor even go from the photo to the album level.

    No.
    I find it extremely frustrating that Apple does not care for such an obvious bug affecting one of the basic funcionalities of AirPlay. Unless, of course, if there's something I don't know - but I've done some research and it seems that plenty of people have same issue and no solution is settled.

  • Is it possible to eliminate Outlook 2008 when using Outlook 2011?

    Is it possible to eliminate Outlook 2008 when using Outlook 2011?

    Sure!
    I personally like AppCleaner (free), a product you could use to remove Office 2008 (I think you meant Office, not Outlook).
    AppCleaner would remove the executables and a lot of the extra stuff associated with the software.

  • Will SUBMIT report EXPORTING LIST TO MEMORY work, when Run in Background?

    You can use SUBMIT <report> EXPORTING LIST TO MEMORY, and then Call the FM LIST_FROM_MEMORY to get the Data.
    This works fine, when the Program is Run in Foreground. My question is, will it work when I Run the Program in Background? i.e. When I Run the Program in Background, will the SUBMIT Statement, Export the List to Memory? Because only then the FM LIST_FROM_MEMORY will get the Data.
    Any alternate solution to meet the same requirement will be appreciated.

    It works for me... my spool output looked like:
    11.01.2008          JC: Calling program - test list to memory                  1                                                                               
    ZLOCAL_JC_SDN_CALLING_PROGRAM                started at 12:54:29                        
    ZLOCAL_JC_SDN_CALLING_PROGRAM                call complete 12:54:30                     
    ZLOCAL_JC_SDN_CALLING_PROGRAM                started at 12:54:30                                                                               
    11.01.2008           JC: Called program - testing list to memory                                                                               
    ZLOCAL_JC_SDN_CALLED_PROGRAM                 was called at: 12:54:29                    
    for the following code:
    report zlocal_jc_sdn_calling_program.
    parameters:
      p_start(1)            type c.
    start-of-selection.
      perform testcase.
    *&      Form  testcase
    form testcase.
      data:
       lt_list              type table of abaplist.
      write: / sy-repid, 'started at', sy-uzeit.
      submit zlocal_jc_sdn_called_program
        exporting list to memory
        and return.
      write: / sy-repid, 'call complete', sy-uzeit.
      call function 'LIST_FROM_MEMORY'
        tables
          listobject = lt_list.
      write: / sy-repid, 'started at', sy-uzeit.
      call function 'WRITE_LIST'
        tables
          listobject = lt_list.
    endform.                    "testcase
    and
    report zlocal_jc_sdn_called_program.
    start-of-selection.
      write: / sy-repid, 'was called at:', sy-uzeit.

  • Bug Report ignored: Palettes do not resize when changing monitors

    So this bug was ignored during beta and it was NOT fixed in the official release of PhotoShop CS6.
    Since I don't feel like retyping the whole bug report after paying a grand for the software here is a link: http://forums.adobe.com/message/4316521
    VERY annoying if you commute with a laptop and dock with a full-size monitor for work every day!
    Any word Adobe?

    Not that Photoshop should ever allow its panels to become impossible to resize, but...
    Have you considered just setting up named workspaces for each environment, then switch them manually using the box in the upper-right of the Photoshop main window?
    Given the ability to maintain workspaces fairly directly, Adobe may not even feel this is a bug.
    -Noel

  • Memory leak when using DB_DBT_MALLOC in CDB.

    Hello!
    Recently when I'm using Berkeley DB CDB and set the value Dbt DB_DBT_MALLOC, I noticed that the app's memory keeps growing during the db.get while;
    I found that many codes on the internet use the syntax free(value.get_data()), but when I tried to free the value.get_data(), I always got an interruption error.
    It's OK when I'm using the DB_DBT_USERMEM flag. So I just get very confused about the DB_DBT_MALLOC and DB_DBT_REALLOC.
    And also, I wonder why there's no memory leak problem when we use the single thread BDB. I think BDB cannot free the value.data pointer too in single thread before the app finish using it, then why our apps don't need to free the data afterwards?
    Thanks a lot in advance!

    You should use free() to free the DBT memory allocated via DB_DBT_MALLOC. You should do that after each Db::get() operation (and of course after finishing processing/using the data), otherwise you will loose the pointer to the memory previously allocated if you happen to reuse the DBT with DB_DBT_MALLOC (the data field will point to a new memory address).
    Alternatively you could use DB_DBT_REALLOC or DB_DBT_USERMEM.
    Note that there are small structures that BDB creates in the environment regions that only get freed/cleaned when the environment is closed.
    If you suspect that there is a memory leak inside the BDB code, make sure you rebuild Berkeley DB using the following configuration options (along with the others you use) when building: enable-debug, enable-umrw. Than, run the program under a memory leak detection utility, like Valgrind (allow the application to open and close the BDB environment) and see if there are any leaks reported.
    If memory leaks are reported, then put together a small stand-alone test case program that demonstrates the leaks, and post it here.
    Regards,
    Andrei

  • Makequeues memory leak when using Lexmark Z53

    Behavior with printer switched off while connected to built-in USB port:
    Problem 1: makequeues has a memory leak, starting up with between 3 and 5 MB of RAM. This is done by connecting the printer when logged in and watching via Activity Monitor.
    Initially makequeues has sent 255 Mach messages. Every ~10.5 seconds, makequeues sends 59 more messages and gets 53 in reply. With each send/receive cycle, its RAM usage grows by 8 KB, a rate of 780 kiB/min.
    Problem 2: The process is started each time the same printer is reconnected.
    Symptoms: Disconnecting the printer doesn't let the process exit (any instance). If left alone, the memory usage cycle continues.
    The memory leak caught my attention after taking up over a half-gigabyte of RAM when I left the Mac running over night.
    Resolution:
    (1) Disconnect USB cable
    (2) Kill each instance of the process
    Results:
    (1) The process launches after reconnection of the printer with 996 KB of RAM, immediately having sent 60 Mach messages and received 56.
    (2) During this run time, the process may use less and less RAM, down to a minimum of 912.
    (3) After sending 64 more messages without replies, one every 4 seconds, the process exits after having sent a total of 120 messages.
    (4) This behavior (1 through 3) is the same for each process launched as a result of printer reconnection.
    This behavior isn't shown during Safe Mode boot - makequeues never starts up as a result of printer connection.
    PowerMac G4 QuickSilver 2001 733Mhz

    If this is meant to be a bug report, please file a bug report in the proper place. This is a user to user discussion forum.
    As to the source of running 'makequeues' (/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS /makequeues), I would look at the Lexmark software. I currently have two Epson printers connected via USB with CUPS running. I see no process 'makequeues' appearing.
    Matt

  • Need help with internal HD memory problems when using Premiere Pro?

    When using PP I keep loosing memory on my HD.
    Now this seems strange to me since I have every thing, all my video and audio files on external HDs.
    Each time I time I make a new project I end up with less space on my internal HD.
    Information related to these projects is somehow remaining on my internal HD.
    Anyone got any ideas about what I might be doing wrong?
    Dimitrije

    Premiere will slowly compile various files to help the project along, and the default place is usually your internal hard drive. Make sure your scratch disks are pointed to an external hard drive if that is what you want, also, make sure the Media Cache Files are being created on your external as well (and not the default location which is on your local drive).
    Premiere Preferences > Media
    Media Cache Files & Media Cache Database should be changed to an external disk if you don't want them created on your local disk. There are many tutorials and explanations about all of these aspects of Premiere on these forums and from other sources. Hope that helps!

  • Indesign cs5 'out of memory' error when using preflight

    I have been regulary getting an 'out of memory' error when i choose to use my bespoke preflight profile.
    I have 4gig of ram and run Indesign CS5 on OS 10.6.8.
    Does anyone know a work around?
    As soon as I select from the basic default profile, i get the beach ball from hell for 10mins, then it kindly lets me know that I am out of memory, sends a crash report to Adobe and then asks if I want to relauch. I'm stuck in a vicious circle. I must of sent my 4th crash report now and no feedback from anyone at Adobe.

    I have replaced my preferences, but still the problem persists. I have tried switching my view from typical display to fast display before i selected a profile. I thought this may give me the extra memory I needed to avoid the enevitable crash. I learnt that 2 files were indeed rgb instead of cmyk before it crashed again. So I switched them to cmyk and tried again, selected my bespoke profile, but yet again it crashed. I think the problem lies with the file, not Indesign, as i have tried the same profile on a different file and the program doesn't crash and runs as it should. So if in future I need to use said crashing file again, firstly i will need to try Peter's isolate fix method. Otherwise i'll never be able to progress to successful a pdf.

  • Memory leak when using Threads?

    I did an experiment and noticed a memory leak when I was using threads.. Here's what I did.
    ======================================
    while( true )
         Scanner sc = new Scanner(System.in);
         String answer;
         System.out.print("Press Enter to continue...");
         answer = sc.next();
         new TestThread();
    ========================================
    And TestThead is the following
    ========================================
    import java.io.*;
    import java.net.*;
    public class TestThread extends Thread
    public TestThread() { start(); }
    public void run() {  }
    =====================================
    When I open windows Task Manager, every time a new thread starts and stops, the java.exe increases the Mem Usage.. Its a memory leak!? What is going on in this situation.. If I start a thread and the it stops, and then I start a new thread, why does it use more memory?
    -Brian

    MoveScanner sc = new
    Scanner(System.in);out of the
    loop.Scanner sc = new Scanner(System.in);
    while (true) {
    That won't matter in any meaningful way.
    Every loop iteration creates a new Scanner, but it also makes a Scanner eligible for GC, so the net memory requirement of the program is constant.
    Now, of course, it's possible that the VM won't bother GCing until 64 MB worth of Scanners have been created, but we don't care about that. If we're allowing the GC 64 MB, then we don't care how it uses it or when it cleans it up.

  • Are there any memory restrictions when using Invoke-Command?

    Hi, I'm using the Invoke-PSCommandSample workbook to run a batch file inside a VM.
    The batch file inside the VM runs a Java program.
    The batch file works fine, when I run it manually in the VM.
    However, when I use the Invoke-PSCommandSample workbook to run the batch file, I get the following error:
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    errorlevel=1
    Press any key to continue . . .
    Does anybody know if there are any memory restrictions when invoking commands inside a VM via runbook?
    Thanks in advance.

    Hi Joe, I'll give some more background information. I'm doing load testing with JMeter in Azure and I want to automate the task. This is my runbook:
    workflow Invoke-JMeter {
    $Cmd = "& 'C:\Program Files (x86)\apache-jmeter-2.11\bin\jmeter-runbook.bat'"
    $Cred = Get-AutomationPSCredential -Name "[email protected]"
    Invoke-PSCommandSample -AzureSubscriptionName "mysubscription" -ServiceName "myservice" -VMName "mymachine" -VMCredentialName "myuser" -PSCommand $Cmd -AzureOrgIdCredential $Cred
    This is my batch file inside the VM:
    set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_71
    set PATH=%JAVA_HOME%\bin;%PATH%
    %COMSPEC% /c "%~dp0jmeter.bat" -n -t build-web-test-plan.jmx -l build-web-test-plan.jtl -j build-web-test-plan.log
    Initially I tried to run JMeter with "-Xms2048m -Xmx2048m". As that didn't work, I lowered the memory allocation but even with "-Xms128m -Xmx128m" it does not work. I have tried with local PowerShell ISE as you suggested, but I'm
    running into certification issues. I'm currently have a look at this. Here's my local script:
    Add-AzureAccount
    Select-AzureSubscription -SubscriptionName "mysubscription"
    $Uri = Get-AzureWinRMUri -ServiceName "myservice" -Name "mymachine"
    $Credential = Get-Credential
    $Cmd = "& 'C:\Program Files (x86)\apache-jmeter-2.11\bin\jmeter-runbook.bat'"
    Invoke-command -ConnectionUri $Uri -credential $Credential -ScriptBlock {
    Invoke-Expression $Args[0]
    } -Args $Cmd
    With this, I get the following error (sorry, it is in German):
    [myservice.cloudapp.net] Beim Verbinden mit dem Remoteserver "myservice.cloudapp.net" ist folgender Fehler
    aufgetreten: Das Serverzertifikat auf dem Zielcomputer (myservice.cloudapp.net:666) enthält die folgenden
    Fehler:
    Das SSL-Zertifikat ist von einer unbekannten Zertifizierungsstelle signiert. Weitere Informationen finden Sie im
    Hilfethema "about_Remote_Troubleshooting".
        + CategoryInfo          : OpenError: (myservice.cloudapp.net:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : 12175,PSSessionStateBroken

Maybe you are looking for

  • APP STORE WHITE SCREEN..!!

    i hav an iphone4...and the app store shows white screen..its been 2-3 days now...plzz help

  • I need help in Swedish

    I need help in Swedish thanks Åke

  • UPgraging from 4.6c to Ecc 5.0

    Hi, Please let me know what are the precautions to be taken while upgrading from 4.6c to ECC 5.0, and what are the issues will arise? Please let me know. Thanks, Pavan.

  • Missing pop up menu

    When I click an option, quick selection tool for example, I don't also get the pop up for further choices such as brush size. This happens for all options.

  • Apple Forgot to Replace Screw's

    When apple replaced my MacBook cover they forgot to out the two screws back in on the left hand side of my MacBook where all the ports are... I have only just noticed this even tho they replaced my uppercase after the magnets dug the lid of the LCD s