void zone_register(void) { /* * If something else replaced the system default zone allocator, don't * register jemalloc's. */ default_zone = zone_default_get(); if (!default_zone->zone_name || strcmp(default_zone->zone_name, "DefaultMallocZone") != 0) return; /* * The default purgeable zone is created lazily by OSX's libc. It uses * the default zone when it is created for "small" allocations * (< 15 KiB), but assumes the default zone is a scalable_zone. This * obviously fails when the default zone is the jemalloc zone, so * malloc_default_purgeable_zone() is called beforehand so that the * default purgeable zone is created when the default zone is still * a scalable_zone. As purgeable zones only exist on >= 10.6, we need * to check for the existence of malloc_default_purgeable_zone() at * run time. */ purgeable_zone = (malloc_default_purgeable_zone == NULL) ? NULL : malloc_default_purgeable_zone(); /* Register the custom zone. At this point it won't be the default. */ zone_init(); malloc_zone_register(&jemalloc_zone); /* Promote the custom zone to be default. */ zone_promote(); }
void vm_mem_bootstrap(void) { vm_offset_t start, end; /* * Initializes resident memory structures. * From here on, all physical memory is accounted for, * and we use only virtual addresses. */ vm_page_bootstrap(&start, &end); /* * Initialize other VM packages */ zone_bootstrap(); vm_object_bootstrap(); vm_map_init(); kmem_init(start, end); pmap_init(); zone_init((vm_size_t)ptoa(vm_page_free_count)); kalloc_init(); #if MACH_RT rtalloc_init(); #endif /* MACH_RT */ vm_fault_init(); vm_page_module_init(); memory_manager_default_init(); }
void process_loop(module_hd_t *module_head) { int32_t status, tag_id; uint64_t pkt_num = 0; extern int system_exit; module_info_t *recv; packet_t *packet; if (g_conf.mode == MODE_LIVE || g_conf.mode == MODE_FILE) { /*收包,线程中加入处理*/ status = 0; packet_zone = zone_init("pcap_read", sizeof(packet_t) + MAX_PACKET_LEN, MAX_PACKET_HANDLE); assert(packet_zone); recv = module_info_get_from_name(module_head, "recv"); assert(recv && recv->ops->process); do { do { packet = (void *)zone_alloc(packet_zone, 0); } while(packet == NULL); tag_id = recv->ops->process(recv, packet); if (tag_id > 0) { assert(packet->data); pkt_num++; status = threadpool_add_task(tp, worker_thread_process, packet, 0); if (status != 0) { log_error(syslog_p, "Threadpool add task, status %d\n", status); status = 0; } if (g_conf.pkt_num != 0 && pkt_num >= g_conf.pkt_num) { system_exit = 1; } } else { status = tag_id; zone_free(packet_zone, packet); } } while( status >= 0 && !system_exit); if (g_conf.mode == MODE_FILE) { sleep(1);/*等待最后加入的work处理完成*/ } } else if (g_conf.mode == MODE_SE) { do { status = module_list_process(module_head, pktag_hd_p, -1, NULL); pkt_num++; if (g_conf.pkt_num != 0 && pkt_num >= g_conf.pkt_num) { system_exit = 1; } } while (status >= 0 && !system_exit); } }
/* NB: leave symmetry / pbc structure intact */ void core_delete_all(struct model_pak *model) { g_assert(model != NULL); /* free core reference lists */ free_mol_list(model); wipe_bonds(model); g_slist_free(model->unique_atom_list); model->unique_atom_list = NULL; /* free cores */ free_slist(model->cores); model->cores = NULL; /* redo dependancies */ zone_init(model); calc_emp(model); gui_refresh(GUI_MODEL_PROPERTIES); model->state = 0; }
void delete_commit(struct model_pak *data) { gint flag1=FALSE, flag2=FALSE; gpointer m; GSList *list1, *list2; struct core_pak *core; struct shel_pak *shell; struct bond_pak *bond; g_assert(data != NULL); /* delete flaged cores in list */ list1 = data->cores; while (list1) { core = list1->data; list1 = g_slist_next(list1); if (core->status & DELETED) { #if DEBUG_DELETE_COMMIT printf("Deleting %s core [%p] ...\n", core->label, core); #endif flag1 = TRUE; /* flag assoc. shell */ if (core->shell) { shell = core->shell; shell->status |= DELETED; } /* update connectivity */ connect_atom_clear(core, data); list2 = data->ubonds; while (list2) { bond = list2->data; list2 = g_slist_next(list2); if (bond->atom1 == core || bond->atom2 == core) { data->ubonds = g_slist_remove(data->ubonds, bond); g_free(bond); } } /* update selection */ data->selection = g_slist_remove(data->selection, core); /* delete any labels that reference the deleted core */ list2 = data->measure_list; while (list2) { m = list2->data; list2 = g_slist_next(list2); if (measure_has_core(core, m)) measure_free(m, data); } /* update main list */ data->cores = g_slist_remove(data->cores, core); g_free(core); } } /* delete flaged shells in list */ list1 = data->shels; while (list1) { shell = list1->data; list1 = g_slist_next(list1); if (shell->status & DELETED) { flag2 = TRUE; /* update main list */ data->shels = g_slist_remove(data->shels, shell); g_free(shell); } } /* refresh totals */ data->num_atoms = g_slist_length(data->cores); data->num_shells = g_slist_length(data->shels); /* refresh spatial partitioning */ /* it's probably best to refresh the partitioning here, rather than */ /* incrementally as it's speedups for large models we're targeting */ zone_init(data); /* cope with deleted bonds - expensive, so only do if required */ if (flag1) { connect_bonds(data); connect_molecules(data); } /* refresh net charge calc */ calc_emp(data); /* refresh unique atom list */ g_slist_free(data->unique_atom_list); data->unique_atom_list = find_unique(ELEMENT, data); /* refresh widgets */ meas_graft_model(data); gui_refresh(GUI_MODEL_PROPERTIES); /* reset functions with static pointers to cores */ data->state = 0; }
int main(int argc, char **argv) { INIT_GLB_VARS(); SET_PROCESS_ROLE(PROCESS_ROLE_MASTER); SET_CHILD_PROCESS(PROCESS_ROLE_MASTER, getpid()); /* 此处注册清理函数, 以便主进程由于某些原因退出时, kill掉 * 启动的所有子进程. 但man atexit可知, 通过fork的子进程会 * 继承atexit的注册链, 而exec后将抛弃此注册链. * <NOTE> 此处不考虑fork子进程也执行此函数带来的影响 */ (void)atexit(kill_child_all); if (log_init() == RET_ERR) { SDNS_LOG_ERR("LOG init failed"); exit(EXIT_FAILURE); } if (zone_init() == RET_ERR) { SDNS_LOG_ERR("ZONE init failed"); exit(EXIT_FAILURE); } if (get_options(argc, argv) == RET_ERR) { SDNS_LOG_ERR("parse cmdline failed"); usage_help(); exit(EXIT_FAILURE); } if (IS_PROCESS_ROLE(PROCESS_ROLE_SIGNALLER)) { process_option_signal(); exit(EXIT_SUCCESS); } if (IS_PROCESS_ROLE(PROCESS_ROLE_HELPER)) { usage_help(); exit(EXIT_SUCCESS); } if (start_monitor() == RET_ERR) { exit(EXIT_FAILURE); } if (parse_conf() == RET_ERR) { exit(EXIT_FAILURE); } if (IS_PROCESS_ROLE(PROCESS_ROLE_TESTER)) { SDNS_LOG_DEBUG("配置文件测试OK"); print_parse_res(); exit(EXIT_SUCCESS); } if (pkt_engine_init() == RET_ERR) { SDNS_LOG_ERR("engine init failed"); exit(EXIT_FAILURE); } if (set_required_signal() == RET_ERR || block_required_signal() == RET_ERR) { SDNS_LOG_ERR("signal init failed"); exit(EXIT_FAILURE); } if (sort_init() == RET_ERR) { SDNS_LOG_ERR("sort init failed"); exit(EXIT_FAILURE); } start_worker(); if (start_pkt_engine() == RET_ERR) { SDNS_LOG_ERR("start engine failed"); exit(EXIT_FAILURE); } for(;;) { (void)wait_required_signal(); (void)process_signals(); } exit(EXIT_SUCCESS); }