Deleted Added
full compact
hash_buf.c (1573) hash_buf.c (14272)
1/*-
1/*-
2 * Copyright (c) 1990, 1993
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Margo Seltzer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 19 unchanged lines hidden (view full) ---

30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Margo Seltzer.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 19 unchanged lines hidden (view full) ---

30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char sccsid[] = "@(#)hash_buf.c 8.2 (Berkeley) 2/21/94";
38static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94";
39#endif /* LIBC_SCCS and not lint */
40
41/*
42 * PACKAGE: hash
43 *
44 * DESCRIPTION:
45 * Contains buffer management
46 *

--- 5 unchanged lines hidden (view full) ---

52 * __reclaim_buf
53 * Internal
54 * newbuf
55 */
56
57#include <sys/param.h>
58
59#include <errno.h>
39#endif /* LIBC_SCCS and not lint */
40
41/*
42 * PACKAGE: hash
43 *
44 * DESCRIPTION:
45 * Contains buffer management
46 *

--- 5 unchanged lines hidden (view full) ---

52 * __reclaim_buf
53 * Internal
54 * newbuf
55 */
56
57#include <sys/param.h>
58
59#include <errno.h>
60#include <stddef.h>
60#include <stdio.h>
61#include <stdlib.h>
61#include <stdio.h>
62#include <stdlib.h>
63
62#ifdef DEBUG
63#include <assert.h>
64#endif
65
66#include <db.h>
67#include "hash.h"
68#include "page.h"
69#include "extern.h"
70
64#ifdef DEBUG
65#include <assert.h>
66#endif
67
68#include <db.h>
69#include "hash.h"
70#include "page.h"
71#include "extern.h"
72
71static BUFHEAD *newbuf __P((HTAB *, u_int, BUFHEAD *));
73static BUFHEAD *newbuf __P((HTAB *, u_int32_t, BUFHEAD *));
72
73/* Unlink B from its place in the lru */
74#define BUF_REMOVE(B) { \
75 (B)->prev->next = (B)->next; \
76 (B)->next->prev = (B)->prev; \
77}
78
79/* Insert B after P */

--- 17 unchanged lines hidden (view full) ---

97 *
98 * CAVEAT: The buffer header accessed via prev_bp's ovfl field may no longer
99 * be valid. Therefore, you must always verify that its address matches the
100 * address you are seeking.
101 */
102extern BUFHEAD *
103__get_buf(hashp, addr, prev_bp, newpage)
104 HTAB *hashp;
74
75/* Unlink B from its place in the lru */
76#define BUF_REMOVE(B) { \
77 (B)->prev->next = (B)->next; \
78 (B)->next->prev = (B)->prev; \
79}
80
81/* Insert B after P */

--- 17 unchanged lines hidden (view full) ---

