Wednesday, September 30, 2015

MEMORY MANAGEMENT - 1

  MEMORY MANAGEMENT INTERVIEW QUESTIONS AND ANSWERS

PAGE - 1


1..Which partition is used for virtual memory by a Linux system?
swap
2..How to find out the usage of memory in linux?
# free –m
# vmstat –s
# top

3..What is Swap Space?
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.

4..How to check the information about RAM of your system?
# free

5..What is virtual address space?
Linux, a operating system, virtualizes its physical resource of memory.
Processes do not directly address physical memory. Instead, the kernel associates each process with a unique virtual address space. This address space is linear, with addresses starting at zero, and increasing to some maximum value.

6..Write the difference between  the Pages and Paging?

The virtual address space is composed of pages. The system architecture and
machine type determine the size of a page, which is fixed; typical sizes include 4 KB (for 32-bit systems), and 8 KB (for 64-bit systems).* Pages are either valid or invalid.

 A valid page is associated with a page in physical memory, or some secondary backing storage, such as a swap partition or a file on disk. An invalid page is not associated with anything and represents an unused, unallocated piece of the address space.
Accessing such a page causes a segmentation violation. The address space is not necessarily  contiguous. While linearly addressed, it contains plenty of unaddressable  gaps.

7..What is memory region?
The kernel arranges pages into blocks that share certain properties, such as access permissions. These blocks are called memory regions, segments, or mappings.

8..How to allocate dynamic memory?
Memory also comes in the form of automatic and static variables, but the foundation of any memory management system is the allocation, use, and eventual return of dynamic memory. Dynamic memory is allocated at runtime, not compile time, in sizes that may be unknown until the moment of allocation

9..How to free the dynamic memory?
Automatic allocations, which are automatically reaped when the stack
unwinds, dynamic allocations are permanent parts of the process’ address space until they are manually freed

10..How to allocate the aligned memory?
Most part, the compiler and the C library transparently handle alignment
concerns. POSIX decrees that the memory returned via malloc( ), calloc( ), and
realloc( ) be properly aligned for use with any of the standard C types. On Linux,

these functions always return memory that is aligned along an 8 byte boundary on 32-bit systems and a 16 byte boundary on 64-bit systems.

No comments: