Coda Distributed File System
rds_private.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 5
5
6 Copyright (c) 1987-2016 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16
17#*/
18
19/*
20 * Internal type definitions for the Recoverable Dynamic Storage package.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#ifdef __STDC__
28#include <string.h>
29#include "assert.h"
30#endif
31
32#include <rvm/rvm.h>
33#include <rvm/rvm_segment.h>
34#include <rvm/rds.h>
35
36#ifndef _RDS_PRIVATE_H_
37#define _RDS_PRIVATE_H_
38
39/********************
40 *Type definitions
41 */
42
43/*
44 * Rather than wasting cycles to manage locks which will only produce a
45 * small amount of concurrency, We decided to have one mutex on the entire
46 * heap. With the exception of coalescing, none of the routines should take
47 * substantial time since most are memory changes and simple computations.
48 */
49
50/* Synchronization and Threads support */
51
52/*
53 * We can have one of three thread models:
54 * cthreads: Mach threads (kernel or coroutine)
55 * lwp: Coda's lightweight process package
56 * pthreads: POSIX threads
57 *
58 * If RVM_USELWP is defined, then lwp support is compiled in.
59 * If RVM_USEPT is defined, then pthreads support is compiled in.
60 * If niether of these is defined, then cthreads support is compiled in.
61 *
62 * It is assumed in the rds package that cthreads and pthreads use
63 * preemptive scheduling, and they are synchronized appropriately.
64 *
65 * You must define only one of the above targets, and it must be defined
66 * consistently across the following packages: RVM, RDS, and URT
67 */
68
69#ifdef RVM_USELWP /* special thread support for Coda */
70#include "rvm_lwp.h"
71#elif defined(RVM_USEPT) /* special support for pthreads */
72#include "rvm_pthread.h"
73#else /* normal: use Cthreads */
74#include <cthreads.h>
75
76/* define types symbolically to permit use of non-Cthread thread support */
77#define RVM_MUTEX struct mutex
78#define RVM_CONDITION struct condition
79#endif
80
81#define START_CRITICAL mutex_lock(&heap_lock)
82#define LEAVE_CRITICAL_SECTION goto end_critical
83#define END_CRITICAL \
84 goto end_critical; \
85 end_critical: \
86 mutex_unlock(&heap_lock)
87
88/* Guards detect if the block structure had been illegally overwritten.
89 * One is placed after the size, and before user's data. The other is placed
90 * at the end of the block. */
91
92#define FREE_GUARD 0x345298af
93#define ALLOC_GUARD 0x783bd92c
94#define END_GUARD 0xfd10a32e
95
96#define RDS_BLOCK_HDR_SIZE (sizeof(block_size_t) + 2 * sizeof(guard_t))
97#define BLOCK_END(bp) \
98 ((guard_t *)((char *)(bp) + ((bp)->size * RDS_CHUNK_SIZE)) - 1)
99
100#define USER_BLOCK(bp) ((char *)&((bp)->prev))
101#define BLOCK_HDR(bp) \
102 ((free_block_t *)((char *)(bp) - (sizeof(block_size_t) + sizeof(guard_t))))
103
104typedef unsigned long block_size_t;
105typedef unsigned long guard_t;
106
107typedef struct fbt {
110 struct fbt *prev, *next;
112
113#define FREE_LIST_GUARD 0xad938945
114
115typedef struct {
119
120#define NEXT_CONSECUTIVE_BLOCK(bp) \
121 ((free_block_t *)((char *)(bp) + ((bp)->size * RDS_CHUNK_SIZE)))
122
123#define HEAP_LIST_GROWSIZE 20 /* Number of blocks to prealloc */
124
125#define RDS_HEAP_VERSION "Dynamic Allocator Using Rvm Release 0.1 1 Dec 1990"
126#define RDS_VERSION_MAX 80
127
128typedef struct {
129 char version[RDS_VERSION_MAX]; /* Version String */
130 unsigned long heaplength;
131 unsigned long chunk_size;
132 unsigned long nlists;
133 rds_stats_t stats; /* statistics on heap usage. */
134 unsigned long maxlist; /* Current non-empty largest list */
135 unsigned long dummy[10]; /* Space to allow header to grow */
136 free_list_t lists[1]; /* Number of lists is dynamically set */
138
139/* Global data extern declarations. */
142extern RVM_MUTEX heap_lock;
143
144extern int rds_tracing;
145extern FILE *rds_tracing_file;
146
147#define HEAP_INIT (RecoverableHeapStartAddress != 0)
148#define RDS_VERSION_STAMP (RecoverableHeapStartAddress->version)
149#define RDS_HEAPLENGTH (RecoverableHeapStartAddress->heaplength)
150#define RDS_CHUNK_SIZE (RecoverableHeapStartAddress->chunk_size)
151#define RDS_FREE_LIST (RecoverableHeapStartAddress->lists)
152#define RDS_NLISTS (RecoverableHeapStartAddress->nlists)
153#define RDS_MAXLIST (RecoverableHeapStartAddress->maxlist)
154#define RDS_STATS (RecoverableHeapStartAddress->stats)
155#define RDS_HIGH_ADDR (RecoverableHeapHighAddress)
156
157/*******************
158 * byte <-> string
159 */
160#ifdef __STDC__
161#define BCOPY(S, D, L) memcpy((D), (S), (L))
162#define BZERO(D, L) memset((D), 0, (L))
163#else
164#define BCOPY(S, D, L) bcopy((S), (D), (L))
165#define BZERO(D, L) bzero((D), (L))
166#endif
167
168/********************
169 * Definitions of worker functions.
170 */
171extern int print_heap();
174extern int put_block();
175
176/*********************
177 * Definitions of util functions
178 */
180
181/***********************
182 * Coalesce
183 */
184int merge_with_next_free(free_block_t *fbp, rvm_tid_t *tid, int *err);
185void coalesce(rvm_tid_t *tid, int *err);
186
187#endif /* _RDS_PRIVATE_H_ */
RVM_MUTEX heap_lock
Definition: rds_start.c:59
int merge_with_next_free(free_block_t *fbp, rvm_tid_t *tid, int *err)
Definition: rds_coalesce.c:32
#define RVM_MUTEX
Definition: rds_private.h:77
int rm_from_list()
free_block_t * split()
int print_heap()
Definition: rds_util.c:98
heap_header_t * RecoverableHeapStartAddress
Definition: rds_start.c:40
free_block_t * RecoverableHeapHighAddress
Definition: rds_start.c:46
struct fbt free_block_t
FILE * rds_tracing_file
Definition: rds_stats.c:23
unsigned long guard_t
Definition: rds_private.h:105
unsigned long block_size_t
Definition: rds_private.h:104
#define RDS_VERSION_MAX
Definition: rds_private.h:126
int rds_tracing
Definition: rds_stats.c:22
free_block_t * get_block()
void coalesce(rvm_tid_t *tid, int *err)
Definition: rds_coalesce.c:85
int put_block()
Definition: rds_private.h:107
struct fbt * prev
Definition: rds_private.h:110
guard_t type
Definition: rds_private.h:108
block_size_t size
Definition: rds_private.h:109
struct fbt * next
Definition: rds_private.h:110
Definition: rds_private.h:115
free_block_t * head
Definition: rds_private.h:117
guard_t guard
Definition: rds_private.h:116
Definition: rds_private.h:128
unsigned long nlists
Definition: rds_private.h:132
rds_stats_t stats
Definition: rds_private.h:133
unsigned long heaplength
Definition: rds_private.h:130
unsigned long chunk_size
Definition: rds_private.h:131
unsigned long maxlist
Definition: rds_private.h:134
Definition: rds.h:89
Definition: rvm.h:251