Source
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/* should be a multiple of 8 and at least (2 * ZBX_PTR_SIZE) */
/* starting from this size all free chunks are put into the same bucket */
typedef struct
{
void *base;
void **buckets;
void *lo_bound;
void *hi_bound;
zbx_uint64_t free_size;
zbx_uint64_t used_size;
zbx_uint64_t orig_size;
zbx_uint64_t total_size;
int shm_id;
/* Continue execution in out of memory situation. */
/* Normally allocator forces exit when it runs out of allocatable memory. */
/* Set this flag to 1 to allow execution in out of memory situations. */
char allow_oom;
const char *mem_descr;
const char *mem_param;
}
zbx_shmem_info_t;
typedef struct
{
zbx_uint64_t free_size;
zbx_uint64_t used_size;
zbx_uint64_t min_chunk_size;
zbx_uint64_t max_chunk_size;
zbx_uint64_t overhead;
unsigned int chunks_num[ZBX_SHMEM_BUCKET_COUNT];
unsigned int free_chunks;
unsigned int used_chunks;
}
zbx_shmem_stats_t;
int zbx_shmem_create(zbx_shmem_info_t **info, zbx_uint64_t size, const char *descr, const char *param,
int allow_oom, char **error);
int zbx_shmem_create_min(zbx_shmem_info_t **info, zbx_uint64_t size, const char *descr, const char *param,