Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmap for windows #3557

Merged

Conversation

daniellerozenblit
Copy link
Contributor

This PR is a follow-up to #3486. It adds memory-mapped dictionaries for Windows.

programs/fileio.c Outdated Show resolved Hide resolved
@daniellerozenblit daniellerozenblit marked this pull request as ready for review March 17, 2023 18:33
programs/fileio.c Outdated Show resolved Hide resolved
programs/fileio.c Outdated Show resolved Hide resolved
static void FIO_munmap(void* buffer, size_t bufferSize) {
(void)bufferSize;
free(buffer);
static void FIO_munmap(const FIO_Dict_t* dict) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here, prefer FIO_Dict_t* dict as argument type.

}
/* We might want to also do mapping for windows */
static size_t FIO_createDictBufferMMap(void** bufferPtr, const char* fileName, FIO_prefs_t* const prefs, stat_t* dictFileStat)
static size_t FIO_createDictBufferMMap(FIO_Dict_t* dict, const char* fileName, FIO_prefs_t* const prefs, stat_t* dictFileStat)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussion on naming convention :

When I read a function name like PREFIX_createType(), I expect it to return a Type* pointer object.
That's not the case here.

On a related note, if the object is allocated beforehand (on stack for example), I would consider PREFIX_initType(Type* v, ...) for the function name.

I note that this situation is slightly different : you want to set member dict->dictBuffer with the outcome of mmap (and I presume FIO_Dict_t is larger than this member), and return the underlying file size.

In which case, maybe FIO_setDictBufferMMap() ?

programs/fileio.c Outdated Show resolved Hide resolved
@daniellerozenblit daniellerozenblit force-pushed the windows-mmap-dictionaries branch 2 times, most recently from 45f8a1c to 7467668 Compare March 27, 2023 20:15
@daniellerozenblit daniellerozenblit force-pushed the windows-mmap-dictionaries branch from 7467668 to ffc7bcf Compare March 27, 2023 20:21
ress.dict.dictBufferSize = FIO_createDictBufferMMap(&ress.dict.dictBuffer, dictFileName, prefs, &ress.dictFileStat);
}
dictBufferType = (useMMap && !forceNoUseMMap) ? FIO_mmapDict : FIO_mallocDict;
ress.dict.dictBufferSize = FIO_initDict(&ress.dict, dictFileName, prefs, &ress.dictFileStat, dictBufferType); /* works with dictFileName==NULL */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of FIO_initDict() is used to initialize ress.dict.dictBufferSize.

Since the stated goal of FIO_initDict() is to initialize ress.dict,
I would rather expect FIO_initDict() to directly set ress.dict.dictBufferSize as part of the initialization.

FIO_initDict() should rather return a success/error code.

Copy link
Contributor

@Cyan4973 Cyan4973 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good !

Please squash commits before merging

@daniellerozenblit daniellerozenblit merged commit b2ad17a into facebook:dev Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants