NetApp Interview Question for Interns

Country: United States

Comment hidden because of low score. Click to expand.
of 0 vote

Basically this is an implementation for kernel's version of malloc called kmalloc ...

phys_mem_t phys_mem_get_pages (uint32_t pages, uint32_t align)
static uint32_t current=0;
uint32_t stride = (1<<(align-1));
uint32_t mask = ~(stride-1);
uint32_t first;
int wrapped=0;
int found=0;
int i;

current &= mask; /* adjust for alignment */
first = current; /* keep track of where we started */

/* find a properly aligned bit */
found = get_bit (bitmap,current); // bitmap is an array representing 1 bit for a page in phy memory ... and a 1 represnts it is used and a 0 unused ...
while(!wrapped && !found)
current += stride;
if((current+pages) > ARCH_NUM_PAGES) // ARCH_NUM_PAGES is the no. of free pages in the memory ...
found = get_bit(bitmap,current);

/* now see if there are enough contiguous bits */
found &= get_bit(bitmap,i);
while(!wrapped && !found);

/* if(found) */
/* kprintf("found a bit at %08X\n\r",current); */
/* else */
/* kprintf("nothing found at %08X\n\r",current); */

/* if there is no set of bits to satisfy the request, then return
error code */

/* otherwise, clear the bits and return the address */
num_free -= pages;

#ifdef DEBUG
kprintf("phys_mem_get_pages returning %08X\n\r",current<<PAGE_BITS);
return current<<PAGE_BITS;

- Vikas May 23, 2012 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More