#define ZLOGGER_BLOCK_COUNT (ZLOGGER_BUFFER_SIZE / ZLOGGER_BLOCK_SIZE)
#define ZLOGGER_BITMAP_SIZE (ZLOGGER_BLOCK_COUNT / 8)
#define ZLOGGER_DATA_MAX (ZLOGGER_BLOCK_SIZE - sizeof(struct zlogger_header))
+#define ZLOGGER_BLOCK_NUMBER 8192
#define ZLOGGER_TAG_MAX (32)
#define ZLOGGER_MSG_MAX (140)
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_BLOCKS 10000
+#define POOL_SIZE 2
+#define INIT_PROCESSES 5000
+
+struct process_history {
+ pid_t pid;
+ int history[POOL_SIZE]; // last used blocks
+ //int current_index; // which index should be overwritten
+};
+
+size_t history_size = INIT_PROCESSES;
+struct proccess_history *history;
+
+void init() {
+ history = calloc(INIT_PROCESSES, sizeof(struct process_history));
+}
+
+int get_proccess_index(pid_t pid) {
+ for (int i = 0; i < history_size; i++)
+ if (history[i].pid == pid)
+ return i;
+}
+
+void save_new_process(pid_t pid) {
+ for (int i = 0; i < history_size; i++) {
+ if (history[i].pid == 0) {
+ history[i].pid = pid;
+ return;
+ }
+ }
+
+ struct process_history *temp = realloc(history, sizeof(struct process_history)*history_size*2);
+ if (temp != NULL) {
+ history = temp;
+ history_size*=2;
+ }
+}
+
+void delete_process(pid_t pid) {
+ memset(&history[get_proccess_index(pid)], 0, sizeof(struct process_history));
+}
+
+void choose_block(pid_t pid) {
+ int idx = get_proccess_index(pid);
+ // sprawdz czy ktorys z tablicy history[idx] jest wolny, jak nie to przydziel dowolny wolny i nadpisz jeden z blokow w historii
+}
+
+
+
static struct miscdevice zlogger_dump_device;
static int g_init;
-static char *g_shm_ptr[ZLOGGER_DEVICE_COUNT];
+static char *g_shm_ptr[ZLOGGER_BLOCK_NUMBER];
static struct thread_table *g_thread_table;
static struct mutex g_block_mutex;
int g_shm_ptr_i = 0;
int r = 0;
+ unsigned int target_size = 32 * 1024 * 1024; // 32mb
+ unsigned int page_size = 4 * 1024; // 4kb
+
+ unsigned int iterations = target_size / page_size;
+ if (target_size % page_size != 0) {
+ iterations++;
+ }
+
if (!g_zlog_enable) {
pr_info("zlog is disable\n");
return 0;
return -ENOMEM;
hash_init(g_thread_table->data);
- for (g_shm_ptr_i = 0; g_shm_ptr_i < ZLOGGER_DEVICE_COUNT; g_shm_ptr_i++) {
- g_shm_ptr[g_shm_ptr_i] = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, MAP_ORDER);
+ for (g_shm_ptr_i = 0; g_shm_ptr_i < iterations; g_shm_ptr_i++) {
+ g_shm_ptr[g_shm_ptr_i] = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(page_size));
if (g_shm_ptr[g_shm_ptr_i] == NULL) {
r = -ENOMEM;
goto out_free_g_thread_table_g_shm_ptr;