1/* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Decription: memory operation for gp sharedmem. 4 * 5 * This software is licensed under the terms of the GNU General Public 6 * License version 2, as published by the Free Software Foundation, and 7 * may be copied, distributed, and modified under those terms. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 */ 14#ifndef MEM_H 15#define MEM_H 16#include <linux/types.h> 17#include "teek_ns_client.h" 18 19#define PRE_ALLOCATE_SIZE (1024*1024) 20#define MEM_POOL_ELEMENT_SIZE (64*1024) 21#define MEM_POOL_ELEMENT_NR (8) 22#define MEM_POOL_ELEMENT_ORDER (4) 23 24struct tc_ns_shared_mem *tc_mem_allocate(size_t len); 25void tc_mem_free(struct tc_ns_shared_mem *shared_mem); 26 27static inline void get_sharemem_struct(struct tc_ns_shared_mem *sharemem) 28{ 29 if (sharemem != NULL) 30 atomic_inc(&sharemem->usage); 31} 32 33static inline void put_sharemem_struct(struct tc_ns_shared_mem *sharemem) 34{ 35 if (sharemem != NULL) { 36 if (atomic_dec_and_test(&sharemem->usage)) 37 tc_mem_free(sharemem); 38 } 39} 40 41#endif 42