Commit cd0373b9 authored by Alessandro Rubini's avatar Alessandro Rubini

core: allocate control structures using an own kmem_cache

Testing /dev/urandom versus zzero-0-1-data (the random device)
shows this increases performance by 0.1 usecs per block. We
are now just over 0.7 usecs per block on my development PC.

This also introduces zio-core.c with generic stuff. We agree that zio-sys
will become zio-sysfs over time.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
Acked-by: 's avatarFederico Vaga <federico.vaga@gmail.com>

Conflicts:

	Makefile
parent ae24b85a
LINUX ?= /lib/modules/$(shell uname -r)/build
zio-objs := zio-cdev.o zio-sys.o
zio-objs := zio-core.o zio-cdev.o zio-sys.o
zio-objs += buffers/zio-buf-kmalloc.o triggers/zio-trig-user.o
obj-m = zio.o
......
......@@ -16,27 +16,6 @@
#define ZIO_DEFAULT_BUFFER "kmalloc" /* For devices with no own buffer type */
/* FIXME: use a kmem_cache and real functions for control alloc/free */
static inline struct zio_control *zio_alloc_control(gfp_t gfp)
{
struct zio_control *ctrl;
ctrl = kzalloc(sizeof(*ctrl), gfp);
if (!ctrl)
return NULL;
ctrl->major_version = ZIO_MAJOR_VERSION;
ctrl->minor_version = ZIO_MINOR_VERSION;
if (ntohl(1) == 1)
ctrl->flags |= ZIO_CONTROL_BIG_ENDIAN;
else
ctrl->flags |= ZIO_CONTROL_LITTLE_ENDIAN;
return ctrl;
}
static inline void zio_free_control(struct zio_control *ctrl)
{
kfree(ctrl);
}
/*
* The following structure defines a buffer type, with methods.
* An instance is created for each channel using it
......@@ -75,6 +54,13 @@ int __must_check zio_register_buf(struct zio_buffer_type *zbuf,
const char *name);
void zio_unregister_buf(struct zio_buffer_type *zbuf);
/* We have our own kmem_cache (a.k.a. slab) for control structures */
int zio_slab_init(void);
void zio_slab_exit(void);
struct zio_control *zio_alloc_control(gfp_t gfp);
void zio_free_control(struct zio_control *ctrl);
struct zio_bi {
struct zio_obj_head head;
struct list_head list; /* instance list */
......
/* Alessandro Rubini, Federico Vaga for CERN, 2011, GNU GPLv2 or later */
/*
* This file includes functions that build up the zio core, but are not
* strictly related to sysfs and configuration. Those are in zio-sysfs.c
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/zio.h>
#include <linux/zio-buffer.h>
/*
* We use a local slab for control structures.
*/
static struct kmem_cache *zio_ctrl_slab;
struct zio_control *zio_alloc_control(gfp_t gfp)
{
struct zio_control *ctrl;
ctrl = kmem_cache_alloc(zio_ctrl_slab, gfp);
if (!ctrl)
return NULL;
ctrl->major_version = ZIO_MAJOR_VERSION;
ctrl->minor_version = ZIO_MINOR_VERSION;
if (ntohl(1) == 1)
ctrl->flags |= ZIO_CONTROL_BIG_ENDIAN;
else
ctrl->flags |= ZIO_CONTROL_LITTLE_ENDIAN;
return ctrl;
}
void zio_free_control(struct zio_control *ctrl)
{
kmem_cache_free(zio_ctrl_slab, ctrl);
}
int __init zio_slab_init(void)
{
zio_ctrl_slab = KMEM_CACHE(zio_control, 0);
if (!zio_ctrl_slab)
return -ENOMEM;
return 0;
}
void zio_slab_exit(void) /* not __exit: called from zio_init on failures */
{
if (zio_ctrl_slab)
kmem_cache_destroy(zio_ctrl_slab);
return;
}
......@@ -1745,6 +1745,9 @@ static int __init zio_init(void)
BUILD_BUG_ON(ZATTR_STD_NUM_ZBUF != ARRAY_SIZE(zio_zbuf_attr_names));
BUILD_BUG_ON(ZATTR_STD_NUM_TRIG != ARRAY_SIZE(zio_trig_attr_names));
err = zio_slab_init();
if (err)
return err;
/* Initialize char device */
err = __zio_register_cdev();
if (err)
......@@ -1774,6 +1777,7 @@ static int __init zio_init(void)
out_kobj:
__zio_unregister_cdev();
out_cdev:
zio_slab_exit();
return err;
}
......@@ -1792,6 +1796,7 @@ static void __exit zio_exit(void)
/* Remove char device */
__zio_unregister_cdev();
zio_slab_exit();
pr_info("zio-core had been unloaded\n");
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment