snmalloc icon indicating copy to clipboard operation
snmalloc copied to clipboard

Pickup page size from unistd.h

Open mjp41 opened this issue 1 year ago • 8 comments

This uses the PAGESIZE constant from the unistd.h on POSIX. This should make the code more resilient to being compiled on platforms with different page sizes.

mjp41 avatar Jun 17 '24 09:06 mjp41

Hopefully addresses #663

mjp41 avatar Jun 17 '24 09:06 mjp41

@schrodingerzhu would you be able to see if this fixes your problem.

mjp41 avatar Jun 17 '24 09:06 mjp41

will try this after work

SchrodingerZhu avatar Jun 17 '24 19:06 SchrodingerZhu

Sorry for the noise. git seems to have strange behaviour when checking out pr/head so my local change was not overwritten, which makes me think the issue was fixed.

The fix is not working. Such macro is undefined on platforms without a fixed page size.

#ifdef PAGESIZE
    #warning "defined"
    static constexpr size_t page_size = max(Aal::smallest_page_size, PAGESIZE);
#else
    #warning "undefined"
    static constexpr size_t page_size = Aal::smallest_page_size;
#endif

Gives undefined.

Actually, the corresponding header says

/* We do not provide fixed values for

   ARG_MAX      Maximum length of argument to the `exec' function
                including environment data.

   ATEXIT_MAX   Maximum number of functions that may be registered
                with `atexit'.

   CHILD_MAX    Maximum number of simultaneous processes per real
                user ID.

   OPEN_MAX     Maximum number of files that one process can have open
                at anyone time.

   PAGESIZE
   PAGE_SIZE    Size of bytes of a page.

   PASS_MAX     Maximum number of significant bytes in a password.

   We only provide a fixed limit for

   IOV_MAX      Maximum number of `iovec' structures that one process has
                available for use with `readv' or writev'.

   if this is indeed fixed by the underlying system.
*/

If this is not the on the perf-critical path, I suggest use _SC_PAGESIZE approach instead. It is the most portable way. In libc on linux, this value is usually populated via aux vector and cached by libc. There is no syscall involved. If you are concern that sysconf has a super large jumptable, you can also cache it inside snmalloc.

SchrodingerZhu avatar Jun 18 '24 01:06 SchrodingerZhu

Inspected the code a little, it seems that a dynamic page size demands too many changes and may impact negatively on the performance. Is it possible to allow cmake to run sysconf or let user override page size during configuration phase? All these can be set as additional options.

SchrodingerZhu avatar Jun 22 '24 03:06 SchrodingerZhu

Inspected the code a little, it seems that a dynamic page size demands too many changes and may impact negatively on the performance. Is it possible to allow cmake to run sysconf or let user override page size during configuration phase? All these can be set as additional options.

I would prefer the second. The first might have issues with cross compiling, so I wouldn't want to always run sysconf at configure time.

I think we could make the dynamic page size work, but it is more effort than I have time for, and would be pretty subtle to review the changes.

mjp41 avatar Jun 22 '24 08:06 mjp41

@schrodingerzhu can this be used for your use case?

mjp41 avatar Jul 01 '24 14:07 mjp41

Yes. I can workaround the issue with this patch

SchrodingerZhu avatar Jul 30 '24 19:07 SchrodingerZhu