Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Hardware

ARM

What am I trying to do: Answer: I am trying to create memory fragmentation on a Linux 2.6.31 based swapless embedded device.

Why: Answer:I am trying to port some patches to Linux 2.6.31 that will defragment the fragmented memory. In order to test if those patches are working correctly I'd like to try to fragment the memory first.

I learnt that continuous allocation and deallocation of memory by apps can lead to fragmentation. Therefore I wrote these simple C programs.

#include <stdio.h>
#include <stdlib.h>

int main(void) {

    srand(time(NULL));
    int i = 0, j = 0, randnum=0;
    while(1) {

        randnum = rand()%10000000;
        double *ptr = (double*) malloc(sizeof(*ptr) * randnum);

        for(j = 0 ; j < randnum; j++) {
            *(ptr+j) = (double)j+1;
        }

        free(ptr);
    }
}

==========

#include <stdio.h>
#include <stdlib.h>

int main(void) {

    srand(time(NULL));
    int i = 0, j = 0, randnum=0;
    int arr[6] = { 3072, 7168, 15360 , 31744, 64512, 130048}; 
    while(1) {

        for (i = 0; i < 6 ; i++) {

            int *ptr = (int*) malloc(arr[i] * 93);  

            for(j = 0 ; j < arr[i] * 93 / sizeof(int); j++) {
                *(ptr+j) = j+1;
            }

            free(ptr);
        }
    }       
}

How do I measure if memory is fragmented?: Answer:I look at the o/p of /proc/buddyinfo

What do I need:? Can you suggest a better way to fragment the memory? Because those C programs work but very very slowly.

share|improve this question
    
what is your hardware? –  user55518 Mar 7 at 1:08
    
Maybe some sample here can help. –  Amphiteóth Mar 7 at 2:17
    
@bersch Hardware is ARM. –  abc Mar 8 at 21:30
    
Why do you think you need to defragment the memory? "An MMU also mitigates the problem of fragmentation of memory" and "ARM architecture-based application processors implement an MMU defined by ARM's virtual memory system architecture" Source MMU –  user55518 Mar 8 at 21:42
    
@bersch I want to fragment and not defragment the memory. –  abc Mar 9 at 5:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.