Wednesday, September 30, 2015

MEMORY MANAGEMENT - 2

     MEMORY MANAGEMENT INTERVIEW QUESTIONS AND ANSWERS
                                                
                                                PAGE - 2



11..How to manage the  data segment?
Linux  systems historically have provided interfaces for directly managing the data segment. However, most programs have no direct use for these interfaces because malloc( ) and other allocation schemes are easier to use and more powerful

12..How to create the anonymous memory mappings?
Use of a memory mapping over the heap for a specific allocation, or perhaps because you are writing your own memory allocation system, you may want to manually create your own anonymous memory mapping—either, way, Linux makes it easy.

13..How to debugging memory allocations?
Programs can set the environment variable MALLOC_CHECK_ to enable enhanced debugging in the memory subsystem. The additional debugging checks come at the expense of less efficient memory allocations, but the overhead is often worth it during the debugging stage of application development. You can check with the following command
$ MALLOC_CHECK_=1 ./rudder

14..How to lock the virtual memory?
A call to mlock( ) locks the virtual memory starting at addr, and extending for
Len bytes into physical memory.

15..How to lock the all address space?
A call to mlockall( ) locks all of the pages in the current process’ address space into physical memory.

16..How to unlock the memory?
The system call munlock( ) unlocks the pages starting at addr and extending for len bytes. It undoes the effects of mlock( ).

17..How to find out  the page is physical memory or not?
Linux provides the mincore( ) function, which can be used to determine whether a given range of memory is in physical memory, or swapped out to disk:

#include <unistd.h>
#include <sys/mman.h>
int mincore (void *start,
size_t length,
unsigned char *vec);

A call to mincore( ) provides a vector delineating which pages of a mapping are in physical memory at the time of the system call. The call returns the vector via vec, and describes the pages starting at start  and extending for length bytes.

Each byte in vec corresponds to one page in the range provided, starting with the first byte describing the first page, and moving linearly forward. Consequently, vec must be at least large enough to contain (length - 1 + page size) / page size bytes. The lowest-order bit in each byte is 1 if the page is resident in physical memory, and 0 if it is not. The other bits are currently undefined and reserved for future use.

18..What is Min / Max Spare Servers?
These options are used to create a pool of spare servers that Apache can use
when it is busy. Larger sites may wish to increase these numbers from their defaults. However, for each spare server, more memory is required on  the server.

19..What is memory optimizations?
User-space code and data, kernel code and data reside permanently in main
memory, so it is important to reduce memory waste in every way possible. Initialization code is a good candidate for memory optimization. Given their nature, most initialization routines are executed either just once or not at all, depending on the kernel configuration

20..What is System Memory Management?
One of the primary functions of the operating system kernel is memory management. Not only does the kernel manage the physical memory available on the server, but it can also create and manage virtual memory, or memory that does not actually exist.

It does this by using space on the hard disk, called the swap space. The kernel swaps the contents of virtual memory locations back and forth from the swap space to the actual physical memory. This allows the system to think there is more memory available than what physically exists


No comments: