Re: [RFC 3/3] zram: add swap_get_free hint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Minchan,

First of all, I agree with the overall purpose of your patch set.

On 09/04/2014 10:39 AM, Minchan Kim wrote:
This patch implement SWAP_GET_FREE handler in zram so that VM can
know how many zram has freeable space.
VM can use it to stop anonymous reclaiming once zram is full.

Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
---
  drivers/block/zram/zram_drv.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 88661d62e46a..8e22b20aa2db 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -951,6 +951,22 @@ static int zram_slot_free_notify(struct block_device *bdev,
  	return 0;
  }

+static int zram_get_free_pages(struct block_device *bdev, long *free)
+{
+	struct zram *zram;
+	struct zram_meta *meta;
+
+	zram = bdev->bd_disk->private_data;
+	meta = zram->meta;
+
+	if (!zram->limit_pages)
+		return 1;
+
+	*free = zram->limit_pages - zs_get_total_pages(meta->mem_pool);

Even if 'free' is zero here, there may be free spaces available to store more compressed pages into the zs_pool. I mean calculation above is not quite accurate and wastes memory, but have no better idea for now.

heesub

+
+	return 0;
+}
+
  static int zram_swap_hint(struct block_device *bdev,
  				unsigned int hint, void *arg)
  {
@@ -958,6 +974,8 @@ static int zram_swap_hint(struct block_device *bdev,

  	if (hint == SWAP_SLOT_FREE)
  		ret = zram_slot_free_notify(bdev, (unsigned long)arg);
+	else if (hint == SWAP_GET_FREE)
+		ret = zram_get_free_pages(bdev, arg);

  	return ret;
  }


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]