4 * Copyright (C) 2006 - 2009 Vladislav Bolkhovitin <vst@vlnb.net>
5 * Copyright (C) 2007 - 2009 ID7 Ltd.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, version 2
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/scatterlist.h>
19 #include <linux/workqueue.h>
21 #define SGV_POOL_ELEMENTS 11
24 * sg_num is indexed by the page number, pg_count is indexed by the sg number.
25 * Made in one entry to simplify the code (eg all sizeof(*) parts) and save
26 * some CPU cache for non-clustered case.
28 struct trans_tbl_ent {
29 unsigned short sg_num;
30 unsigned short pg_count;
37 /* jiffies, protected by sgv_pool_lock */
38 unsigned long time_stamp;
40 struct list_head recycling_list_entry;
41 struct list_head sorted_recycling_list_entry;
43 struct sgv_pool *owner_pool;
48 struct trans_tbl_ent *trans_tbl;
49 struct scatterlist *sg_entries;
50 struct scatterlist sg_entries_data[0];
53 struct sgv_pool_cache_acc {
54 atomic_t total_alloc, hit_alloc;
58 struct sgv_pool_alloc_fns {
59 struct page *(*alloc_pages_fn)(struct scatterlist *sg, gfp_t gfp_mask,
61 void (*free_pages_fn)(struct scatterlist *sg, int sg_count,
66 enum sgv_clustering_types clustering_type;
67 int single_alloc_pages;
70 struct sgv_pool_alloc_fns alloc_fns;
72 /* <=4K, <=8, <=16, <=32, <=64, <=128, <=256, <=512, <=1024, <=2048 */
73 struct kmem_cache *caches[SGV_POOL_ELEMENTS];
75 spinlock_t sgv_pool_lock; /* outer lock for sgv_pools_lock! */
79 /* Protected by sgv_pool_lock, if necessary */
80 unsigned int purge_work_scheduled:1;
81 unsigned int sgv_kobj_initialized:1;
83 /* Protected by sgv_pool_lock */
84 struct list_head sorted_recycling_list;
86 int inactive_cached_pages; /* protected by sgv_pool_lock */
88 /* Protected by sgv_pool_lock */
89 struct list_head recycling_lists[SGV_POOL_ELEMENTS];
91 int cached_pages, cached_entries; /* protected by sgv_pool_lock */
93 struct sgv_pool_cache_acc cache_acc[SGV_POOL_ELEMENTS];
95 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
96 struct delayed_work sgv_purge_work;
98 struct work_struct sgv_purge_work;
101 struct list_head sgv_active_pools_list_entry;
103 atomic_t big_alloc, big_pages, big_merged;
104 atomic_t other_alloc, other_pages, other_merged;
106 atomic_t sgv_pool_ref;
110 /* SCST_MAX_NAME + few more bytes to match scst_user expectations */
111 char cache_names[SGV_POOL_ELEMENTS][SCST_MAX_NAME + 10];
112 char name[SCST_MAX_NAME + 10];
114 struct mm_struct *owner_mm;
116 struct list_head sgv_pools_list_entry;
118 struct kobject sgv_kobj;
121 static inline struct scatterlist *sgv_pool_sg(struct sgv_pool_obj *obj)
123 return obj->sg_entries;
126 int scst_sgv_pools_init(unsigned long mem_hwmark, unsigned long mem_lwmark);
127 void scst_sgv_pools_deinit(void);
129 void sgv_pool_destroy(struct sgv_pool *pool);
131 #ifdef CONFIG_SCST_PROC
132 int sgv_procinfo_show(struct seq_file *seq, void *v);
134 ssize_t sgv_sysfs_stat_show(struct kobject *kobj,
135 struct kobj_attribute *attr, char *buf);
136 ssize_t sgv_sysfs_global_stat_show(struct kobject *kobj,
137 struct kobj_attribute *attr, char *buf);
140 void scst_sgv_pool_use_norm(struct scst_tgt_dev *tgt_dev);
141 void scst_sgv_pool_use_norm_clust(struct scst_tgt_dev *tgt_dev);
142 void scst_sgv_pool_use_dma(struct scst_tgt_dev *tgt_dev);