Skip to content

Instantly share code, notes, and snippets.

@ethercflow
Created September 5, 2019 09:07
Show Gist options
  • Select an option

  • Save ethercflow/58f81189ed6e760b99a78f48484eb60b to your computer and use it in GitHub Desktop.

Select an option

Save ethercflow/58f81189ed6e760b99a78f48484eb60b to your computer and use it in GitHub Desktop.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#define N 100000
#define ORDER 2 * 2 * 2
static char *mems[N_MEM];
static int
frag_init(void)
{
size_t i;
for (i = 0; i < N; i++)
mems[i] = kzalloc(4096 * order, GFP_KERNEL);
return 0;
}
static void
frag_exit(void)
{
size_t i;
for (i = 0; i < N_MEM; i += 2)
kfree(mems[i]);
}
module_init(frag_init);
module_exit(frag_exit);
MODULE_LICENSE("GPL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment