Skip to content

Instantly share code, notes, and snippets.

@gwydirsam
Created October 12, 2017 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwydirsam/6f25309b720350b6883dc2cd1f398349 to your computer and use it in GitHub Desktop.
Save gwydirsam/6f25309b720350b6883dc2cd1f398349 to your computer and use it in GitHub Desktop.
A small program to
/*
* tlbshoot.c - A program used to test SmartOS TLB shoot down.
*
* This program simply creates a shared memory segment of fixed size
* attaches to the shm segment then detaches repeatedly to cause TLB
* flushes.
*/
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define IPCProtection (0600) /* access/modify by user only */
#define SHMGET_FLAGS (IPC_CREAT | IPC_EXCL | IPCProtection)
#define SHMAT_FLAGS SHM_SHARE_MMU
int main() {
int shmid;
size_t size = 32000000000;
char *shm;
/*
* Create the segment.
*/
if ((shmid = shmget(getpid(), size, SHMGET_FLAGS)) < 0) {
perror("shmget");
exit(1);
}
for (int i = 0;;i++) {
printf("Iteration: %d\n", i);
/*
* Now we attach the segment to our data space.
*/
if ((shm = shmat(shmid, NULL, SHMAT_FLAGS)) == (char *) -1) {
perror("shmat");
exit(1);
}
/*
* Detach
*/
if (shmdt(shm) != 0) {
perror("shmdt");
exit(1);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment