4 * Copyright (C) 2006 Vladislav Bolkhovitin <vst@vlnb.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <asm/scatterlist.h>
19 #define SGV_POOL_ELEMENTS 11
21 #if defined(DEBUG) && defined(CONFIG_DEBUG_SLAB)
22 #define SCST_SLAB_FLAGS ( SLAB_RED_ZONE | SLAB_POISON )
24 #define SCST_SLAB_FLAGS 0L
28 * sg_num is indexed by the page number, pg_count is indexed by the sg number.
29 * Made in one entry to simplify the code (eg all sizeof(*) parts) and save
30 * the CPU cache for non-clustered case.
32 struct trans_tbl_ent {
33 unsigned short sg_num;
34 unsigned short pg_count;
39 struct kmem_cache *owner_cache;
44 struct scatterlist *entries;
45 struct trans_tbl_ent trans_tbl[0];
50 atomic_t total_alloc, hit_alloc;
55 struct sgv_pool_acc acc;
56 struct sgv_pool_acc cache_acc[SGV_POOL_ELEMENTS];
57 unsigned int clustered:1;
58 /* 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 */
59 struct kmem_cache *caches[SGV_POOL_ELEMENTS];
60 char cache_names[SGV_POOL_ELEMENTS][25];
65 struct sgv_pool norm_clust, norm;
68 struct sgv_pool highmem;
72 extern atomic_t sgv_big_total_alloc;
73 extern atomic_t sgv_other_total_alloc;
75 extern struct sgv_pool *sgv_pool_create(const char *name, int clustered);
76 extern void sgv_pool_destroy(struct sgv_pool *pool);
78 extern int sgv_pool_init(struct sgv_pool *pool, const char *name,
80 extern void sgv_pool_deinit(struct sgv_pool *pool);
82 extern struct scatterlist *sgv_pool_alloc(struct sgv_pool *pool, int size,
83 unsigned long gfp_mask, int atomic, int *count,
84 struct sgv_pool_obj **sgv);
85 static inline void sgv_pool_free(struct sgv_pool_obj *sgv)
87 TRACE_MEM("Freeing sgv_obj %p", sgv);
88 sgv->entries[sgv->orig_sg].length = sgv->orig_length;
89 kmem_cache_free(sgv->owner_cache, sgv);
92 static inline struct scatterlist *sgv_pool_sg(struct sgv_pool_obj *obj)
97 extern int scst_sgv_pools_init(struct scst_sgv_pools *pools);
98 extern void scst_sgv_pools_deinit(struct scst_sgv_pools *pools);