VMX: Report the correct flags in IA32_APICBASE MSR emulation
[akaros.git] / kern / include / slab.h
index c041883..4d90556 100644 (file)
 #define SLAB_LARGE_CUTOFF (PGSIZE / NUM_BUF_PER_SLAB)
 
 #define KMC_NAME_SZ                            32
+#define KMC_MAG_MIN_SZ                 8
+#define KMC_MAG_MAX_SZ                 62              /* chosen for mag size and caching */
 
 /* Cache creation flags: */
 #define KMC_NOTOUCH                            0x0001  /* Can't use source/object's memory */
 #define KMC_QCACHE                             0x0002  /* Cache is an arena's qcache */
 #define __KMC_USE_BUFCTL               0x1000  /* Internal use */
 
+struct kmem_magazine {
+       SLIST_ENTRY(kmem_magazine)      link;
+       unsigned int                            nr_rounds;
+       void                                            *rounds[KMC_MAG_MAX_SZ];
+} __attribute__((aligned(ARCH_CL_SIZE)));
+SLIST_HEAD(kmem_mag_slist, kmem_magazine);
+
+struct kmem_pcpu_cache {
+       int8_t                                          irq_state;
+       unsigned int                            magsize;
+       struct kmem_magazine            *loaded;
+       struct kmem_magazine            *prev;
+       size_t                                          nr_allocs_ever;
+} __attribute__((aligned(ARCH_CL_SIZE)));
+
+struct kmem_depot {
+       spinlock_t                                      lock;
+       struct kmem_mag_slist           not_empty;
+       struct kmem_mag_slist           empty;
+       unsigned int                            magsize;
+       unsigned int                            nr_empty;
+       unsigned int                            nr_not_empty;
+       unsigned int                            busy_count;
+       uint64_t                                        busy_start;
+};
+
 struct kmem_slab;
 
 /* Control block for buffers for large-object slabs */
@@ -72,7 +100,9 @@ TAILQ_HEAD(kmem_slab_list, kmem_slab);
 
 /* Actual cache */
 struct kmem_cache {
-       SLIST_ENTRY(kmem_cache) link;
+       TAILQ_ENTRY(kmem_cache) all_kmc_link;
+       struct kmem_pcpu_cache *pcpu_caches;
+       struct kmem_depot depot;
        spinlock_t cache_lock;
        size_t obj_size;
        size_t import_amt;
@@ -82,25 +112,26 @@ struct kmem_cache {
        struct kmem_slab_list full_slab_list;
        struct kmem_slab_list partial_slab_list;
        struct kmem_slab_list empty_slab_list;
-       void (*ctor)(void *, size_t);
-       void (*dtor)(void *, size_t);
+       int (*ctor)(void *obj, void *priv, int flags);
+       void (*dtor)(void *obj, void *priv);
+       void *priv;
        unsigned long nr_cur_alloc;
        struct hash_helper hh;
        struct kmem_bufctl_list *alloc_hash;
        struct kmem_bufctl_list static_hash[HASH_INIT_SZ];
        char name[KMC_NAME_SZ];
+       TAILQ_ENTRY(kmem_cache) import_link;
 };
 
-/* List of all kmem_caches, sorted in order of size */
-SLIST_HEAD(kmem_cache_list, kmem_cache);
-extern struct kmem_cache_list kmem_caches;
+extern struct kmem_cache_tailq all_kmem_caches;
 
 /* Cache management */
 struct kmem_cache *kmem_cache_create(const char *name, size_t obj_size,
                                      int align, int flags,
                                      struct arena *source,
-                                     void (*ctor)(void *, size_t),
-                                     void (*dtor)(void *, size_t));
+                                     int (*ctor)(void *, void *, int),
+                                     void (*dtor)(void *, void *),
+                                     void *priv);
 void kmem_cache_destroy(struct kmem_cache *cp);
 /* Front end: clients of caches use these */
 void *kmem_cache_alloc(struct kmem_cache *cp, int flags);
@@ -108,13 +139,10 @@ void kmem_cache_free(struct kmem_cache *cp, void *buf);
 /* Back end: internal functions */
 void kmem_cache_init(void);
 void kmem_cache_reap(struct kmem_cache *cp);
+unsigned int kmc_nr_pcpu_caches(void);
 /* Low-level interface for initializing a cache. */
 void __kmem_cache_create(struct kmem_cache *kc, const char *name,
                          size_t obj_size, int align, int flags,
                          struct arena *source,
-                         void (*ctor)(void *, size_t),
-                         void (*dtor)(void *, size_t));
-
-/* Debug */
-void print_kmem_cache(struct kmem_cache *kc);
-void print_kmem_slab(struct kmem_slab *slab);
+                         int (*ctor)(void *, void *, int),
+                         void (*dtor)(void *, void *), void *priv);