2011-08-12 11:09:48 +00:00
|
|
|
// (c) 2011 Thomas Schoebel-Theuer / 1&1 Internet AG
|
|
|
|
#ifndef BRICK_MEM_H
|
|
|
|
#define BRICK_MEM_H
|
|
|
|
|
|
|
|
#include <linux/mm_types.h>
|
|
|
|
|
2012-12-31 18:33:32 +00:00
|
|
|
#define BRICK_DEBUG_MEM 4096
|
|
|
|
|
2013-01-21 12:13:26 +00:00
|
|
|
#ifndef CONFIG_MARS_DEBUG_MEM
|
2012-12-31 18:33:32 +00:00
|
|
|
#undef BRICK_DEBUG_MEM
|
|
|
|
#endif
|
2013-01-21 16:59:29 +00:00
|
|
|
#ifdef CONFIG_MARS_DEBUG_ORDER0
|
|
|
|
#define BRICK_DEBUG_ORDER0
|
|
|
|
#endif
|
2012-12-31 18:33:32 +00:00
|
|
|
|
2011-08-12 11:09:48 +00:00
|
|
|
#define GFP_BRICK GFP_NOIO
|
|
|
|
//#define GFP_BRICK GFP_KERNEL // can lead to deadlocks!
|
|
|
|
|
2012-08-08 09:16:52 +00:00
|
|
|
extern long long brick_global_memavail;
|
2011-08-31 11:42:04 +00:00
|
|
|
extern long long brick_global_memlimit;
|
2012-11-15 13:35:02 +00:00
|
|
|
extern atomic64_t brick_global_block_used;
|
2011-08-31 11:42:04 +00:00
|
|
|
|
2011-08-12 11:09:48 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// small memory allocation (use this only for len < PAGE_SIZE)
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
#define brick_mem_alloc(_len_) _brick_mem_alloc(_len_, __LINE__)
|
|
|
|
#define brick_zmem_alloc(_len_) ({ void *_res_ = _brick_mem_alloc(_len_, __LINE__); if (_res_) { memset(_res_, 0, _len_); } _res_; })
|
2011-08-12 11:09:48 +00:00
|
|
|
extern void *_brick_mem_alloc(int len, int line);
|
2011-08-25 10:16:32 +00:00
|
|
|
#define brick_mem_free(_data_) _brick_mem_free(_data_, __LINE__)
|
2011-08-12 11:09:48 +00:00
|
|
|
extern void _brick_mem_free(void *data, int line);
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// string memory allocation
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
#define BRICK_STRING_LEN 1024 /* default value when len == 0 */
|
|
|
|
|
|
|
|
#define brick_string_alloc(_len_) _brick_string_alloc(_len_, __LINE__)
|
2011-11-14 15:00:25 +00:00
|
|
|
#define brick_strndup(_orig_,_len_) ({ char *_res_ = _brick_string_alloc((_len_) + 1, __LINE__); if (_res_) { strncpy(_res_, _orig_, (_len_)); _res_[_len_] = '\0';} _res_; })
|
2011-10-12 14:57:53 +00:00
|
|
|
#define brick_strdup(_orig_) ({ int _len_ = strlen(_orig_); char *_res_ = _brick_string_alloc(_len_ + 1, __LINE__); if (_res_) { strncpy(_res_, _orig_, _len_ + 1); } _res_; })
|
2011-08-25 10:16:32 +00:00
|
|
|
extern char *_brick_string_alloc(int len, int line);
|
|
|
|
#define brick_string_free(_data_) _brick_string_free(_data_, __LINE__)
|
2011-08-12 11:09:48 +00:00
|
|
|
extern void _brick_string_free(const char *data, int line);
|
|
|
|
|
|
|
|
extern void brick_mem_statistics(void);
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// block memory allocation (for aligned multiples of 512 resp PAGE_SIZE)
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
#define brick_block_alloc(_pos_,_len_) _brick_block_alloc(_pos_, _len_, __LINE__)
|
2011-08-12 11:09:48 +00:00
|
|
|
extern void *_brick_block_alloc(loff_t pos, int len, int line);
|
2011-11-14 17:52:05 +00:00
|
|
|
extern void _brick_block_free(void *data, int len, int cline);
|
|
|
|
#define brick_block_free(_data_,_len_) _brick_block_free(_data_, _len_, __LINE__)
|
2011-08-12 11:09:48 +00:00
|
|
|
extern struct page *brick_iomap(void *data, int *offset, int *len);
|
|
|
|
|
|
|
|
|
2011-11-14 17:52:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// reservations / preallocation
|
|
|
|
|
2012-01-23 10:23:41 +00:00
|
|
|
#define BRICK_MAX_ORDER 11
|
2011-11-14 17:52:05 +00:00
|
|
|
|
|
|
|
extern bool brick_allow_freelist;
|
|
|
|
|
|
|
|
struct mem_reservation {
|
|
|
|
int amount[BRICK_MAX_ORDER+1];
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int brick_mem_reserve(struct mem_reservation *r);
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
2012-11-28 11:55:37 +00:00
|
|
|
#ifdef CONFIG_MARS_HAVE_BIGMODULE
|
|
|
|
#undef __exit
|
|
|
|
#define __exit /*empty*/
|
|
|
|
#endif
|
|
|
|
|
2011-08-25 10:16:32 +00:00
|
|
|
extern int init_brick_mem(void);
|
|
|
|
extern void exit_brick_mem(void);
|
|
|
|
|
2011-08-12 11:09:48 +00:00
|
|
|
#endif
|