memcached.c
static int enable_large_pages(void) {
#if defined(HAVE_GETPAGESIZES) && defined(HAVE_MEMCNTL)
    int ret = -1;
    size_t sizes[32];
    int avail = getpagesizes(sizes, 32);
    if (avail != -1) {
        size_t max = sizes[0];
        struct memcntl_mha arg = {0};
        int ii;

        for (ii = 1; ii < avail; ++ii) {
            if (max < sizes[ii]) {
                max = sizes[ii];
            }
        }

        arg.mha_flags   = 0;
        arg.mha_pagesize = max;
        arg.mha_cmd = MHA_MAPSIZE_BSSBRK;

        if (memcntl(0, 0, MC_HAT_ADVISE, (caddr_t)&arg, 0, 0) == -1) {
            fprintf(stderr, "Failed to set large pages: %s\n",
                    strerror(errno));
            fprintf(stderr, "Will use default page size\n");
        } else {
            ret = 0;
        }
    } else {
        fprintf(stderr, "Failed to get supported pagesizes: %s\n",
                strerror(errno));
        fprintf(stderr, "Will use default page size\n");
    }

    return ret;
#else
    return 0;
#endif
}
/*
 * On systems that supports multiple page sizes we may reduce the
 * number of TLB-misses by using the biggest available page size
 */
On systems that supports multiple page sizes we may reduce the
number of TLB-misses by using the biggest available page size
On systems that supports multiple page sizes we may reduce the number of TLB - misses by using the biggest available page size
static int enable_large_pages(void) {
#if defined(HAVE_GETPAGESIZES) && defined(HAVE_MEMCNTL)
    int ret = -1;
    size_t sizes[32];
    int avail = getpagesizes(sizes, 32);
    if (avail != -1) {
        size_t max = sizes[0];
        struct memcntl_mha arg = {0};
        int ii;
        for (ii = 1; ii < avail; ++ii) {
            if (max < sizes[ii]) {
                max = sizes[ii];
            }
        }
        arg.mha_flags   = 0;
        arg.mha_pagesize = max;
        arg.mha_cmd = MHA_MAPSIZE_BSSBRK;
        if (memcntl(0, 0, MC_HAT_ADVISE, (caddr_t)&arg, 0, 0) == -1) {
            fprintf(stderr, "Failed to set large pages: %s\n",
                    strerror(errno));
            fprintf(stderr, "Will use default page size\n");
        } else {
            ret = 0;
        }
    } else {
        fprintf(stderr, "Failed to get supported pagesizes: %s\n",
                strerror(errno));
        fprintf(stderr, "Will use default page size\n");
    }
    return ret;
#else
    return 0;
#endif
}
static int enable_large_pages ( void ) { #if defined ( HAVE_GETPAGESIZES ) && defined ( HAVE_MEMCNTL ) int ret = -1 ; size_t sizes [ 32 ] ; int avail = getpagesizes ( sizes , 32 ) ; if ( avail != -1 ) { size_t max = sizes [ 0 ] ; struct memcntl_mha arg = { 0 } ; int ii ; for ( ii = 1 ; ii < avail ; ++ ii ) { if ( max < sizes [ ii ] ) { max = sizes [ ii ] ; } } arg . mha_flags = 0 ; arg . mha_pagesize = max ; arg . mha_cmd = MHA_MAPSIZE_BSSBRK ; if ( memcntl ( 0 , 0 , MC_HAT_ADVISE , ( caddr_t ) & arg , 0 , 0 ) == -1 ) { fprintf ( stderr , " \n " , strerror ( errno ) ) ; fprintf ( stderr , " \n " ) ; } else { ret = 0 ; } } else { fprintf ( stderr , " \n " , strerror ( errno ) ) ; fprintf ( stderr , " \n " ) ; } return ret ; #else return 0 ; #endif }
On systems that supports multiple page sizes we may reduce the
 number of TLB-misses by using the biggest available page size
On systems that supports multiple page sizes we may reduce the number of TLB - misses by using the biggest available page size