Flexible I/O Tester development
 help / color / mirror / Atom feed
* [PATCH]: Let I/O engine provide methods to allocate/free I/O memory.
@ 2016-02-23 21:16 Andrey Kuzmin
  2016-02-23 21:57 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Andrey Kuzmin @ 2016-02-23 21:16 UTC (permalink / raw)
  To: Jens Axboe; +Cc: fio@vger.kernel.org


[-- Attachment #1.1: Type: text/plain, Size: 1897 bytes --]

I/O engine may have special needs as to how the I/O memory should be
allocated. The below patch adds respective methods to the I/O engine
interface.

Regards,
Andrey

diff --git a/ioengine.h b/ioengine.h
index 6734c7b..161acf5 100644
--- a/ioengine.h
+++ b/ioengine.h
@@ -16,7 +16,7 @@
 #include <guasi.h>
 #endif

-#define FIO_IOOPS_VERSION    22
+#define FIO_IOOPS_VERSION    23

 enum {
     IO_U_F_FREE        = 1 << 0,
@@ -157,6 +157,8 @@ struct ioengine_ops {
     int (*unlink_file)(struct thread_data *, struct fio_file *);
     int (*get_file_size)(struct thread_data *, struct fio_file *);
     void (*terminate)(struct thread_data *);
+    int (*iomem_alloc)(struct thread_data *, size_t);
+    void (*iomem_free)(struct thread_data *);
     int (*io_u_init)(struct thread_data *, struct io_u *);
     void (*io_u_free)(struct thread_data *, struct io_u *);
     int option_struct_size;
diff --git a/memory.c b/memory.c
index 5060223..4d5d474 100644
--- a/memory.c
+++ b/memory.c
@@ -229,7 +229,9 @@ int allocate_io_mem(struct thread_data *td)

     dprint(FD_MEM, "Alloc %llu for buffers\n", (unsigned long long)
total_mem);

-    if (td->o.mem_type == MEM_MALLOC)
+    if (td->io_ops->iomem_alloc)
+        ret = td->io_ops->iomem_alloc(td, total_mem);
+    else if (td->o.mem_type == MEM_MALLOC)
         ret = alloc_mem_malloc(td, total_mem);
     else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE)
         ret = alloc_mem_shm(td, total_mem);
@@ -255,7 +257,9 @@ void free_io_mem(struct thread_data *td)
     if (td->o.odirect || td->o.oatomic)
         total_mem += page_mask;

-    if (td->o.mem_type == MEM_MALLOC)
+    if (td->io_ops->iomem_free)
+        td->io_ops->iomem_free(td);
+    else if (td->o.mem_type == MEM_MALLOC)
         free_mem_malloc(td);
     else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE)
         free_mem_shm(td);

[-- Attachment #1.2: Type: text/html, Size: 2295 bytes --]

[-- Attachment #2: Let-io-engine-allocate-io-memory.patch --]
[-- Type: text/x-patch, Size: 1624 bytes --]

diff --git a/ioengine.h b/ioengine.h
index 6734c7b..161acf5 100644
--- a/ioengine.h
+++ b/ioengine.h
@@ -16,7 +16,7 @@
 #include <guasi.h>
 #endif
 
-#define FIO_IOOPS_VERSION	22
+#define FIO_IOOPS_VERSION	23
 
 enum {
 	IO_U_F_FREE		= 1 << 0,
@@ -157,6 +157,8 @@ struct ioengine_ops {
 	int (*unlink_file)(struct thread_data *, struct fio_file *);
 	int (*get_file_size)(struct thread_data *, struct fio_file *);
 	void (*terminate)(struct thread_data *);
+	int (*iomem_alloc)(struct thread_data *, size_t);
+	void (*iomem_free)(struct thread_data *);
 	int (*io_u_init)(struct thread_data *, struct io_u *);
 	void (*io_u_free)(struct thread_data *, struct io_u *);
 	int option_struct_size;
diff --git a/memory.c b/memory.c
index 5060223..4d5d474 100644
--- a/memory.c
+++ b/memory.c
@@ -229,7 +229,9 @@ int allocate_io_mem(struct thread_data *td)
 
 	dprint(FD_MEM, "Alloc %llu for buffers\n", (unsigned long long) total_mem);
 
-	if (td->o.mem_type == MEM_MALLOC)
+	if (td->io_ops->iomem_alloc)
+		ret = td->io_ops->iomem_alloc(td, total_mem);
+	else if (td->o.mem_type == MEM_MALLOC)
 		ret = alloc_mem_malloc(td, total_mem);
 	else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE)
 		ret = alloc_mem_shm(td, total_mem);
@@ -255,7 +257,9 @@ void free_io_mem(struct thread_data *td)
 	if (td->o.odirect || td->o.oatomic)
 		total_mem += page_mask;
 
-	if (td->o.mem_type == MEM_MALLOC)
+	if (td->io_ops->iomem_free)
+		td->io_ops->iomem_free(td);
+	else if (td->o.mem_type == MEM_MALLOC)
 		free_mem_malloc(td);
 	else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE)
 		free_mem_shm(td);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-23 22:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-23 21:16 [PATCH]: Let I/O engine provide methods to allocate/free I/O memory Andrey Kuzmin
2016-02-23 21:57 ` Jens Axboe
2016-02-23 22:02   ` Andrey Kuzmin
2016-02-23 22:04     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox