* [PATCH RFC v4 11/13] mm/vmscan: Move count_vm_event(DROP_SLAB) into drop_slab()
[not found] <20191212171137.13872-1-david@redhat.com>
@ 2019-12-12 17:11 ` David Hildenbrand
2020-02-25 14:13 ` Michal Hocko
2019-12-12 17:11 ` [PATCH RFC v4 13/13] virtio-mem: Drop slab objects when unplug continues to fail David Hildenbrand
1 sibling, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2019-12-12 17:11 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, virtio-dev, virtualization, kvm, Michal Hocko,
Andrew Morton, Michael S . Tsirkin, David Hildenbrand,
Alexander Viro, linux-fsdevel
Let's count within the function itself, so every invocation (of future
users) will be counted.
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: David Hildenbrand <david@redhat.com>
---
fs/drop_caches.c | 4 +---
mm/vmscan.c | 1 +
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index d31b6c72b476..a042da782fcd 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -61,10 +61,8 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
iterate_supers(drop_pagecache_sb, NULL);
count_vm_event(DROP_PAGECACHE);
}
- if (sysctl_drop_caches & 2) {
+ if (sysctl_drop_caches & 2)
drop_slab();
- count_vm_event(DROP_SLAB);
- }
if (!stfu) {
pr_info("%s (%d): drop_caches: %d\n",
current->comm, task_pid_nr(current),
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 5a6445e86328..c3e53502a84a 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -726,6 +726,7 @@ void drop_slab(void)
for_each_online_node(nid)
drop_slab_node(nid);
+ count_vm_event(DROP_SLAB);
}
static inline int is_page_cache_freeable(struct page *page)
--
2.23.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH RFC v4 13/13] virtio-mem: Drop slab objects when unplug continues to fail
[not found] <20191212171137.13872-1-david@redhat.com>
2019-12-12 17:11 ` [PATCH RFC v4 11/13] mm/vmscan: Move count_vm_event(DROP_SLAB) into drop_slab() David Hildenbrand
@ 2019-12-12 17:11 ` David Hildenbrand
1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2019-12-12 17:11 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, virtio-dev, virtualization, kvm, Michal Hocko,
Andrew Morton, Michael S . Tsirkin, David Hildenbrand,
Alexander Viro, Jason Wang, Oscar Salvador, Igor Mammedov,
Dave Young, Dan Williams, Pavel Tatashin, Stefan Hajnoczi,
Vlastimil Babka, linux-fsdevel
Start dropping slab objects after 30 minutes and repeat every 30 minutes
in case we can't unplug more memory using alloc_contig_range().
Log messages and make it configurable. Enable dropping slab objects as
default (especially, reclaimable slab objects that are not movable).
In the future, we might want to implement+use drop_slab_range(), which
will also come in handy for other users (e.g., offlining, gigantic huge
pages).
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/virtio/virtio_mem.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index 3a57434f92ed..8f25f7453a08 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -25,6 +25,11 @@ static bool unplug_online = true;
module_param(unplug_online, bool, 0644);
MODULE_PARM_DESC(unplug_online, "Try to unplug online memory");
+static bool drop_slab_objects = true;
+module_param(drop_slab_objects, bool, 0644);
+MODULE_PARM_DESC(drop_slab_objects,
+ "Drop slab objects when unplug continues to fail");
+
enum virtio_mem_mb_state {
/* Unplugged, not added to Linux. Can be reused later. */
VIRTIO_MEM_MB_STATE_UNUSED = 0,
@@ -1384,6 +1389,7 @@ static int virtio_mem_mb_unplug_any_sb_online(struct virtio_mem *vm,
static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff)
{
uint64_t nb_sb = diff / vm->subblock_size;
+ bool retried = false;
unsigned long mb_id;
int rc;
@@ -1421,6 +1427,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff)
return 0;
}
+retry_locked:
/* Try to unplug subblocks of partially plugged online blocks. */
virtio_mem_for_each_mb_state(vm, mb_id,
VIRTIO_MEM_MB_STATE_ONLINE_PARTIAL) {
@@ -1445,6 +1452,29 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff)
}
mutex_unlock(&vm->hotplug_mutex);
+
+ /*
+ * If we can't unplug the requested amount of memory for a long time,
+ * start freeing up memory in caches. This might harm performance,
+ * is configurable, and we log a message. Retry imemdiately a second
+ * time - then wait another VIRTIO_MEM_RETRY_TIMER_MAX_MS.
+ */
+ if (nb_sb && !retried && drop_slab_objects &&
+ vm->retry_timer_ms == VIRTIO_MEM_RETRY_TIMER_MAX_MS) {
+ if (vm->nid == NUMA_NO_NODE) {
+ dev_info(&vm->vdev->dev, "dropping all slab objects\n");
+ drop_slab();
+ } else {
+ dev_info(&vm->vdev->dev,
+ "dropping all slab objects on node=%d\n",
+ vm->nid);
+ drop_slab_node(vm->nid);
+ }
+ retried = true;
+ mutex_lock(&vm->hotplug_mutex);
+ goto retry_locked;
+ }
+
return nb_sb ? -EBUSY : 0;
out_unlock:
mutex_unlock(&vm->hotplug_mutex);
--
2.23.0
^ permalink raw reply related [flat|nested] 3+ messages in thread