zsmalloc.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * zsmalloc memory allocator
  3. *
  4. * Copyright (C) 2011 Nitin Gupta
  5. *
  6. * This code is released using a dual license strategy: BSD/GPL
  7. * You can choose the license that better fits your requirements.
  8. *
  9. * Released under the terms of 3-clause BSD License
  10. * Released under the terms of GNU General Public License Version 2.0
  11. */
  12. #ifndef _ZS_MALLOC_H_
  13. #define _ZS_MALLOC_H_
  14. #include <linux/types.h>
  15. /*
  16. * zsmalloc mapping modes
  17. *
  18. * NOTE: These only make a difference when a mapped object spans pages.
  19. * They also have no effect when PGTABLE_MAPPING is selected.
  20. */
  21. enum zs_mapmode {
  22. ZS_MM_RW, /* normal read-write mapping */
  23. ZS_MM_RO, /* read-only (no copy-out at unmap time) */
  24. ZS_MM_WO /* write-only (no copy-in at map time) */
  25. /*
  26. * NOTE: ZS_MM_WO should only be used for initializing new
  27. * (uninitialized) allocations. Partial writes to already
  28. * initialized allocations should use ZS_MM_RW to preserve the
  29. * existing data.
  30. */
  31. };
  32. struct zs_pool;
  33. struct zs_pool *zs_create_pool(gfp_t flags);
  34. void zs_destroy_pool(struct zs_pool *pool);
  35. unsigned long zs_malloc(struct zs_pool *pool, size_t size);
  36. void zs_free(struct zs_pool *pool, unsigned long obj);
  37. void *zs_map_object(struct zs_pool *pool, unsigned long handle,
  38. enum zs_mapmode mm);
  39. void zs_unmap_object(struct zs_pool *pool, unsigned long handle);
  40. u64 zs_get_total_size_bytes(struct zs_pool *pool);
  41. #endif