99 *
100 * CAVEAT: The buffer header accessed via prev_bp's ovfl field may no longer
101 * be valid. Therefore, you must always verify that its address matches the
102 * address you are seeking.
103 */
104extern BUFHEAD *
105__get_buf(hashp, addr, prev_bp, newpage)
106 HTAB *hashp;
105 u_int addr;
107 u_int32_t addr;
106 BUFHEAD *prev_bp;
107 int newpage; /* If prev_bp set, indicates a new overflow page. */
108{
109 register BUFHEAD *bp;
108 BUFHEAD *prev_bp;
109 int newpage; /* If prev_bp set, indicates a new overflow page. */
110{
111 register BUFHEAD *bp;
110 register u_int is_disk_mask;
112 register u_int32_t is_disk_mask;
111 register int is_disk, segment_ndx;
112 SEGMENT segp;
113
114 is_disk = 0;
115 is_disk_mask = 0;
116 if (prev_bp) {
117 bp = prev_bp->ovfl;
118 if (!bp || (bp->addr != addr))

--- 16 unchanged lines hidden (view full) ---

135
136 if (!bp) {
137 bp = newbuf(hashp, addr, prev_bp);
138 if (!bp ||
139 __get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0))
140 return (NULL);
141 if (!prev_bp)
142 segp[segment_ndx] =
113 register int is_disk, segment_ndx;
114 SEGMENT segp;
115
116 is_disk = 0;
117 is_disk_mask = 0;
118 if (prev_bp) {
119 bp = prev_bp->ovfl;
120 if (!bp || (bp->addr != addr))

--- 16 unchanged lines hidden (view full) ---

137
138 if (!bp) {
139 bp = newbuf(hashp, addr, prev_bp);
140 if (!bp ||
141 __get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0))
142 return (NULL);
143 if (!prev_bp)
144 segp[segment_ndx] =
143 (BUFHEAD *)((u_int)bp | is_disk_mask);
145 (BUFHEAD *)((ptrdiff_t)bp | is_disk_mask);
144 } else {
145 BUF_REMOVE(bp);
146 MRU_INSERT(bp);
147 }
148 return (bp);
149}
150
151/*
152 * We need a buffer for this page. Either allocate one, or evict a resident
153 * one (if we have as many buffers as we're allowed) and put this one in.
154 *
155 * If newbuf finds an error (returning NULL), it also sets errno.
156 */
157static BUFHEAD *
158newbuf(hashp, addr, prev_bp)
159 HTAB *hashp;
146 } else {
147 BUF_REMOVE(bp);
148 MRU_INSERT(bp);
149 }
150 return (bp);
151}
152
153/*
154 * We need a buffer for this page. Either allocate one, or evict a resident
155 * one (if we have as many buffers as we're allowed) and put this one in.
156 *
157 * If newbuf finds an error (returning NULL), it also sets errno.
158 */
159static BUFHEAD *
160newbuf(hashp, addr, prev_bp)
161 HTAB *hashp;
160 u_int addr;
162 u_int32_t addr;
161 BUFHEAD *prev_bp;
162{
163 register BUFHEAD *bp; /* The buffer we're going to use */
164 register BUFHEAD *xbp; /* Temp pointer */
165 register BUFHEAD *next_xbp;
166 SEGMENT segp;
167 int segment_ndx;
163 BUFHEAD *prev_bp;
164{
165 register BUFHEAD *bp; /* The buffer we're going to use */
166 register BUFHEAD *xbp; /* Temp pointer */
167 register BUFHEAD *next_xbp;
168 SEGMENT segp;
169 int segment_ndx;
168 u_short oaddr, *shortp;
170 u_int16_t oaddr, *shortp;
169
170 oaddr = 0;
171 bp = LRU;
172 /*
173 * If LRU buffer is pinned, the buffer pool is too small. We need to
174 * allocate more buffers.
175 */
176 if (hashp->nbufs || (bp->flags & BUF_PIN)) {
177 /* Allocate a new one */
178 if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL)
179 return (NULL);
171
172 oaddr = 0;
173 bp = LRU;
174 /*
175 * If LRU buffer is pinned, the buffer pool is too small. We need to
176 * allocate more buffers.
177 */
178 if (hashp->nbufs || (bp->flags & BUF_PIN)) {
179 /* Allocate a new one */
180 if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL)
181 return (NULL);
182#ifdef PURIFY
183 memset(bp, 0xff, sizeof(BUFHEAD));
184#endif
180 if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) {
181 free(bp);
182 return (NULL);
183 }
185 if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) {
186 free(bp);
187 return (NULL);
188 }
189#ifdef PURIFY
190 memset(bp->page, 0xff, hashp->BSIZE);
191#endif
184 if (hashp->nbufs)
185 hashp->nbufs--;
186 } else {
187 /* Kick someone out */
188 BUF_REMOVE(bp);
189 /*
190 * If this is an overflow page with addr 0, it's already been
191 * flushed back in an overflow chain and initialized.
192 */
193 if ((bp->addr != 0) || (bp->flags & BUF_BUCKET)) {
194 /*
195 * Set oaddr before __put_page so that you get it
196 * before bytes are swapped.
197 */
192 if (hashp->nbufs)
193 hashp->nbufs--;
194 } else {
195 /* Kick someone out */
196 BUF_REMOVE(bp);
197 /*
198 * If this is an overflow page with addr 0, it's already been
199 * flushed back in an overflow chain and initialized.
200 */
201 if ((bp->addr != 0) || (bp->flags & BUF_BUCKET)) {
202 /*
203 * Set oaddr before __put_page so that you get it
204 * before bytes are swapped.
205 */
198 shortp = (u_short *)bp->page;
206 shortp = (u_int16_t *)bp->page;
199 if (shortp[0])
200 oaddr = shortp[shortp[0] - 1];
201 if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page,
202 bp->addr, (int)IS_BUCKET(bp->flags), 0))
203 return (NULL);
204 /*
205 * Update the pointer to this page (i.e. invalidate it).
206 *

--- 26 unchanged lines hidden (view full) ---

233 xbp->ovfl = 0;
234 xbp = next_xbp;
235
236 /* Check that ovfl pointer is up date. */
237 if (IS_BUCKET(xbp->flags) ||
238 (oaddr != xbp->addr))
239 break;
240
207 if (shortp[0])
208 oaddr = shortp[shortp[0] - 1];
209 if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page,
210 bp->addr, (int)IS_BUCKET(bp->flags), 0))
211 return (NULL);
212 /*
213 * Update the pointer to this page (i.e. invalidate it).
214 *

--- 26 unchanged lines hidden (view full) ---

241 xbp->ovfl = 0;
242 xbp = next_xbp;
243
244 /* Check that ovfl pointer is up date. */
245 if (IS_BUCKET(xbp->flags) ||
246 (oaddr != xbp->addr))
247 break;
248
241 shortp = (u_short *)xbp->page;
249 shortp = (u_int16_t *)xbp->page;
242 if (shortp[0])
243 /* set before __put_page */
244 oaddr = shortp[shortp[0] - 1];
245 if ((xbp->flags & BUF_MOD) && __put_page(hashp,
246 xbp->page, xbp->addr, 0, 0))
247 return (NULL);
248 xbp->addr = 0;
249 xbp->flags = 0;

--- 98 unchanged lines hidden ---
250 if (shortp[0])
251 /* set before __put_page */
252 oaddr = shortp[shortp[0] - 1];
253 if ((xbp->flags & BUF_MOD) && __put_page(hashp,
254 xbp->page, xbp->addr, 0, 0))
255 return (NULL);
256 xbp->addr = 0;
257 xbp->flags = 0;

--- 98 unchanged lines hidden ---