static int check_all_minfree(void *param, void *param2) { #if 1 extern int get_min_free_pages(pid_t pid); struct task_struct *p = 0; int n = 4096 * 170000; int nr_pages = (n / PAGE_SIZE) + ((n % PAGE_SIZE) ? 1 : 0); int free_pages = global_page_state(NR_FREE_PAGES) + global_page_state(NR_FILE_PAGES) + global_page_state(NR_FILE_DIRTY); ALMK_WRN(KERN_ALERT "%s\n", __func__); ALMK_WRN(KERN_ALERT "=====================================\n"); for_each_process(p) { /* get_min_free_pages(p->pid); */ ALMK_WRN(KERN_ALERT "trying to alloc %d bytes (%d pages)\n" "(NR_FREE_PAGES) + " "(NR_FILE_PAGES) + " "(NR_FILE_DIRTY) - " "nr_pages = (%d + %d + %d - %d) = %d\n" "target_min_free_pages = %d\n", n, nr_pages, global_page_state(NR_FREE_PAGES), global_page_state(NR_FILE_PAGES), global_page_state(NR_FILE_DIRTY), nr_pages, free_pages - nr_pages, get_min_free_pages(p->pid)); ALMK_WRN(KERN_ALERT "allocation is %s\n", (free_pages - nr_pages >= get_min_free_pages(p->pid)) ? "safe" : "not safe"); } #endif }
static int almk_flush(struct file *a_pstFile, fl_owner_t a_id) { unsigned int *pStatus; pStatus = (unsigned int *)a_pstFile->private_data; if (NULL == pStatus) { ALMK_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n"); return -EFAULT; } return 0; }
static int almk_open(struct inode *inode, struct file *file) { unsigned int *pStatus; /* Allocate and initialize private data */ file->private_data = kmalloc(sizeof(unsigned int), GFP_ATOMIC); if (NULL == file->private_data) { ALMK_WRN("Not enough entry for ALMK open operation\n"); return -ENOMEM; } pStatus = (unsigned int *)file->private_data; *pStatus = 0; return 0; }
static int almk_ioctl(unsigned int cmd, unsigned long arg, struct file *file) { ALMK_DRV_DATA drv_data; unsigned int max_safe_size; unsigned int *pStatus; pStatus = (unsigned int*)file->private_data; if(NULL == pStatus) { ALMK_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n"); return -EFAULT; } switch(cmd) { // initial and reset ALMK case ALMK_IOCTL_CMD_INIT: ALMK_MSG("ALMK Driver Initial and Lock\n"); *pStatus = ALMK_PROCESS; break; case ALMK_IOCTL_CMD_GET_MAX_SIZE: ALMK_MSG("ALMK Driver GET_MAX_SIZE!!\n"); if(*pStatus != ALMK_PROCESS) { ALMK_WRN("Permission Denied! This process can not access ALMK Driver"); return -EFAULT; } if(copy_from_user(&drv_data, (void *)arg, sizeof(ALMK_DRV_DATA))) { ALMK_WRN("ALMK Driver : Copy from user error\n"); return -EFAULT; } max_safe_size = get_max_safe_size(drv_data.pid); if(copy_to_user(drv_data.maxSafeSize, &max_safe_size, sizeof(unsigned int))) { ALMK_WRN("ALMK Driver : Copy to user error (result)\n"); return -EFAULT; } break; case ALMK_IOCTL_CMD_DEINIT: // copy input parameters ALMK_MSG("ALMK Driver Deinit!!\n"); if(*pStatus != ALMK_PROCESS) { ALMK_WRN("Permission Denied! This process can not access ALMK Driver"); return -EFAULT; } *pStatus = 0; return 0; } return 0; }