X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=runtime%2Fmem.c;h=2f55ff4d2108d93522d878e4549ef5812cc10721;hp=420171e711e31c99f3101e7da07f72dcb4cbeb57;hb=HEAD;hpb=778b8c8ca708b082a1192acfb114a6751b2ad7c9 diff --git a/runtime/mem.c b/runtime/mem.c index 420171e..2f55ff4 100644 --- a/runtime/mem.c +++ b/runtime/mem.c @@ -74,9 +74,9 @@ static inline header_t *get_header (void *r) { } static void *get_new_region (int block_scale) { - LOCALIZE_THREAD_LOCAL(tid_, int); + int thread_index = GET_THREAD_INDEX(); #ifdef RECYCLE_PAGES - tl_t *tl = &tl_[tid_]; // thread-local data + tl_t *tl = &tl_[thread_index]; // thread-local data if (block_scale <= PAGE_SCALE && tl->free_pages != NULL) { void *region = tl->free_pages; tl->free_pages = tl->free_pages->next; @@ -97,7 +97,7 @@ static void *get_new_region (int block_scale) { if ((size_t)region & (region_size - 1)) { TRACE("m0", "get_new_region: region not aligned", 0, 0); munmap(region, region_size); - region = mmap(NULL, region_size * 2, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); + region = mmap(NULL, region_size * 2, PROT_READ|PROT_WRITE, MAP_NORESERVE|MAP_ANON|MAP_PRIVATE, -1, 0); if (region == (void *)-1) { perror("get_new_region: mmap"); exit(-1); @@ -122,7 +122,7 @@ static void *get_new_region (int block_scale) { TRACE("m1", "get_new_region: header %p (%p)", h, h - headers_); assert(h->scale == 0); h->scale = block_scale; - h->owner = tid_; + h->owner = thread_index; return region; } @@ -148,7 +148,6 @@ void mem_init (void) { void nbd_free (void *x) { TRACE("m1", "nbd_free: block %p page %p", x, (size_t)x & ~MASK(PAGE_SCALE)); ASSERT(x); - LOCALIZE_THREAD_LOCAL(tid_, int); block_t *b = (block_t *)x; header_t *h = get_header(x); int b_scale = h->scale; @@ -164,8 +163,9 @@ void nbd_free (void *x) { #ifndef NDEBUG memset(b, 0xcd, (1ULL << b_scale)); // bear trap #endif - tl_t *tl = &tl_[tid_]; // thread-local data - if (h->owner == tid_) { + int thread_index = GET_THREAD_INDEX(); + tl_t *tl = &tl_[thread_index]; // thread-local data + if (h->owner == thread_index) { TRACE("m1", "nbd_free: private block, old free list head %p", tl->free_list[b_scale], 0); #ifndef RECYCLE_PAGES @@ -264,8 +264,7 @@ void *nbd_malloc (size_t n) { if (EXPECT_FALSE(b_scale < MIN_SCALE)) { b_scale = MIN_SCALE; } if (EXPECT_FALSE(b_scale > MAX_SCALE)) { return NULL; } - LOCALIZE_THREAD_LOCAL(tid_, int); - tl_t *tl = &tl_[tid_]; // thread-local data + tl_t *tl = &tl_[GET_THREAD_INDEX()]; // thread-local data block_t *b = pop_free_list(tl, b_scale); if (b != NULL) {