GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 4.1.114.Final upgrade 4.1.115.Final OOM · Issue #14553 · netty/netty

4.1.114.Final upgrade 4.1.115.Final OOM #14553

New issue
Copy link
New issue
Copy link
Closed
#14586
Closed
4.1.114.Final upgrade 4.1.115.Final OOM#14553
#14586
Copy link
Milestone
4.1.116.Final

Description

@linking12
linking12
opened on Dec 10, 2024
Issue body actions

Expected behavior

No OOM

Actual behavior

OOM

Steps to reproduce

Hard to provide

Minimal yet complete reproducer code (or URL to code)

Hard to provide

Netty version

4.1.115

JVM version (e.g. java -version)

Jdk17

OS version (e.g. uname -a)

K8s

I think this is a hard to reproduce issue, when i upgrade netty to 4.1.115.Final, the application of our cluster 2 node oom killed;
one is aws ec2, one is k8s node, i found the oom reason is mmap cache is increaseing slow, but not all the instance occurs this issue;

es2 monitor:
image

k8s node oom log:

image image

i make sure our app'mmap do not increase;
image

I'd like to confirm if there was any change in version 4.115 that caused the mmap to grow?

Activity

Next
  1. chrisvest commented on Dec 10, 2024

    @chrisvest
    chrisvest
    on Dec 10, 2024
    Member
    More actions

    List of changes: netty-4.1.114.Final...netty-4.1.115.Final

    We don't directly map files, but anonymous mapped memory is where the system malloc sources its memory.
    Maybe some of the adaptive allocator changes behaves poorly?

  2. linking12 commented on Dec 11, 2024

    @linking12
    linking12
    on Dec 11, 2024
    Author
    More actions

    List of changes: netty-4.1.114.Final...netty-4.1.115.Final

    We don't directly map files, but anonymous mapped memory is where the system malloc sources its memory. Maybe some of the adaptive allocator changes behaves poorly?

    image

    @chrisvest i found inactive_anno & rss memory cause the k8s node oom, i think adaptive has some memory leak in 4.1.115.Final version, also this issue happened on high traffic comming, but when no high traffic, everything is fine

  3. linking12 commented on Dec 12, 2024

    @linking12
    linking12
    on Dec 12, 2024
    Author
    More actions

    Another node has OOM for the same reason. I turned on Leak Detaction and found no leak. I suspect there is a problem with adaptive allocation. I will roll to version 114 for verification.

  4. He-Pin commented on Dec 12, 2024

    @He-Pin
    He-Pin
    on Dec 12, 2024
    Contributor
    More actions

    @linking12 Hi, which BytebufAllocator are you currently using? We found the same issue when we tried the AdaptiveByteBufAllocator when stressing testing, but sorry, have not had another chance to stress it again.

    I think you can try to stress it with a different payload to see if that still happen in production.

  5. linking12 commented on Dec 12, 2024

    @linking12
    linking12
    on Dec 12, 2024
    Author
    More actions

    @linking12 Hi, which BytebufAllocator are you currently using? We found the same issue when we tried the AdaptiveByteBufAllocator when stressing testing, but sorry, have not had another chance to stress it again.

    I think you can try to stress it with a different payload to see if that still happen in production.

    AdaptiveByteBufAllocator, 4.1.114.Final i think there is no this issue, i want to found what have changed in 4.1.115.Final

  6. franz1981 commented on Dec 12, 2024

    @franz1981
    franz1981
    on Dec 12, 2024
    Contributor
    More actions

    Mmap Is used by glibc malloc when the allocations exceed MMAP_THRESHOLD; which native allocator you are using?
    I suggest to use async profiler with -e mprotect if is glibc and we can probably capture the code path which keep on leaking

    Reacted by Norman Maurer
  7. linking12 commented on Dec 12, 2024

    @linking12
    linking12
    on Dec 12, 2024
    Author
    More actions

    Mmap Is used by glibc malloc when the allocations exceed MMAP_THRESHOLD; which native allocator you are using? I suggest to use async profiler with -e mprotect if is glibc and we probably capture the code path which keep on leaking

    We use the default glibc malloc of the operating system. I am currently rolling back the version to stop the bleeding. I will try your suggestion.

  8. franz1981 commented on Dec 12, 2024

    @franz1981
    franz1981
    on Dec 12, 2024
    Contributor
    More actions

    Another option could be to use cleaners or limit the JVM native memory (you can do it both via a netty property or maxDirectMemory one on the JVM) and add heap dump on OOM so we can inspect the Chunk(s) instances there; my gut feeling point to #14550 (comment) which shows that over a specific requested size we allocates instead of reusing memory..

    Re -e mprotect; glibc malloc creates new malloc arenas and perform mprotect on them, which means that the stack traces we can find can both be cause or an effect of a leak, but since allocations on the pool should become zero (if not on chunk exhaustion or big allocations), it's fine to be suspicious of any new allocation when the existing malloc arenas are exhausted.

    Reacted by linking12 and He-Pin(kerr)
  9. He-Pin commented on Dec 12, 2024

    @He-Pin
    He-Pin
    on Dec 12, 2024
    Contributor
    More actions

    @linking12 Add a -XX:MaxDirectMemorySize=6g in your staging ENV and do stressing, which will help.
    And another thing is , you can change your JVM to use jemalloc too.

  10. laosijikaichele commented on Dec 12, 2024

    @laosijikaichele
    laosijikaichele
    on Dec 12, 2024
    Contributor
    More actions

    This may be related or not, I also have observed the OutOfMemoryError when doing the benchmark for AdaptiveByteBufAllocator, it seems that the AdaptiveByteBufAllocator is more likely to encounter 'OOM' than the PooledByteBufAllocator.DEFAULT allocator.

    Use this sample code BufAllocatorOOMBenchmark to produce OutOfMemoryError, which limit the memory size by -Xms168m -Xmx168m -XX:MaxDirectMemorySize=168m

    Run the sample code, you will see the PooledByteBufAllocator.DEFAULT passed the benchmark, but the AdaptiveByteBufAllocator got OutOfMemoryError.

    For this sample code, the netty-version does not matter, '4.1.114.Final' and '4.1.115.Final' both rise the OutOfMemoryError.

    Reacted by He-Pin(kerr)
  11. linking12 commented on Dec 13, 2024

    @linking12
    linking12
    on Dec 13, 2024
    Author
    More actions

    Mmap Is used by glibc malloc when the allocations exceed MMAP_THRESHOLD; which native allocator you are using? I suggest to use async profiler with -e mprotect if is glibc and we probably capture the code path which keep on leaking

    We use the default glibc malloc of the operating system. I am currently rolling back the version to stop the bleeding. I will try your suggestion.

    rollback to '4.1.114.Final' oom disappear, but some node's memory has increased a little, maybe @laosijikaichele is right,it seems that the AdaptiveByteBufAllocator is more likely to encounter 'OOM' than the PooledByteBufAllocator.DEFAULT allocator. We usually release once every two weeks has covered up this issue

  12. He-Pin commented on Dec 13, 2024

    @He-Pin
    He-Pin
    on Dec 13, 2024
    Contributor
    More actions

    Link to this : Does AdaptivePoolingAllocator use more memory than PooledByteBufAllocator? #14135

  13. He-Pin commented on Dec 13, 2024

    @He-Pin
    He-Pin
    on Dec 13, 2024
    Contributor
    More actions

    @laosijikaichele I think the AdaptiveByteBufAllocator may have many small fragmants which are not fully utilized when allocation, I was not have time to look into it :(

    Reacted by old driver
  14. laosijikaichele commented on Dec 13, 2024

    @laosijikaichele
    laosijikaichele
    on Dec 13, 2024
    Contributor
    More actions

    It seems that add the code
    chunk.allocatedBytes = chunk.allocatedBytes - length;
    after the line-1273 make the OOM less occurred:

    netty/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java

    Lines 1270 to 1285 in 67c50a1

    @Override
    protected void deallocate() {
    if (chunk != null) {
    chunk.release();
    }
    tmpNioBuf = null;
    chunk = null;
    rootParent = null;
    if (handle instanceof EnhancedHandle) {
    EnhancedHandle<AdaptiveByteBuf> enhancedHandle = (EnhancedHandle<AdaptiveByteBuf>) handle;
    enhancedHandle.unguardedRecycle(this);
    } else {
    handle.recycle(this);
    }
    }
    }

    But, I am not sure if this is correct in logical. @chrisvest @franz1981 @He-Pin

  15. normanmaurer commented on Dec 13, 2024

    @normanmaurer
    normanmaurer
    on Dec 13, 2024
    Member
    More actions

    It seems that add the code chunk.allocatedBytes = chunk.allocatedBytes - length; after the line-1273 make the OOM less occurred:

    netty/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java

    Lines 1270 to 1285 in 67c50a1

    @Override
    protected void deallocate() {
    if (chunk != null) {
    chunk.release();
    }
    tmpNioBuf = null;
    chunk = null;
    rootParent = null;
    if (handle instanceof EnhancedHandle) {
    EnhancedHandle<AdaptiveByteBuf> enhancedHandle = (EnhancedHandle<AdaptiveByteBuf>) handle;
    enhancedHandle.unguardedRecycle(this);
    } else {
    handle.recycle(this);
    }
    }
    }

    But, I am not sure if this is correct in logical. @chrisvest @franz1981 @He-Pin

    So before null out chunk ?

  16. 5 remaining items

  17. johnou commented on Dec 13, 2024

    @johnou
    johnou
    on Dec 13, 2024
    Contributor
    More actions

    @laosijikaichele looks like there is also an edge case in io.netty.buffer.AdaptivePoolingAllocator.Chunk#readInitInto where allocatedBytes is incremented but in the finally catch when deallocating b/c of failure it is not decremented.

    Index: buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java b/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
    --- a/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java	(revision 67c50a1647b5a1c7673a327c833799493f062b3e)
    +++ b/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java	(date 1734091751136)
    @@ -880,6 +880,7 @@
                         // If chunk is not null we know that buf.init(...) failed and so we need to manually release
                         // the chunk again as we retained it before calling buf.init(...).
                         chunk.release();
    +                    allocatedBytes = startIndex;
                     }
                 }
             }
    
    Reacted by old driver, He-Pin(kerr) and linking12
  18. normanmaurer commented on Dec 13, 2024

    @normanmaurer
    normanmaurer
    on Dec 13, 2024
    Member
    More actions

    @laosijikaichele looks like there is also an edge case in io.netty.buffer.AdaptivePoolingAllocator.Chunk#readInitInto where allocatedBytes is incremented but in the finally catch when deallocating b/c of failure it is not decremented.

    Index: buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java b/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
    --- a/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java	(revision 67c50a1647b5a1c7673a327c833799493f062b3e)
    +++ b/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java	(date 1734091751136)
    @@ -880,6 +880,7 @@
                         // If chunk is not null we know that buf.init(...) failed and so we need to manually release
                         // the chunk again as we retained it before calling buf.init(...).
                         chunk.release();
    +                    allocatedBytes = startIndex;
                     }
                 }
             }
    

    Good catch #14577

  19. normanmaurer commented on Dec 13, 2024

    @normanmaurer
    normanmaurer
    on Dec 13, 2024
    Member
    More actions

    @johnou Thanks for the quick test. But I thinks it's probably not that simple, as the #14553 (comment) stated, we may need to find another way to make the released memory be reusable...

    Yes its not as easy...

  20. normanmaurer commented on Dec 13, 2024

    @normanmaurer
    normanmaurer
    on Dec 13, 2024
    Member
    More actions

    So I think the problem basically steams from how we calculate the queue size:

        /**
         * The maximum size of a pooled chunk, in bytes. Allocations bigger than this will never be pooled.
         * <p>
         * This number is 10 MiB, and is derived from the limitations of internal histograms.
         */
        private static final int MAX_CHUNK_SIZE =
                BUFS_PER_CHUNK * (1 << AllocationStatistics.HISTO_MAX_BUCKET_SHIFT); // 10 MiB.
    
        /**
         * The capacity if the central queue that allow chunks to be shared across magazines.
         * The default size is {@link NettyRuntime#availableProcessors()},
         * and the maximum number of magazines is twice this.
         * <p>
         * This means the maximum amount of memory that we can have allocated-but-not-in-use is
         * 5 * {@link NettyRuntime#availableProcessors()} * {@link #MAX_CHUNK_SIZE} bytes.
         */
        private static final int CENTRAL_QUEUE_CAPACITY = SystemPropertyUtil.getInt(
                "io.netty.allocator.centralQueueCapacity", NettyRuntime.availableProcessors());
    

    This basically means if you end up with a Chunk size of 10MB the worst case is that you will have 2 * 10 MB (for the Magazine) + cores * 10MB. This can easily a few hundred MB.

  21. He-Pin commented on Dec 13, 2024

    @He-Pin
    He-Pin
    on Dec 13, 2024
    Contributor
    More actions

    You mean if there are many cores ?

  22. normanmaurer commented on Dec 13, 2024

    @normanmaurer
    normanmaurer
    on Dec 13, 2024
    Member
    More actions

    Yeah... that said there was also a bug that could lead to huge memory usage:

    #14581

  23. normanmaurer
    added this to the 4.1.116.Final milestone on Dec 13, 2024
  24. normanmaurer
    added 3 commits that reference this issue on Dec 13, 2024

    Adapt: Ensure Chunks from the central Queue are re-used even if there…

    6e25f59

    Adapt: Ensure Chunks from the central Queue are re-used even if there…

    9927575

    Adapt: Ensure Chunks from the central Queue are re-used even if there…

    e26ef2a
  25. normanmaurer
    closed this as completedin #14586on Dec 14, 2024
  26. normanmaurer
    closed this as completedin dccfcc8on Dec 14, 2024
  27. pull
    added a commit that references this issue on Dec 14, 2024

    Adapt: Ensure Chunks from the central Queue are re-used even if there… (

    dccfcc8
  28. linking12 commented on Dec 18, 2024

    @linking12
    linking12
    on Dec 18, 2024
    Author
    More actions
    image

    @normanmaurer i'm not sure this issue is fixed, we use the latest code;
    I found that the rss memory will continue to increase. Although it will decrease after a certain period of time, it is generally increasing. Now I understand why the mmap memory why increase. It should be that when the rss is not enough, it will try to exchange memory through mmap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.1.116.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.