Can memory allocated to swap space be used for storage (similar to hard drive storage) - virtual-machine

I learned that if physical memory (RAM) is filled then OS can use swap space memory from hard drive. However can this swap space memory be again used from permanent storage?
Also if we can allocate any amount of memory to swap space then why don't people buy small amount of physical memory and use large amount swap memory

Related

What is internal memory? Where can I find it?

So today I got to make presentation about RAM ROM and Internal memory, the problem is that internal memory is literally RAM and ROM, I asked my teacher, he said it is and it is not, he also mentioned that there is internal memory in CPU it self or something right that, so any resources about Internal memory and what parts of technology you can find it would be appreciated, also if you could find internal memory in cpu I would love that because I couldn't find it anywhere!
Some microcontrollers come with some internal RAM that's architecturally usable as memory for loads/stores. (System on chip where external RAM is optional.) http://www.avr-asm-tutorial.net/avr_en/beginner/SRAM.html shows how AVR maps SRAM to the low end of physical address space. And that the very bottom of physical address space aliases the registers! (That's unusual, most ISAs don't memory-map the register file.)
But more generally, caches and physical register files are SRAM arrays, so in most CPUs you have internal RAM that's not architecturally visible as "memory".

Is redis using cache?

I restarted my redis server after 120 days.
Before restart, memory usage 29.5GB
After restarted, memory usage 27.5GB
So, how 2GB reduced comes?
Free memory in ram like this article https://redis.io/topics/memory-optimization
Redis will not always free up (return) memory to the OS when keys are
removed. This is not something special about Redis, but it is how most
malloc() implementations work. For example if you fill an instance
with 5GB worth of data, and then remove the equivalent of 2GB of data,
the Resident Set Size (also known as the RSS, which is the number of
memory pages consumed by the process) will probably still be around
5GB, even if Redis will claim that the user memory is around 3GB. This
happens because the underlying allocator can't easily release the
memory. For example often most of the removed keys were allocated in
the same pages as the other keys that still exist. The previous point
means that you need to provision memory based on your peak memory
usage. If your workload from time to time requires 10GB, even if most
of the times 5GB could do, you need to provision for 10GB.
However allocators are smart and are able to reuse free chunks of
memory, so after you freed 2GB of your 5GB data set, when you start
adding more keys again, you'll see the RSS (Resident Set Size) to stay
steady and don't grow more, as you add up to 2GB of additional keys.
The allocator is basically trying to reuse the 2GB of memory
previously (logically) freed.
Because of all this, the fragmentation ratio is not reliable when you
had a memory usage that at peak is much larger than the currently used
memory. The fragmentation is calculated as the amount of memory
currently in use (as the sum of all the allocations performed by
Redis) divided by the physical memory actually used (the RSS value).
Because the RSS reflects the peak memory, when the (virtually) used
memory is low since a lot of keys / values were freed, but the RSS is
high, the ratio mem_used / RSS will be very high.
Or free memory of caches which was used by my redis server?
Is redis using cache? Cache of cache?
Thanks!

What is the minimum requirement of physical RAM if I want to set JVM virtual RAM 8GB?

Recently I am trying to Integrate mateplus a semantic role labeling tool for my work. It requires upto 8GB JVM virtual RAM for heap memory. can anybody help me out that If I want to do that, what is the minimum requirement of physical RAM.
It will be good to have at least 8GB RAM, but the JVM's are allocating virtual memory, not physical memory. The OS will assign physical memory to virtual memory as necessary and efficient. Modern operating systems can allow virtual memory consumption to significantly exceed physical memory. This may or may not lead to poor performance, depending on the working set size -- roughly how much of the virtual memory is actually accessed.
So in simple words if OS have less physical memory than JVM need it will swap it on hard disk which will affect performance.

Can a 32-bit processor load a 64-bit memory address using multiple blocks or registers?

I was doing a little on 32-bit microprocessors and have I have learnt that:
1) A 32-bit microprocessor can only address 2^32 bits of memory which means that the memory pointer size should not exceed 32-bit range i.e. the pointer size should be equal to or less than 32-bit.
2) I also came to know that CPU allocate multiple blocks of memory for things like storing numbers and text, that is up to the program and not related to the size of each address (Source:here).So is it possible that a CPU can use multiple blocks (registers) to store pointers more than 32-bit in size?
Processors can access an essentially unlimited amount of memory by using variations on a technique called bank switching. In a simple bank-switching scheme, the memory chips that are wired to a portion of the address space will have some address inputs fed by the processor and some from an external latching device. Historically, the IBM PC had a 1MB address space, but an expanded memory board would IIRC allow two 16KB regions of that space to be mapped to any of dozens or hundreds of 16KB blocks of memory contained thereon. Nowadays processors generally have a memory-management unit built-in, which maps 4KB or 64KB blocks of memory to any address within a much larger space, and additional circuitry may, with OS support, expand things further.
The big difficulty with bank switching is that any given address might identify many different places in memory depending upon how the bank-switching hardware is configured, so accessing data from memories in a banked region will generally be more complicated than accessing data in directly-accessible memory and will only be possible from code which knows how the bank-switching hardware works. Nowadays it's more common to simply use a processor which can access all the memory one needs, but historically bank-switching was often a useful technique for going beyond processor limitations.
You could store a 64 bit pointer using 2 separate locations in memeory. But it probably wouldn't be useful since your processor can only use 32 bit pointers.

providing more heap in Keil

I am working on MCB2300 (with LPC2378 processor)and using keil uVision4. In my program I am creating dynamic memory using malloc() function. As all dynamic contents will be stored in heap, I need to ensure that required heap size allocated. The default value for heap in my startup file (LPC2300.s) is 0x00000800. In my application I am reading an image (bmp format) and storing the pixel values into a matrix and the matrix is created dynamically with respect to size of input image. The maximum heap value I can set in my start up file is 0x000072FF. For this value of heap, I was able to read an image of 44 x 33 successfully. Beyond this size memory is not allocated. I need to read an image with dimensions of atleast 100 x 100. My available RAM is 32K
These are my output values after I compile my code
Program Size: Code=30664 RO-data=1220 RW-data=132 ZI-data=37628
How to provide additional heap?
Is it possible to store heap memory on SD/MMC card or external memory bank which has been provided for LPC2378. Please help me to solve this problem
If your board has external RAM chip, you can use it for heap.
But if there are no external RAM, there are no way to increase heap size above internal RAM size.
You can write some variant of virtual memory driver to use SD/MMC card as memory device. But since your device has no MMU (memory management unit), your driver will be extreme complex and extreme slow. So it is not an option.
Also, having 28K of heap, you can hold 99x99 RGB24 BMP image there. 99*99*3 = 29403.