Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-36213

Doubled memory usage (11.4.4 <-> 11.4.5)

Details

    • Bug
    • Status: Closed (View Workflow)
    • Blocker
    • Resolution: Fixed
    • 11.4.5
    • 11.4.6
    • Character Sets
    • None
    • Ubuntu 24.04
      Fedora 41

    Description

      Doubled memory usage (11.4.4 <-> 11.4.5)

      After updating a productive MariaDB installation to 11.4.5 my monitoring showed that the docker container for MariaDB (official image) is using twice as much memory than with the previous version (around 128MB with 11.4.4 and around 256 MB with 11.4.5).
      I checked my config and "SHOW GLOBAL STATUS", but nothing seems to explain that increase in memory usage. After rolling back to 11.4.4, everything is back to normal. This happened on Ubuntu 24.04 LTS (kernel 6.8.0-54-generic).

      I can even see a 30% increase with a blank database and default config on my Fedora 41 Workstation. When a client connects, in 11.4.5 the memory usage increases by 90MB (compared to 5MB in the previous version). With a client connected, you can see the 100% increase in memory usage.

      I also attached two screenshots showing memory and disk metrics of my production host around the time of downgrading MariaDB 11.4.5 to 11.4.4. It seems noticeable that 11.4.5 also causes higher disk I/O.

      # Check memory usage (use dedicated terminal to keep running)
      docker stats
       
      # Start containers
      docker run -d --name mariadb-11.4.4 -e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 mariadb:11.4.4
      docker run -d --name mariadb-11.4.5 -e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 mariadb:11.4.5
       
      # Connect a client
      docker exec -it mariadb-11.4.4 mariadb
      docker exec -it mariadb-11.4.5 mariadb
       
      # Stop containers and cleanup
      docker stop mariadb-11.4.4 mariadb-11.4.5
      docker rm mariadb-11.4.4 mariadb-11.4.5
      

      Attachments

        Issue Links

          Activity

            Reading through the code I ended in add_alias_for_collation (in mysys/charset.c). I think that is where things go bad.

            Usually character sets and collations are lazy loaded, so not touched at all most of the time. This changes here, just before creating the 0900 collation aliases the corresponding 1400 collation is initialized - this adds both, extra allocated memory and processing runtime.

            So wondering if we can add these aliases without eager loading the corresponding collation before...

            eworm Christian Hesse added a comment - Reading through the code I ended in add_alias_for_collation (in mysys/charset.c ). I think that is where things go bad. Usually character sets and collations are lazy loaded, so not touched at all most of the time. This changes here, just before creating the 0900 collation aliases the corresponding 1400 collation is initialized - this adds both, extra allocated memory and processing runtime. So wondering if we can add these aliases without eager loading the corresponding collation before...
            bar Alexander Barkov added a comment - - edited

            eworm, you are right, things go badly in add_alias_for_collation(). It performs deep initialization of all 1400 collations having 0900 aliases.

            I have a patch fixing to do only basic initialization at startup time (enough for SHOW and INFORMATION_SCHEMA queries), while deep initialization is postponed until a collation is used for the first time:

            https://github.com/MariaDB/server/tree/bb-11.4-bar-MDEV-36213

            The patch currently (as of 2025-03-32) is in progress. Still need to add MTR tests to prove that deep initialization is not done at statup. But the code change is done. I had to do some refactoring to make the code easier to maintain.

            bar Alexander Barkov added a comment - - edited eworm , you are right, things go badly in add_alias_for_collation(). It performs deep initialization of all 1400 collations having 0900 aliases. I have a patch fixing to do only basic initialization at startup time (enough for SHOW and INFORMATION_SCHEMA queries), while deep initialization is postponed until a collation is used for the first time: https://github.com/MariaDB/server/tree/bb-11.4-bar-MDEV-36213 The patch currently (as of 2025-03-32) is in progress. Still need to add MTR tests to prove that deep initialization is not done at statup. But the code change is done. I had to do some refactoring to make the code easier to maintain.

            bar, I've already followed the changes in that branch. At least an earlier revision did work as expected. Let me know if you want me the recheck.

            The patch currently (as of 2025-03-32) is in progress.

            Don't let it get lost in transition... 😜

            eworm Christian Hesse added a comment - bar , I've already followed the changes in that branch. At least an earlier revision did work as expected. Let me know if you want me the recheck. The patch currently (as of 2025-03-32) is in progress. Don't let it get lost in transition... 😜
            bar Alexander Barkov added a comment - Hi Monty. Please review a patch: https://github.com/MariaDB/server/commit/1748b02ec63263693240c76baea8e780805fa6c2
            monty Michael Widenius added a comment -

            Review done. Some trivial changes requested, nothing that should take any notable time

            monty Michael Widenius added a comment - Review done. Some trivial changes requested, nothing that should take any notable time

            People

              bar Alexander Barkov
              mklocke Marius Klocke
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.