Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Memory helpers |
| 3 | */ |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 4 | #include <sys/types.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <fcntl.h> |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 7 | #include <unistd.h> |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 8 | #include <sys/mman.h> |
| 9 | |
| 10 | #include "fio.h" |
Oleg | a5e0ee1 | 2013-03-12 00:06:53 -0700 | [diff] [blame] | 11 | #ifndef FIO_NO_HAVE_SHM_H |
| 12 | #include <sys/shm.h> |
| 13 | #endif |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 14 | |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 15 | void fio_unpin_memory(struct thread_data *td) |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 16 | { |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 17 | if (td->pinned_mem) { |
| 18 | dprint(FD_MEM, "unpinning %llu bytes\n", td->o.lockmem); |
| 19 | if (munlock(td->pinned_mem, td->o.lockmem) < 0) |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 20 | perror("munlock"); |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 21 | munmap(td->pinned_mem, td->o.lockmem); |
| 22 | td->pinned_mem = NULL; |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 23 | } |
| 24 | } |
| 25 | |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 26 | int fio_pin_memory(struct thread_data *td) |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 27 | { |
| 28 | unsigned long long phys_mem; |
| 29 | |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 30 | if (!td->o.lockmem) |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 31 | return 0; |
| 32 | |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 33 | dprint(FD_MEM, "pinning %llu bytes\n", td->o.lockmem); |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 34 | |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 35 | /* |
| 36 | * Don't allow mlock of more than real_mem-128MB |
| 37 | */ |
| 38 | phys_mem = os_phys_mem(); |
| 39 | if (phys_mem) { |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 40 | if ((td->o.lockmem + 128 * 1024 * 1024) > phys_mem) { |
| 41 | td->o.lockmem = phys_mem - 128 * 1024 * 1024; |
Jens Axboe | b22989b | 2009-07-17 22:29:23 +0200 | [diff] [blame] | 42 | log_info("fio: limiting mlocked memory to %lluMB\n", |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 43 | td->o.lockmem >> 20); |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 47 | td->pinned_mem = mmap(NULL, td->o.lockmem, PROT_READ | PROT_WRITE, |
Jens Axboe | a55820d | 2008-06-04 20:37:18 +0200 | [diff] [blame] | 48 | MAP_PRIVATE | OS_MAP_ANON, -1, 0); |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 49 | if (td->pinned_mem == MAP_FAILED) { |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 50 | perror("malloc locked mem"); |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 51 | td->pinned_mem = NULL; |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 52 | return 1; |
| 53 | } |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 54 | if (mlock(td->pinned_mem, td->o.lockmem) < 0) { |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 55 | perror("mlock"); |
Jens Axboe | 1b79a07 | 2012-03-28 20:50:15 +0200 | [diff] [blame] | 56 | munmap(td->pinned_mem, td->o.lockmem); |
| 57 | td->pinned_mem = NULL; |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 64 | static int alloc_mem_shm(struct thread_data *td, unsigned int total_mem) |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 65 | { |
Jens Axboe | b931a9c | 2015-01-20 18:38:11 -0700 | [diff] [blame] | 66 | #ifndef CONFIG_NO_SHM |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 67 | int flags = IPC_CREAT | S_IRUSR | S_IWUSR; |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 68 | |
Jens Axboe | a1242a2 | 2009-09-12 21:33:51 +0200 | [diff] [blame] | 69 | if (td->o.mem_type == MEM_SHMHUGE) { |
| 70 | unsigned long mask = td->o.hugepage_size - 1; |
| 71 | |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 72 | flags |= SHM_HUGETLB; |
Jens Axboe | a1242a2 | 2009-09-12 21:33:51 +0200 | [diff] [blame] | 73 | total_mem = (total_mem + mask) & ~mask; |
| 74 | } |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 75 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 76 | td->shm_id = shmget(IPC_PRIVATE, total_mem, flags); |
| 77 | dprint(FD_MEM, "shmget %u, %d\n", total_mem, td->shm_id); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 78 | if (td->shm_id < 0) { |
| 79 | td_verror(td, errno, "shmget"); |
Jens Axboe | da7d79b | 2009-09-14 08:51:55 +0200 | [diff] [blame] | 80 | if (geteuid() != 0 && (errno == ENOMEM || errno == EPERM)) |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 81 | log_err("fio: you may need to run this job as root\n"); |
Jens Axboe | 886b878 | 2007-07-19 10:01:03 +0200 | [diff] [blame] | 82 | if (td->o.mem_type == MEM_SHMHUGE) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 83 | if (errno == EINVAL) { |
| 84 | log_err("fio: check that you have free huge" |
| 85 | " pages and that hugepage-size is" |
| 86 | " correct.\n"); |
| 87 | } else if (errno == ENOSYS) { |
| 88 | log_err("fio: your system does not appear to" |
| 89 | " support huge pages.\n"); |
| 90 | } else if (errno == ENOMEM) { |
| 91 | log_err("fio: no huge pages available, do you" |
| 92 | " need to alocate some? See HOWTO.\n"); |
| 93 | } |
Jens Axboe | d8602dd | 2007-07-19 10:00:05 +0200 | [diff] [blame] | 94 | } |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 95 | |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | td->orig_buffer = shmat(td->shm_id, NULL, 0); |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 100 | dprint(FD_MEM, "shmat %d, %p\n", td->shm_id, td->orig_buffer); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 101 | if (td->orig_buffer == (void *) -1) { |
| 102 | td_verror(td, errno, "shmat"); |
| 103 | td->orig_buffer = NULL; |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | return 0; |
Jens Axboe | b931a9c | 2015-01-20 18:38:11 -0700 | [diff] [blame] | 108 | #else |
| 109 | log_err("fio: shm not supported\n"); |
| 110 | return 1; |
| 111 | #endif |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 114 | static void free_mem_shm(struct thread_data *td) |
| 115 | { |
Jens Axboe | b931a9c | 2015-01-20 18:38:11 -0700 | [diff] [blame] | 116 | #ifndef CONFIG_NO_SHM |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 117 | struct shmid_ds sbuf; |
| 118 | |
| 119 | dprint(FD_MEM, "shmdt/ctl %d %p\n", td->shm_id, td->orig_buffer); |
| 120 | shmdt(td->orig_buffer); |
| 121 | shmctl(td->shm_id, IPC_RMID, &sbuf); |
Jens Axboe | b931a9c | 2015-01-20 18:38:11 -0700 | [diff] [blame] | 122 | #endif |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Jens Axboe | 0f805c0 | 2011-03-25 21:36:28 +0100 | [diff] [blame] | 125 | static int alloc_mem_mmap(struct thread_data *td, size_t total_mem) |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 126 | { |
Shaohua Li | d9759b1 | 2013-01-17 13:28:15 +0100 | [diff] [blame] | 127 | int flags = 0; |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 128 | |
Jens Axboe | 5aa6d82 | 2014-10-30 08:40:47 -0600 | [diff] [blame] | 129 | td->mmapfd = -1; |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 130 | |
Jens Axboe | d6dc02f | 2012-11-20 13:39:59 +0100 | [diff] [blame] | 131 | if (td->o.mem_type == MEM_MMAPHUGE) { |
| 132 | unsigned long mask = td->o.hugepage_size - 1; |
| 133 | |
Shaohua Li | d9759b1 | 2013-01-17 13:28:15 +0100 | [diff] [blame] | 134 | /* TODO: make sure the file is a real hugetlbfs file */ |
Jens Axboe | 836fcc0 | 2013-01-24 09:08:45 -0700 | [diff] [blame] | 135 | if (!td->o.mmapfile) |
Shaohua Li | d9759b1 | 2013-01-17 13:28:15 +0100 | [diff] [blame] | 136 | flags |= MAP_HUGETLB; |
Jens Axboe | d6dc02f | 2012-11-20 13:39:59 +0100 | [diff] [blame] | 137 | total_mem = (total_mem + mask) & ~mask; |
| 138 | } |
| 139 | |
Jens Axboe | 83ea422 | 2012-03-28 14:01:46 +0200 | [diff] [blame] | 140 | if (td->o.mmapfile) { |
| 141 | td->mmapfd = open(td->o.mmapfile, O_RDWR|O_CREAT, 0644); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 142 | |
| 143 | if (td->mmapfd < 0) { |
| 144 | td_verror(td, errno, "open mmap file"); |
| 145 | td->orig_buffer = NULL; |
| 146 | return 1; |
| 147 | } |
Shaohua Li | d9759b1 | 2013-01-17 13:28:15 +0100 | [diff] [blame] | 148 | if (td->o.mem_type != MEM_MMAPHUGE && |
| 149 | ftruncate(td->mmapfd, total_mem) < 0) { |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 150 | td_verror(td, errno, "truncate mmap file"); |
| 151 | td->orig_buffer = NULL; |
| 152 | return 1; |
| 153 | } |
Shaohua Li | d9759b1 | 2013-01-17 13:28:15 +0100 | [diff] [blame] | 154 | if (td->o.mem_type == MEM_MMAPHUGE) |
| 155 | flags |= MAP_SHARED; |
| 156 | else |
| 157 | flags |= MAP_PRIVATE; |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 158 | } else |
Shaohua Li | d9759b1 | 2013-01-17 13:28:15 +0100 | [diff] [blame] | 159 | flags |= OS_MAP_ANON | MAP_PRIVATE; |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 160 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 161 | td->orig_buffer = mmap(NULL, total_mem, PROT_READ | PROT_WRITE, flags, |
| 162 | td->mmapfd, 0); |
Jens Axboe | 4b91ee8 | 2013-02-25 10:18:33 +0100 | [diff] [blame] | 163 | dprint(FD_MEM, "mmap %llu/%d %p\n", (unsigned long long) total_mem, |
| 164 | td->mmapfd, td->orig_buffer); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 165 | if (td->orig_buffer == MAP_FAILED) { |
| 166 | td_verror(td, errno, "mmap"); |
| 167 | td->orig_buffer = NULL; |
Jens Axboe | e0ba571 | 2015-01-05 08:50:41 -0700 | [diff] [blame] | 168 | if (td->mmapfd != 1 && td->mmapfd != -1) { |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 169 | close(td->mmapfd); |
Jens Axboe | b3493a7 | 2014-04-14 13:20:38 -0600 | [diff] [blame] | 170 | if (td->o.mmapfile) |
| 171 | unlink(td->o.mmapfile); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 172 | } |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 173 | |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 174 | return 1; |
| 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
Jens Axboe | 0f805c0 | 2011-03-25 21:36:28 +0100 | [diff] [blame] | 180 | static void free_mem_mmap(struct thread_data *td, size_t total_mem) |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 181 | { |
Jens Axboe | 4b91ee8 | 2013-02-25 10:18:33 +0100 | [diff] [blame] | 182 | dprint(FD_MEM, "munmap %llu %p\n", (unsigned long long) total_mem, |
| 183 | td->orig_buffer); |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 184 | munmap(td->orig_buffer, td->orig_buffer_size); |
Jens Axboe | 83ea422 | 2012-03-28 14:01:46 +0200 | [diff] [blame] | 185 | if (td->o.mmapfile) { |
Jens Axboe | 5aa6d82 | 2014-10-30 08:40:47 -0600 | [diff] [blame] | 186 | if (td->mmapfd != -1) |
| 187 | close(td->mmapfd); |
Jens Axboe | 83ea422 | 2012-03-28 14:01:46 +0200 | [diff] [blame] | 188 | unlink(td->o.mmapfile); |
| 189 | free(td->o.mmapfile); |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 190 | } |
| 191 | } |
Jens Axboe | d87612a | 2007-07-19 15:06:57 +0200 | [diff] [blame] | 192 | |
Jens Axboe | 0f805c0 | 2011-03-25 21:36:28 +0100 | [diff] [blame] | 193 | static int alloc_mem_malloc(struct thread_data *td, size_t total_mem) |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 194 | { |
| 195 | td->orig_buffer = malloc(total_mem); |
Jens Axboe | 4b91ee8 | 2013-02-25 10:18:33 +0100 | [diff] [blame] | 196 | dprint(FD_MEM, "malloc %llu %p\n", (unsigned long long) total_mem, |
| 197 | td->orig_buffer); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 198 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 199 | return td->orig_buffer == NULL; |
| 200 | } |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 201 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 202 | static void free_mem_malloc(struct thread_data *td) |
| 203 | { |
| 204 | dprint(FD_MEM, "free malloc mem %p\n", td->orig_buffer); |
| 205 | free(td->orig_buffer); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 208 | /* |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 209 | * Set up the buffer area we need for io. |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 210 | */ |
| 211 | int allocate_io_mem(struct thread_data *td) |
| 212 | { |
Jens Axboe | 0f805c0 | 2011-03-25 21:36:28 +0100 | [diff] [blame] | 213 | size_t total_mem; |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 214 | int ret = 0; |
| 215 | |
Jens Axboe | b4c5e1a | 2007-10-25 18:44:45 +0200 | [diff] [blame] | 216 | if (td->io_ops->flags & FIO_NOIO) |
| 217 | return 0; |
| 218 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 219 | total_mem = td->orig_buffer_size; |
Jens Axboe | d529ee1 | 2009-07-01 10:33:03 +0200 | [diff] [blame] | 220 | |
Chris Mason | d01612f | 2013-11-15 15:52:58 -0700 | [diff] [blame] | 221 | if (td->o.odirect || td->o.mem_align || td->o.oatomic || |
Jens Axboe | ca7e0dd | 2010-10-28 08:52:13 -0600 | [diff] [blame] | 222 | (td->io_ops->flags & FIO_MEMALIGN)) { |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 223 | total_mem += page_mask; |
Jens Axboe | d529ee1 | 2009-07-01 10:33:03 +0200 | [diff] [blame] | 224 | if (td->o.mem_align && td->o.mem_align > page_size) |
| 225 | total_mem += td->o.mem_align - page_size; |
| 226 | } |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 227 | |
Jens Axboe | 4b91ee8 | 2013-02-25 10:18:33 +0100 | [diff] [blame] | 228 | dprint(FD_MEM, "Alloc %llu for buffers\n", (unsigned long long) total_mem); |
Jens Axboe | 0f805c0 | 2011-03-25 21:36:28 +0100 | [diff] [blame] | 229 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 230 | if (td->o.mem_type == MEM_MALLOC) |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 231 | ret = alloc_mem_malloc(td, total_mem); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 232 | else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE) |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 233 | ret = alloc_mem_shm(td, total_mem); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 234 | else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE) |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 235 | ret = alloc_mem_mmap(td, total_mem); |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 236 | else { |
| 237 | log_err("fio: bad mem type: %d\n", td->o.mem_type); |
| 238 | ret = 1; |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Jens Axboe | 3deb310 | 2007-04-26 15:24:20 +0200 | [diff] [blame] | 241 | if (ret) |
| 242 | td_verror(td, ENOMEM, "iomem allocation"); |
| 243 | |
Jens Axboe | b6f9676 | 2007-04-17 19:48:46 +0200 | [diff] [blame] | 244 | return ret; |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void free_io_mem(struct thread_data *td) |
| 248 | { |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 249 | unsigned int total_mem; |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 250 | |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 251 | total_mem = td->orig_buffer_size; |
Chris Mason | d01612f | 2013-11-15 15:52:58 -0700 | [diff] [blame] | 252 | if (td->o.odirect || td->o.oatomic) |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 253 | total_mem += page_mask; |
| 254 | |
| 255 | if (td->o.mem_type == MEM_MALLOC) |
| 256 | free_mem_malloc(td); |
| 257 | else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE) |
| 258 | free_mem_shm(td); |
| 259 | else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE) |
| 260 | free_mem_mmap(td, total_mem); |
| 261 | else |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 262 | log_err("Bad memory type %u\n", td->o.mem_type); |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 263 | |
| 264 | td->orig_buffer = NULL; |
Jens Axboe | 829a602 | 2009-07-01 09:00:52 +0200 | [diff] [blame] | 265 | td->orig_buffer_size = 0; |
Jens Axboe | 2f9ade3 | 2006-10-20 11:25:52 +0200 | [diff] [blame] | 266 | } |