int AsyncFile::check_odirect_read(Uint32 flags, int &new_flags, int mode) { #ifdef O_DIRECT int ret; char * bufptr = (char*)((UintPtr(g_odirect_readbuf)+(GLOBAL_PAGE_SIZE - 1)) & ~(GLOBAL_PAGE_SIZE - 1)); while (((ret = ::read(theFd, bufptr, GLOBAL_PAGE_SIZE)) == -1) && (errno == EINTR)); if (ret == -1) { ndbout_c("%s Failed to read using O_DIRECT, disabling", theFileName.c_str()); goto reopen; } if(lseek(theFd, 0, SEEK_SET) != 0) { return errno; } if ((flags & FsOpenReq::OM_CHECK_SIZE) == 0) { struct stat buf; if ((fstat(theFd, &buf) == -1)) { return errno; } else if ((buf.st_size % GLOBAL_PAGE_SIZE) != 0) { ndbout_c("%s filesize not a multiple of %d, disabling O_DIRECT", theFileName.c_str(), GLOBAL_PAGE_SIZE); goto reopen; } } return 0; reopen: close(theFd); new_flags &= ~O_DIRECT; theFd = ::open(theFileName.c_str(), new_flags, mode); if (theFd == -1) return errno; #endif return 0; }
void WOPool::release_not_current(Ptr<void> ptr) { WOPage* page = (WOPage*)(UintPtr(ptr.p) & ~(GLOBAL_PAGE_SIZE - 1)); Uint32 cnt = page->m_ref_count; Uint32 type = page->m_type_id; Uint32 ri_type = m_record_info.m_type_id; if (likely(cnt && type == ri_type)) { if (cnt == 1) { m_ctx.release_page(ri_type, ptr.i >> POOL_RECORD_BITS); return; } page->m_ref_count = cnt - 1; return; }
int AsyncFile::check_odirect_write(Uint32 flags, int& new_flags, int mode) { assert(new_flags & (O_CREAT | O_TRUNC)); #ifdef O_DIRECT int ret; char * bufptr = (char*)((UintPtr(g_odirect_readbuf)+(GLOBAL_PAGE_SIZE - 1)) & ~(GLOBAL_PAGE_SIZE - 1)); while (((ret = ::write(theFd, bufptr, GLOBAL_PAGE_SIZE)) == -1) && (errno == EINTR)); if (ret == -1) { new_flags &= ~O_DIRECT; ndbout_c("%s Failed to write using O_DIRECT, disabling", theFileName.c_str()); } close(theFd); theFd = ::open(theFileName.c_str(), new_flags, mode); if (theFd == -1) return errno; #endif return 0; }
static bool isAligned(char* p) { return isAligned(UintPtr(p)); }
static TFPage* ptr(struct iovec p) { UintPtr v = UintPtr(p.iov_base); v -= offsetof(TFPage, m_data); return (TFPage*)v; }
static bool do_malloc(Uint32 pages, InitChunk* chunk, Uint32 *watchCounter, void * baseaddress) { pages += 1; void * ptr = 0; Uint32 sz = pages; retry: if (watchCounter) *watchCounter = 9; char method = f_method[f_method_idx]; switch(method){ case 0: return false; case 'S': case 's': { ptr = 0; while (ptr == 0) { if (watchCounter) *watchCounter = 9; ptr = sbrk(sizeof(Alloc_page) * sz); if (ptr == (void*)-1) { if (method == 'S') { f_method_idx++; goto retry; } ptr = 0; sz = 1 + (9 * sz) / 10; if (pages >= 32 && sz < 32) { sz = pages; f_method_idx++; goto retry; } } else if (UintPtr(ptr) < UintPtr(baseaddress)) { /** * Unusable memory :( */ ndbout_c("sbrk(%lluMb) => %p which is less than baseaddress!!", Uint64((sizeof(Alloc_page) * sz) >> 20), ptr); f_method_idx++; goto retry; } } break; } case 'M': case 'm': { ptr = 0; while (ptr == 0) { if (watchCounter) *watchCounter = 9; ptr = malloc(sizeof(Alloc_page) * sz); if (UintPtr(ptr) < UintPtr(baseaddress)) { ndbout_c("malloc(%lluMb) => %p which is less than baseaddress!!", Uint64((sizeof(Alloc_page) * sz) >> 20), ptr); free(ptr); ptr = 0; } if (ptr == 0) { if (method == 'M') { f_method_idx++; goto retry; } sz = 1 + (9 * sz) / 10; if (pages >= 32 && sz < 32) { f_method_idx++; goto retry; } } } break; }