• Home
  • Raw
  • Download

Lines Matching refs:td

15 void fio_unpin_memory(struct thread_data *td)  in fio_unpin_memory()  argument
17 if (td->pinned_mem) { in fio_unpin_memory()
18 dprint(FD_MEM, "unpinning %llu bytes\n", td->o.lockmem); in fio_unpin_memory()
19 if (munlock(td->pinned_mem, td->o.lockmem) < 0) in fio_unpin_memory()
21 munmap(td->pinned_mem, td->o.lockmem); in fio_unpin_memory()
22 td->pinned_mem = NULL; in fio_unpin_memory()
26 int fio_pin_memory(struct thread_data *td) in fio_pin_memory() argument
30 if (!td->o.lockmem) in fio_pin_memory()
33 dprint(FD_MEM, "pinning %llu bytes\n", td->o.lockmem); in fio_pin_memory()
40 if ((td->o.lockmem + 128 * 1024 * 1024) > phys_mem) { in fio_pin_memory()
41 td->o.lockmem = phys_mem - 128 * 1024 * 1024; in fio_pin_memory()
43 td->o.lockmem >> 20); in fio_pin_memory()
47 td->pinned_mem = mmap(NULL, td->o.lockmem, PROT_READ | PROT_WRITE, in fio_pin_memory()
49 if (td->pinned_mem == MAP_FAILED) { in fio_pin_memory()
51 td->pinned_mem = NULL; in fio_pin_memory()
54 if (mlock(td->pinned_mem, td->o.lockmem) < 0) { in fio_pin_memory()
56 munmap(td->pinned_mem, td->o.lockmem); in fio_pin_memory()
57 td->pinned_mem = NULL; in fio_pin_memory()
64 static int alloc_mem_shm(struct thread_data *td, unsigned int total_mem) in alloc_mem_shm() argument
69 if (td->o.mem_type == MEM_SHMHUGE) { in alloc_mem_shm()
70 unsigned long mask = td->o.hugepage_size - 1; in alloc_mem_shm()
76 td->shm_id = shmget(IPC_PRIVATE, total_mem, flags); in alloc_mem_shm()
77 dprint(FD_MEM, "shmget %u, %d\n", total_mem, td->shm_id); in alloc_mem_shm()
78 if (td->shm_id < 0) { in alloc_mem_shm()
79 td_verror(td, errno, "shmget"); in alloc_mem_shm()
82 if (td->o.mem_type == MEM_SHMHUGE) { in alloc_mem_shm()
99 td->orig_buffer = shmat(td->shm_id, NULL, 0); in alloc_mem_shm()
100 dprint(FD_MEM, "shmat %d, %p\n", td->shm_id, td->orig_buffer); in alloc_mem_shm()
101 if (td->orig_buffer == (void *) -1) { in alloc_mem_shm()
102 td_verror(td, errno, "shmat"); in alloc_mem_shm()
103 td->orig_buffer = NULL; in alloc_mem_shm()
114 static void free_mem_shm(struct thread_data *td) in free_mem_shm() argument
119 dprint(FD_MEM, "shmdt/ctl %d %p\n", td->shm_id, td->orig_buffer); in free_mem_shm()
120 shmdt(td->orig_buffer); in free_mem_shm()
121 shmctl(td->shm_id, IPC_RMID, &sbuf); in free_mem_shm()
125 static int alloc_mem_mmap(struct thread_data *td, size_t total_mem) in alloc_mem_mmap() argument
129 td->mmapfd = -1; in alloc_mem_mmap()
131 if (td->o.mem_type == MEM_MMAPHUGE) { in alloc_mem_mmap()
132 unsigned long mask = td->o.hugepage_size - 1; in alloc_mem_mmap()
135 if (!td->o.mmapfile) in alloc_mem_mmap()
140 if (td->o.mmapfile) { in alloc_mem_mmap()
141 td->mmapfd = open(td->o.mmapfile, O_RDWR|O_CREAT, 0644); in alloc_mem_mmap()
143 if (td->mmapfd < 0) { in alloc_mem_mmap()
144 td_verror(td, errno, "open mmap file"); in alloc_mem_mmap()
145 td->orig_buffer = NULL; in alloc_mem_mmap()
148 if (td->o.mem_type != MEM_MMAPHUGE && in alloc_mem_mmap()
149 td->o.mem_type != MEM_MMAPSHARED && in alloc_mem_mmap()
150 ftruncate(td->mmapfd, total_mem) < 0) { in alloc_mem_mmap()
151 td_verror(td, errno, "truncate mmap file"); in alloc_mem_mmap()
152 td->orig_buffer = NULL; in alloc_mem_mmap()
155 if (td->o.mem_type == MEM_MMAPHUGE || in alloc_mem_mmap()
156 td->o.mem_type == MEM_MMAPSHARED) in alloc_mem_mmap()
163 td->orig_buffer = mmap(NULL, total_mem, PROT_READ | PROT_WRITE, flags, in alloc_mem_mmap()
164 td->mmapfd, 0); in alloc_mem_mmap()
166 td->mmapfd, td->orig_buffer); in alloc_mem_mmap()
167 if (td->orig_buffer == MAP_FAILED) { in alloc_mem_mmap()
168 td_verror(td, errno, "mmap"); in alloc_mem_mmap()
169 td->orig_buffer = NULL; in alloc_mem_mmap()
170 if (td->mmapfd != 1 && td->mmapfd != -1) { in alloc_mem_mmap()
171 close(td->mmapfd); in alloc_mem_mmap()
172 if (td->o.mmapfile) in alloc_mem_mmap()
173 unlink(td->o.mmapfile); in alloc_mem_mmap()
182 static void free_mem_mmap(struct thread_data *td, size_t total_mem) in free_mem_mmap() argument
185 td->orig_buffer); in free_mem_mmap()
186 munmap(td->orig_buffer, td->orig_buffer_size); in free_mem_mmap()
187 if (td->o.mmapfile) { in free_mem_mmap()
188 if (td->mmapfd != -1) in free_mem_mmap()
189 close(td->mmapfd); in free_mem_mmap()
190 unlink(td->o.mmapfile); in free_mem_mmap()
191 free(td->o.mmapfile); in free_mem_mmap()
195 static int alloc_mem_malloc(struct thread_data *td, size_t total_mem) in alloc_mem_malloc() argument
197 td->orig_buffer = malloc(total_mem); in alloc_mem_malloc()
199 td->orig_buffer); in alloc_mem_malloc()
201 return td->orig_buffer == NULL; in alloc_mem_malloc()
204 static void free_mem_malloc(struct thread_data *td) in free_mem_malloc() argument
206 dprint(FD_MEM, "free malloc mem %p\n", td->orig_buffer); in free_mem_malloc()
207 free(td->orig_buffer); in free_mem_malloc()
210 static int alloc_mem_cudamalloc(struct thread_data *td, size_t total_mem) in alloc_mem_cudamalloc() argument
222 ret = cuDeviceGetCount(&td->gpu_dev_cnt); in alloc_mem_cudamalloc()
227 dprint(FD_MEM, "found %d GPU devices\n", td->gpu_dev_cnt); in alloc_mem_cudamalloc()
229 if (td->gpu_dev_cnt == 0) { in alloc_mem_cudamalloc()
235 td->gpu_dev_id = td->o.gpu_dev_id; in alloc_mem_cudamalloc()
236 ret = cuDeviceGet(&td->cu_dev, td->gpu_dev_id); in alloc_mem_cudamalloc()
242 ret = cuDeviceGetName(name, sizeof(name), td->gpu_dev_id); in alloc_mem_cudamalloc()
248 td->gpu_dev_id, name); in alloc_mem_cudamalloc()
250 ret = cuCtxCreate(&td->cu_ctx, CU_CTX_MAP_HOST, td->cu_dev); in alloc_mem_cudamalloc()
256 ret = cuMemAlloc(&td->dev_mem_ptr, total_mem); in alloc_mem_cudamalloc()
261 td->orig_buffer = (void *) td->dev_mem_ptr; in alloc_mem_cudamalloc()
264 (unsigned long long) total_mem, td->orig_buffer); in alloc_mem_cudamalloc()
271 static void free_mem_cudamalloc(struct thread_data *td) in free_mem_cudamalloc() argument
274 if (td->dev_mem_ptr != NULL) in free_mem_cudamalloc()
275 cuMemFree(td->dev_mem_ptr); in free_mem_cudamalloc()
277 if (cuCtxDestroy(td->cu_ctx) != CUDA_SUCCESS) in free_mem_cudamalloc()
285 int allocate_io_mem(struct thread_data *td) in allocate_io_mem() argument
290 if (td_ioengine_flagged(td, FIO_NOIO)) in allocate_io_mem()
293 total_mem = td->orig_buffer_size; in allocate_io_mem()
295 if (td->o.odirect || td->o.mem_align || td->o.oatomic || in allocate_io_mem()
296 td_ioengine_flagged(td, FIO_MEMALIGN)) { in allocate_io_mem()
298 if (td->o.mem_align && td->o.mem_align > page_size) in allocate_io_mem()
299 total_mem += td->o.mem_align - page_size; in allocate_io_mem()
308 if (td->io_ops->iomem_alloc) { in allocate_io_mem()
309 if (fio_option_is_set(&td->o, mem_type)) { in allocate_io_mem()
313 ret = td->io_ops->iomem_alloc(td, total_mem); in allocate_io_mem()
314 } else if (td->o.mem_type == MEM_MALLOC) in allocate_io_mem()
315 ret = alloc_mem_malloc(td, total_mem); in allocate_io_mem()
316 else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE) in allocate_io_mem()
317 ret = alloc_mem_shm(td, total_mem); in allocate_io_mem()
318 else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE || in allocate_io_mem()
319 td->o.mem_type == MEM_MMAPSHARED) in allocate_io_mem()
320 ret = alloc_mem_mmap(td, total_mem); in allocate_io_mem()
321 else if (td->o.mem_type == MEM_CUDA_MALLOC) in allocate_io_mem()
322 ret = alloc_mem_cudamalloc(td, total_mem); in allocate_io_mem()
324 log_err("fio: bad mem type: %d\n", td->o.mem_type); in allocate_io_mem()
329 td_verror(td, ENOMEM, "iomem allocation"); in allocate_io_mem()
334 void free_io_mem(struct thread_data *td) in free_io_mem() argument
338 total_mem = td->orig_buffer_size; in free_io_mem()
339 if (td->o.odirect || td->o.oatomic) in free_io_mem()
342 if (td->io_ops->iomem_alloc) { in free_io_mem()
343 if (td->io_ops->iomem_free) in free_io_mem()
344 td->io_ops->iomem_free(td); in free_io_mem()
345 } else if (td->o.mem_type == MEM_MALLOC) in free_io_mem()
346 free_mem_malloc(td); in free_io_mem()
347 else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE) in free_io_mem()
348 free_mem_shm(td); in free_io_mem()
349 else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE || in free_io_mem()
350 td->o.mem_type == MEM_MMAPSHARED) in free_io_mem()
351 free_mem_mmap(td, total_mem); in free_io_mem()
352 else if (td->o.mem_type == MEM_CUDA_MALLOC) in free_io_mem()
353 free_mem_cudamalloc(td); in free_io_mem()
355 log_err("Bad memory type %u\n", td->o.mem_type); in free_io_mem()
357 td->orig_buffer = NULL; in free_io_mem()
358 td->orig_buffer_size = 0; in free_io_mem()