I was wondering what differences and relations are between logical and virtual memory? How do their purposes differ?
Are the relations and differences the same for logical and virtual addresses?
Let's go over the difference between virtual and logical addressing first. I believe the distinction is that "logical address" means that the address the program sees is different from the physical address of the data being stored in RAM.
If you have virtual memory, there may be no physical address at all, as the data stored could be swapped out to disk. However, it is possible to have a system without virtual memory where logical addresses are different from physical addresses, but each logical address is mapped to a physical address. This would make it easier to run multiple programs without them stepping on each other, but wouldn't let the programs use more memory than the physical memory available to the system.
So there is no separate "logical memory" in a computer, though I suppose you could say that a computer with logical addresses but no virtual memory system has a logical memory system. I would just say that logical memory is memory addressed via some indirection method. Is there some specific computer system that you have in mind?
Taking your comments into account:
Logical addresses for the same physical memory can be the same or different. Usually two processes won't have access to the same memory, since then one can corrupt the other. However, if they have arranged to use some form of shared memory, they will usually map that shared memory to different addresses. Virtual addresses are more or less a type of logical address, so if you have an operating system that supports VM, and two processes map shared memory, they will usually see that memory as being at different addresses, the same as if there was no virtual memory.
As for your understanding of the purpose of logical vs virtual, virtual memory is for using the HD to extend the memory that you have available to programs. Logical addressing can be used for more than process separation, but that would be one major use.
"Logical" memory addresses are used by a process to reference its code and data. Translation from a logical address to a physical address depends on the memory model.
When memory is directly mapped (i.e. real mode), the logical memory address is identical to the physical memory address.
If physical memory is larger than the processor's address space (such as on a 16-bit processor), then memory bank hardware is often employed to expand the usable amount of physical memory. Intel 8086/8088 processors used flexible segment registers instead of a fixed bank scheme. Translation of a (16-bit) logical address to a (20-bit) physical address would use the bank map tables. For x86 the logical address would probably include specification of a segment register.
If the physical address range is larger than the typical physical memory (such as 32-bit processors a decade ago), then virtual memory hardware is employed to provide use of the full address range. The logical addresses are backed by physical memory on demand. To accommodate the full virtual/logical address space and/or to provide each process with its own address space, a backing store is needed to hold swapped out copies of virtual memory. The swapped memory could be organized by segments or pages or segmented pages.
BTW in my years of Unix kernel hacking, I rarely heard or used the phrase "logical (memory) address". If you weren't referring to the physical memory address, then it was the virtual address. That is, "logical address" == "virtual address" (when virtual memory is activated in the MMU).