2 *------------------------------------------------------------------
3 * Copyright (c) 2009 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
18 #ifndef __included_svm_common_h__
19 #define __included_svm_common_h__
24 #endif /* __FreeBSD__ */
28 #endif /* __linux__ */
29 #include <vppinfra/clib.h>
30 #include <vppinfra/types.h>
32 #define SVM_VERSION ((1<<16) | 1) /* set to declare region ready. */
34 #define SVM_FLAGS_MHEAP (1<<0) /* region contains an mheap */
35 #define SVM_FLAGS_FILE (1<<1) /* region backed by one or more files */
36 #define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */
37 #define SVM_FLAGS_NEED_DATA_INIT (1<<3)
39 #define SVM_PVT_MHEAP_SIZE (128<<10) /* region's private mheap (128k) */
41 typedef struct svm_region_
43 volatile uword version;
44 pthread_mutex_t mutex;
45 pthread_cond_t condvar;
46 int mutex_owner_pid; /* in case of trouble */
49 uword virtual_base; /* base of the region object */
52 void *data_base; /* data portion base address */
53 void *data_heap; /* data heap, if any */
54 volatile void *user_ctx; /* user context pointer */
55 /* stuff allocated in the region's heap */
56 uword bitmap_size; /* nbits in virtual alloc bitmap */
57 uword *bitmap; /* the bitmap */
65 * (64K) clib heap for the region itself
67 * data_base -> whatever is in this region
72 typedef struct svm_map_region_args_
74 const char *root_path; /* NULL means use the truly global arena */
81 uword backing_mmap_size;
82 /* uid, gid to own the svm region(s) */
85 } svm_map_region_args_t;
88 * Memory mapped to high addresses for session/vppcom/vcl/etc...
91 #ifdef CLIB_SANITIZE_ADDR
92 #define HIGH_SEGMENT_BASEVA 0x300000000000 /* DO NOT CHANGE THIS: YOU'LL BREAK ASAN */
93 #else /* CLIB_SANITIZE_ADDR */
94 #define HIGH_SEGMENT_BASEVA (128ULL << 30) /* 128GB */
95 #endif /* CLIB_SANITIZE_ADDR */
96 #elif __WORDSIZE == 32
97 #define HIGH_SEGMENT_BASEVA (3584UL << 20) /* 3.5GB */
99 #error "unknown __WORDSIZE"
103 * Memory shared across all router instances. Packet buffers, etc
104 * Base should be "out of the way," and size should be big enough to
105 * cover everything we plan to put here.
107 #define SVM_GLOBAL_REGION_SIZE (64<<20)
108 #define SVM_GLOBAL_REGION_NAME "/global_vm"
109 u64 svm_get_global_region_base_va ();
112 * Memory shared across individual router instances.
114 #define SVM_OVERLAY_REGION_BASEVA \
115 (SVM_GLOBAL_REGION_BASEVA + SVM_GLOBAL_REGION_SIZE)
116 #define SVM_OVERLAY_REGION_SIZE (1<<20)
117 #define SVM_OVERLAY_REGION_BASENAME "/overlay_vm"
126 svm_subregion_t *subregions; /* subregion pool */
134 void *svm_region_find_or_create (svm_map_region_args_t * a);
135 void svm_region_init (void);
136 void svm_region_init_mapped_region (svm_map_region_args_t * a,
138 int svm_region_init_chroot (const char *root_path);
139 void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid);
140 void svm_region_init_args (svm_map_region_args_t * a);
141 void svm_region_exit (void);
142 void svm_region_exit_client (void);
143 void svm_region_unmap (void *rp_arg);
144 void svm_region_unmap_client (void *rp_arg);
145 void svm_client_scan (const char *root_path);
146 void svm_client_scan_this_region_nolock (svm_region_t * rp);
147 u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a);
148 u8 *format_svm_region (u8 * s, va_list * args);
150 svm_region_t *svm_get_root_rp (void);
152 #endif /* __included_svm_common_h__ */
155 * fd.io coding-style-patch-verification: ON
158 * eval: (c-set-style "gnu")