Commit c5a1c750 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

With streaming, we cannot allow a storage chunk to move once we

have started to fill it.  Add a param to the STV_trim() method
to indicate acceptability of move.

The only reason I don't remove STV_trim() entirely, is that a site
with gazillions very small objects, will want to disable streaming
and use malloc to squeeze as many objects into memory as possible.
parent fc8678c7
......@@ -1013,7 +1013,7 @@ int RFC2616_Do_Cond(const struct sess *sp);
struct object *STV_NewObject(struct busyobj *, struct objcore **,
const char *hint, unsigned len, uint16_t nhttp);
struct storage *STV_alloc(struct busyobj *, size_t size);
void STV_trim(struct storage *st, size_t size);
void STV_trim(struct storage *st, size_t size, int move_ok);
void STV_free(struct storage *st);
void STV_open(void);
void STV_close(void);
......
......@@ -195,7 +195,7 @@ vfp_nop_end(struct busyobj *bo)
return (0);
}
if (st->len < st->space)
STV_trim(st, st->len);
STV_trim(st, st->len, 1);
return (0);
}
......
......@@ -391,13 +391,13 @@ STV_alloc(struct busyobj *bo, size_t size)
}
void
STV_trim(struct storage *st, size_t size)
STV_trim(struct storage *st, size_t size, int move_ok)
{
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
AN(st->stevedore);
if (st->stevedore->trim)
st->stevedore->trim(st, size);
st->stevedore->trim(st, size, move_ok);
}
void
......
......@@ -42,7 +42,7 @@ struct lru;
typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
typedef void storage_open_f(const struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
typedef void storage_trim_f(struct storage *, size_t size);
typedef void storage_trim_f(struct storage *, size_t size, int move_ok);
typedef void storage_free_f(struct storage *);
typedef struct object *storage_allocobj_f(struct stevedore *, struct busyobj *,
struct objcore **, unsigned ltot, const struct stv_objsecrets *);
......
......@@ -488,7 +488,7 @@ smf_alloc(struct stevedore *st, size_t size)
/*--------------------------------------------------------------------*/
static void
smf_trim(struct storage *s, size_t size)
smf_trim(struct storage *s, size_t size, int move_ok)
{
struct smf *smf;
struct smf_sc *sc;
......@@ -499,6 +499,10 @@ smf_trim(struct storage *s, size_t size)
xxxassert(size > 0); /* XXX: seen */
CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC);
assert(size <= smf->size);
if (!move_ok)
return; /* XXX: trim_smf needs fixed */
sc = smf->sc;
size += (sc->pagesize - 1);
size &= ~(sc->pagesize - 1);
......
......@@ -145,7 +145,7 @@ sma_free(struct storage *s)
}
static void
sma_trim(struct storage *s, size_t size)
sma_trim(struct storage *s, size_t size, int move_ok)
{
struct sma_sc *sma_sc;
struct sma *sma;
......@@ -158,6 +158,10 @@ sma_trim(struct storage *s, size_t size)
assert(sma->sz == sma->s.space);
assert(size < sma->sz);
if (!move_ok)
return;
delta = sma->sz - size;
if (delta < 256)
return;
......
......@@ -522,19 +522,6 @@ smp_alloc(struct stevedore *st, size_t size)
size > 4096 ? 4096 : size, size, NULL, NULL, NULL));
}
/*--------------------------------------------------------------------
* Trim a bite
* XXX: We could trim the last allocation.
*/
static void
smp_trim(struct storage *ss, size_t size)
{
(void)ss;
(void)size;
}
/*--------------------------------------------------------------------
* We don't track frees of storage, we track the objects which own the
* storage and when there are no more objects in in the first segment,
......@@ -562,7 +549,6 @@ const struct stevedore smp_stevedore = {
.alloc = smp_alloc,
.allocobj = smp_allocobj,
.free = smp_free,
.trim = smp_trim,
};
/*--------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment