CarsCanadian
Posts: 2
Joined: Wed Aug 19, 2020 2:24 am

Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Wed Aug 19, 2020 2:29 am

Hey so When ever I try to create a Java VM that is more then 2500MB, it just says not enough memory available. I have a 4GB raspberry pi 4b+ and in top, it says that 3800MB are available. Also I am running OpenJDK 11. Is this a problem with my java Installation?

fruitoftheloom
Posts: 24463
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Wed Aug 19, 2020 7:55 am

CarsCanadian wrote:
Wed Aug 19, 2020 2:29 am
Hey so When ever I try to create a Java VM that is more then 2500MB, it just says not enough memory available. I have a 4GB raspberry pi 4b+ and in top, it says that 3800MB are available. Also I am running OpenJDK 11. Is this a problem with my java Installation?

Where did you get a model 4B+ from, was not aware they existed ?

What Operating System ?
Thinking outside the box is better than burying your head in the sand...

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3445
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Wed Aug 19, 2020 8:09 am

You might get slightly more memory if you run the 64-bit kernel - add "arm_64bit=1" to config.txt. Note that this only changes the kernel - the userland applications and libraries are still 32-bit.

fruitoftheloom
Posts: 24463
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Wed Aug 19, 2020 8:44 am

CarsCanadian wrote:
Wed Aug 19, 2020 2:29 am
Hey so When ever I try to create a Java VM that is more then 2500MB, it just says not enough memory available. I have a 4GB raspberry pi 4b+ and in top, it says that 3800MB are available. Also I am running OpenJDK 11. Is this a problem with my java Installation?

Raspberry Pi ARM64 Beta Operating System is 64bit Kernel & Userland, may be worth a try ??
Thinking outside the box is better than burying your head in the sand...

CarsCanadian
Posts: 2
Joined: Wed Aug 19, 2020 2:24 am

Re: Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Thu Aug 20, 2020 1:01 am

fruitoftheloom wrote:
Wed Aug 19, 2020 7:55 am
CarsCanadian wrote:
Wed Aug 19, 2020 2:29 am
Hey so When ever I try to create a Java VM that is more then 2500MB, it just says not enough memory available. I have a 4GB raspberry pi 4b+ and in top, it says that 3800MB are available. Also I am running OpenJDK 11. Is this a problem with my java Installation?

Where did you get a model 4B+ from, was not aware they existed ?

What Operating System ?
Im using Raspberry pi OS, and sorry I thought that it was 4b+, guess its just 4

fruitoftheloom
Posts: 24463
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Thu Aug 20, 2020 5:57 am

CarsCanadian wrote:
Thu Aug 20, 2020 1:01 am
fruitoftheloom wrote:
Wed Aug 19, 2020 7:55 am
CarsCanadian wrote:
Wed Aug 19, 2020 2:29 am
Hey so When ever I try to create a Java VM that is more then 2500MB, it just says not enough memory available. I have a 4GB raspberry pi 4b+ and in top, it says that 3800MB are available. Also I am running OpenJDK 11. Is this a problem with my java Installation?

Where did you get a model 4B+ from, was not aware they existed ?

What Operating System ?
Im using Raspberry pi OS, and sorry I thought that it was 4b+, guess its just 4

https://www.raspberrypi.org/products/ra ... 4-model-b/
Thinking outside the box is better than burying your head in the sand...

User avatar
clicky
Posts: 501
Joined: Thu Oct 25, 2012 7:34 am

Re: Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Sat Aug 22, 2020 10:42 am

Code: Select all

import java.util.ArrayList;
import java.util.List;

public class MemoryTest {

    public static void main(String[] args) throws Exception {
        List<byte[]> allocatedObjects = new ArrayList<byte[]>();

        for (int i = 0; i < 6 * 10; i++) {
            allocatedObjects.add(allocateHundredMegabytes());
            System.out.println("Allocated " + allocatedObjects.size() * 100L + "MiB, total used " + Runtime.getRuntime().totalMemory() / (1024L * 1024L) + "MiB");
        }
    }

    private static byte[] allocateHundredMegabytes() {
        int hundredMegs = 1024 * 1024 * 100;
        byte[] bs = new byte[hundredMegs];
        for (int i = 0; i < hundredMegs; i = i + 100) {
            bs[i] = 22;
        }
        return bs;
    }
}
64bit PiOS

adoptopenJDK13

VM Args: -Xmx8192M

Happily allocated ~ 7GiB

Do tell me if you think something's not quite right (it seemed too easy and RPi was way to happy to oblige and allocated that memory)...
Attachments
java-memory.jpg
java-memory.jpg (115.42 KiB) Viewed 532 times

User avatar
clicky
Posts: 501
Joined: Thu Oct 25, 2012 7:34 am

Re: Java only being able to reserve 2.5GB on a 4GB Raspberry pi 4

Sat Aug 22, 2020 10:58 am

This is interesting: 8GB RPi, X-windows with KDE and one terminal window open - cannot allocate more than 6.3GiB (heap is set to 8GiB).

Also, JDK13 and JDK14 just bomb out with 'Killed' and no other indication why Java process stopped. Here's the output of above program:

Code: Select all

...
Allocated 3800MiB, total used 6468MiB
Allocated 3900MiB, total used 6468MiB
Allocated 4000MiB, total used 6808MiB
Allocated 4100MiB, total used 6808MiB
Allocated 4200MiB, total used 7148MiB
Allocated 4300MiB, total used 7148MiB
Allocated 4400MiB, total used 7488MiB
Allocated 4500MiB, total used 7488MiB
Allocated 4600MiB, total used 7828MiB
Allocated 4700MiB, total used 7828MiB
Allocated 4800MiB, total used 8168MiB
Allocated 4900MiB, total used 8168MiB
Allocated 5000MiB, total used 8192MiB
Allocated 5100MiB, total used 8192MiB
Allocated 5200MiB, total used 8192MiB
Allocated 5300MiB, total used 8192MiB
Allocated 5400MiB, total used 8192MiB
Allocated 5500MiB, total used 8192MiB
Allocated 5600MiB, total used 8192MiB
Allocated 5700MiB, total used 8192MiB
Allocated 5800MiB, total used 8192MiB
Allocated 5900MiB, total used 8192MiB
Allocated 6000MiB, total used 8192MiB
Allocated 6100MiB, total used 8192MiB
Allocated 6200MiB, total used 8192MiB
Allocated 6300MiB, total used 8192MiB
Killed
pi@desktop-pi:~/Documents/Projects/Workspaces/ah-workspace/MemoryTest $ 

Return to “Java”