Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76ad8855 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Martijn Coenen
Browse files

BACKPORT: dm bufio: refactor adjust_total_allocated



Refactor adjust_total_allocated() so that it takes a bool argument
indicating if it should add or subtract the buffer size.

Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
(cherry picked from commit d0a328a385d2d1ab87e7a959d91c1841ed5a498f)

Bug: 136247322
Change-Id: I25522f4991d17c56f709f7c904f4480a427decbf
Signed-off-by: default avatarMartijn Coenen <maco@android.com>
parent 24d0cad2
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -306,14 +306,22 @@ static void __remove(struct dm_bufio_client *c, struct dm_buffer *b)

/*----------------------------------------------------------------*/

static void adjust_total_allocated(enum data_mode data_mode, long diff)
static void adjust_total_allocated(struct dm_buffer *b, bool unlink)
{
	enum data_mode data_mode;
	long diff;

	static unsigned long * const class_ptr[DATA_MODE_LIMIT] = {
		&dm_bufio_allocated_kmem_cache,
		&dm_bufio_allocated_get_free_pages,
		&dm_bufio_allocated_vmalloc,
	};

	data_mode = b->data_mode;
	diff = (long)b->c->block_size;
	if (unlink)
		diff = -diff;

	spin_lock(&param_spinlock);

	*class_ptr[data_mode] += diff;
@@ -484,7 +492,7 @@ static void __link_buffer(struct dm_buffer *b, sector_t block, int dirty)
	__insert(b->c, b);
	b->last_accessed = jiffies;

	adjust_total_allocated(b->data_mode, (long)c->block_size);
	adjust_total_allocated(b, false);
}

/*
@@ -500,7 +508,7 @@ static void __unlink_buffer(struct dm_buffer *b)
	__remove(b->c, b);
	list_del(&b->lru_list);

	adjust_total_allocated(b->data_mode, -(long)c->block_size);
	adjust_total_allocated(b, true);
}

/*