Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * test_free_pages.c: Check that free_pages() doesn't leak memory
0004  * Copyright (c) 2020 Oracle
0005  * Author: Matthew Wilcox <willy@infradead.org>
0006  */
0007 
0008 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0009 
0010 #include <linux/gfp.h>
0011 #include <linux/mm.h>
0012 #include <linux/module.h>
0013 
0014 static void test_free_pages(gfp_t gfp)
0015 {
0016     unsigned int i;
0017 
0018     for (i = 0; i < 1000 * 1000; i++) {
0019         unsigned long addr = __get_free_pages(gfp, 3);
0020         struct page *page = virt_to_page((void *)addr);
0021 
0022         /* Simulate page cache getting a speculative reference */
0023         get_page(page);
0024         free_pages(addr, 3);
0025         put_page(page);
0026     }
0027 }
0028 
0029 static int m_in(void)
0030 {
0031     pr_info("Testing with GFP_KERNEL\n");
0032     test_free_pages(GFP_KERNEL);
0033     pr_info("Testing with GFP_KERNEL | __GFP_COMP\n");
0034     test_free_pages(GFP_KERNEL | __GFP_COMP);
0035     pr_info("Test completed\n");
0036 
0037     return 0;
0038 }
0039 
0040 static void m_ex(void)
0041 {
0042 }
0043 
0044 module_init(m_in);
0045 module_exit(m_ex);
0046 MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
0047 MODULE_LICENSE("GPL");