staticint zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm)
{ int ret;
ret = comp->ops->create_ctx(comp->params, &zstrm->ctx); if (ret) return ret;
zstrm->local_copy = vzalloc(PAGE_SIZE); /* * allocate 2 pages. 1 for compressed data, plus 1 extra for the * case when compressed size is larger than the original one
*/
zstrm->buffer = vzalloc(2 * PAGE_SIZE); if (!zstrm->buffer || !zstrm->local_copy) {
zcomp_strm_free(comp, zstrm); return -ENOMEM;
} return 0;
}
staticconststruct zcomp_ops *lookup_backend_ops(constchar *comp)
{ int i = 0;
while (backends[i]) { if (sysfs_streq(comp, backends[i]->name)) break;
i++;
} return backends[i];
}
/* * Inspired by zswap * * stream is returned with ->mutex locked which prevents * cpu_dead() from releasing this stream under us, however * there is still a race window between raw_cpu_ptr() and * mutex_lock(), during which we could have been migrated * from a CPU that has already destroyed its stream. If * so then unlock and re-try on the current CPU.
*/
mutex_lock(&zstrm->lock); if (likely(zstrm->buffer)) return zstrm;
mutex_unlock(&zstrm->lock);
}
}
/* * The backends array has a sentinel NULL value, so the minimum * size is 1. In order to be valid the array, apart from the * sentinel NULL element, should have at least one compression * backend selected.
*/
BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL); if (!comp) return ERR_PTR(-ENOMEM);
comp->ops = lookup_backend_ops(alg); if (!comp->ops) {
kfree(comp); return ERR_PTR(-EINVAL);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.