xfs: test that reflink forces the log if mounted with wsync
[xfstests-dev.git] / src / usemem.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6  
7 /*
8  *
9  * usemem: allocate and lock a chunk of memory effectively removing
10  *         it from the usable physical memory range
11  *
12  *                                                  - dxm 04/10/00
13  */
14
15 #include <stdio.h>
16 #include <malloc.h>
17 #include <sys/mman.h>
18 #include <stdlib.h>
19 #include <sys/types.h>
20 #include <sys/wait.h>
21 #include <signal.h>
22 #include <unistd.h>
23
24 void
25 usage(char *argv0)
26 {
27     fprintf(stderr,"Usage: %s <mb>\n", argv0);
28     exit(1);
29 }
30
31 static void
32 signalled(int sig)
33 {
34     printf("*** signal\n");
35 }
36
37 int
38 main(int argc, char *argv[])
39 {
40     int mb;
41     char *buf;
42     
43     if (argc!=2) usage(argv[0]);
44     mb=atoi(argv[1]);
45     if (mb<=0) usage(argv[0]);
46     
47     buf=malloc(mb*1024*1024);
48     if (!buf) {
49         perror("malloc");
50         exit(1);
51     }
52     if (mlock(buf,mb*1024*1024)) {
53         perror("mlock");
54         exit(1);
55     }
56     
57     printf("%s: %d mb locked - interrupt to release\n", argv[0], mb);
58     signal(SIGINT, signalled);
59     pause();
60     printf("%s: %d mb unlocked\n", argv[0], mb);
61     
62     return 0;
63 }
64
65