zram_drv.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Compressed RAM block device
  3. *
  4. * Copyright (C) 2008, 2009, 2010 Nitin Gupta
  5. * 2012, 2013 Minchan Kim
  6. *
  7. * This code is released using a dual license strategy: BSD/GPL
  8. * You can choose the licence that better fits your requirements.
  9. *
  10. * Released under the terms of 3-clause BSD License
  11. * Released under the terms of GNU General Public License Version 2.0
  12. *
  13. */
  14. #ifndef _ZRAM_DRV_H_
  15. #define _ZRAM_DRV_H_
  16. #include <linux/spinlock.h>
  17. #include <linux/zsmalloc.h>
  18. #include "zcomp.h"
  19. /*
  20. * Some arbitrary value. This is just to catch
  21. * invalid value for num_devices module parameter.
  22. */
  23. static const unsigned max_num_devices = 32;
  24. /*-- Configurable parameters */
  25. /*
  26. * Pages that compress to size greater than this are stored
  27. * uncompressed in memory.
  28. */
  29. static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
  30. /*
  31. * NOTE: max_zpage_size must be less than or equal to:
  32. * ZS_MAX_ALLOC_SIZE. Otherwise, zs_malloc() would
  33. * always return failure.
  34. */
  35. /*-- End of configurable params */
  36. #define SECTOR_SHIFT 9
  37. #define SECTOR_SIZE (1 << SECTOR_SHIFT)
  38. #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
  39. #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
  40. #define ZRAM_LOGICAL_BLOCK_SHIFT 12
  41. #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
  42. #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
  43. (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
  44. /* Flags for zram pages (table[page_no].flags) */
  45. enum zram_pageflags {
  46. /* Page consists entirely of zeros */
  47. ZRAM_ZERO,
  48. __NR_ZRAM_PAGEFLAGS,
  49. };
  50. /*-- Data structures */
  51. /* Allocated for each disk page */
  52. struct table {
  53. unsigned long handle;
  54. u16 size; /* object size (excluding header) */
  55. u8 flags;
  56. } __aligned(4);
  57. struct zram_stats {
  58. atomic64_t compr_data_size; /* compressed size of pages stored */
  59. atomic64_t num_reads; /* failed + successful */
  60. atomic64_t num_writes; /* --do-- */
  61. atomic64_t failed_reads; /* should NEVER! happen */
  62. atomic64_t failed_writes; /* can happen when memory is too low */
  63. atomic64_t invalid_io; /* non-page-aligned I/O requests */
  64. atomic64_t notify_free; /* no. of swap slot free notifications */
  65. atomic64_t zero_pages; /* no. of zero filled pages */
  66. atomic64_t pages_stored; /* no. of pages currently stored */
  67. };
  68. struct zram_meta {
  69. rwlock_t tb_lock; /* protect table */
  70. struct table *table;
  71. struct zs_pool *mem_pool;
  72. };
  73. struct zram {
  74. struct zram_meta *meta;
  75. struct request_queue *queue;
  76. struct gendisk *disk;
  77. struct zcomp *comp;
  78. /* Prevent concurrent execution of device init, reset and R/W request */
  79. struct rw_semaphore init_lock;
  80. /*
  81. * This is the limit on amount of *uncompressed* worth of data
  82. * we can store in a disk.
  83. */
  84. u64 disksize; /* bytes */
  85. int max_comp_streams;
  86. struct zram_stats stats;
  87. char compressor[10];
  88. };
  89. #endif