Re: Page allocation and de-allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Sorry for the confusion. I include how I wrote the page allocation and de-allocation code at the end of this email. And the full source code is attached as well.
 

Using vmalloc? So it's a large array. Thousands of entries, right?
Yes. The array is vmalloc-ed. So the array can have many entries.
 

> and each page is allocated by get_free_page(GFP_ATOMIC). And after
                                             ^
              You are NOT using get_free_pages, right?
My design is: each element of the array can only hold one page of memory. So I just use get_free_page, not get_free_pages.


Not really. Memory allocation is a tricky area. You need to show the real
code. Not just explanation -- actual code that does not work for you.
Here is the code:

#This is the part of page allocation
        // alloc page array
        pg_array = (void *)vmalloc(nr_pages * sizeof(void *));
        if (!pg_array) {
            printk("<1>error vmalloc pg_array\n");
            goto jump;
        } else {
            for (i = 0; i < nr_pages; i++) {
                pg_array[i] = NULL;
            }
            for (i = 0; i < nr_pages; i++) {
                pg_array[i] = (void *)get_free_page(GFP_ATOMIC);
                if (!pg_array[i]) {
                    printk("<1>error get_free_page pg_array[%lu]\n", i);
                }
            }
        }
 


# This is the part of the page de-allocation
        if (pg_array) {
            for (i = 0; i < nr_pages; i++)
                if (pg_array[i]) {
                    __free_page(pg_array[i]);
                    pg_array[i] = NULL;
                }
            vfree(pg_array);
            pg_array = NULL;
        }


Note: The full source code is included in the attachment. Thanks for your help.



Best Regards!

Fei

Attachment: client-mem.c
Description: Binary data


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux