Forum Stats

  • 3,760,418 Users
  • 2,251,703 Discussions
  • 7,871,111 Comments

Discussions

Can the JVM put part of the memory on the disk? To reduce the memory occupied by the JVM

User_SQKK0
User_SQKK0 Member Posts: 3 Green Ribbon

Can we put Metaspace on disk? Can the unchanging objects in the method area of the JVM be put into the disk to optimize the memory of the JVM (or objects in the heap that have not been recycled after GC several times). Although the disk IO performance is very low, SSD can greatly improve the performance

Answers

  • Billy Verreynne
    Billy Verreynne Software Engineer Member Posts: 28,573 Red Diamond

    This is essentially an o/s kernel issue. It provides a memory API to processes for allocating & freeing memory. The kernel manages memory page swapping as needed - e.g. swapping pages into and out of the memory cash on disk (typically called a page file or swap disk partition).

  • User_SQKK0
    User_SQKK0 Member Posts: 3 Green Ribbon

    Sorry, I don't quite understand. Do you mean that the operating system can do this, so you don't need a JVM to do it

  • User_SQKK0
    User_SQKK0 Member Posts: 3 Green Ribbon

    Sorry, I don't quite understand. Do you mean that the operating system can do this, so you don't need a JVM to do it

  • Billy is right, memory swap is an OS task which swaps chunks of memory that belong to different OS processes, including memory allocated for the JVM. OS does not care what exactly this memory is used for, just that it should be swapped when this machine runs out of the physical memory capacity. However, you may offload some of the Java objects from memory through serialisation, thus implementing a kind of swap mechanism on the specific application level. In any case you should also consider performance implications.

  • Billy Verreynne
    Billy Verreynne Software Engineer Member Posts: 28,573 Red Diamond
    edited May 13, 2021 12:50PM

    Sorry, I don't quite understand. Do you mean that the operating system can do this, so you don't need a JVM to do it

    The JVM process uses o/s kernel calls for allocating and freeing memory. The o/s manages the physical aspects of the memory pages - whether for example a page can be swapped out, what swap cache to use, and so on.

    The process (like JVM) manages the contents of the page via reads and writes - and determine itself when a data structure used is destroyed, whether to release the memory occupied by the structure back to the o/s kernel as free memory, or whether to hang on to that memory for itself to reuse when a new data structure is created.

    The o/s kernel can also support huge pages as oppose to tons of little pages. The more pages to manage, the bigger the overhead to manage all these pages, and the slower performance. Fewer pages in turn means the coarser the division of memory is between processes, and the larger the smallest/minimum allocation of memory is.

    Then there are means for a process to request pages that will be heavily and continually used, to be locked into memory and not to be swapped,

    Memory management is not simplistic. And unfortunately Java can consume lots of memory, made worse by shoddy design and code.

    Bottom line is however that more RAM for a device or platform, is invariably A Good Thing (tm).