Do hugepages guarantee a single tlb entry in the kernel driver when allocated with alloc_pages(GFP_KERNEL | __GFP_COMP)?

39 Views Asked by At

On a 5.19 linux kernel with transparent hugepages enabled (/sys/kernel/mm/transparent_hugepage/enabled set to "always"), I am using the following code to allocate a hugepage in a kernel module:

static struct page* allocate_hugepage(void)
{
    struct page *page;

    // Allocate a 2MB hugepage
    page = alloc_pages(GFP_KERNEL | __GFP_COMP , 9); //Allocates 2**9=512 pages
    if (!page) {
        printk(KERN_ERR "Failed to allocate hugepage\n");
        return NULL;
    }

    // Map the page to a kernel virtual address
    return page;
}

static int __init lkm_example_init(void)
{
    struct page *hugepage = allocate_hugepage();
    BUG_ON(!hugepage);
    [...]
}

This code seems to work -- it gives me 2Mib of physical continuous memory. However, I am not sure whether this page is actually a hugepage in the sense that it only has one tlb entry (as opposed to 512 entries for all the 4KB pages). How can i confirm that?

0

There are 0 best solutions below