From patchwork Thu Dec 12 17:11:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11288749 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E697614B7 for ; Thu, 12 Dec 2019 17:13:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C632B22527 for ; Thu, 12 Dec 2019 17:13:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ORafC3vW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730246AbfLLRN0 (ORCPT ); Thu, 12 Dec 2019 12:13:26 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49652 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730097AbfLLRNZ (ORCPT ); Thu, 12 Dec 2019 12:13:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576170804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0M4cPw5UPqfIP6A7Wi24/RJTAYGo9ErvDujysnPmZU=; b=ORafC3vWSR/nLxdMxm1IUY7KS3OVD25vLq4K+2EEr9UAq68Xbfq2cOjAn5rZvlNIuaG779 RqXO9diO6tGa17sme+AERUMkXIFmll7l7/eHC1d9Bhvw3KU74kzX8I9BbltNaUU8bOAOsJ t9+U7Vkpvnqhc1a3v5gK5UWjNz3WkAQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-kEdgr6KoPPGF7N8xPrxtsw-1; Thu, 12 Dec 2019 12:13:20 -0500 X-MC-Unique: kEdgr6KoPPGF7N8xPrxtsw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82603107ACC4; Thu, 12 Dec 2019 17:13:18 +0000 (UTC) Received: from t480s.redhat.com (ovpn-117-65.ams2.redhat.com [10.36.117.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 544CE5C1C3; Thu, 12 Dec 2019 17:13:16 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Alexander Viro , linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v4 11/13] mm/vmscan: Move count_vm_event(DROP_SLAB) into drop_slab() Date: Thu, 12 Dec 2019 18:11:35 +0100 Message-Id: <20191212171137.13872-12-david@redhat.com> In-Reply-To: <20191212171137.13872-1-david@redhat.com> References: <20191212171137.13872-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Let's count within the function itself, so every invocation (of future users) will be counted. Cc: Alexander Viro Cc: Andrew Morton Cc: linux-fsdevel@vger.kernel.org Signed-off-by: David Hildenbrand Acked-by: Michal Hocko --- 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) From patchwork Thu Dec 12 17:11:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11288759 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 563BB138D for ; Thu, 12 Dec 2019 17:13:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 33AC5227BF for ; Thu, 12 Dec 2019 17:13:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YTAZqjSC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730070AbfLLRNm (ORCPT ); Thu, 12 Dec 2019 12:13:42 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23252 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730260AbfLLRNg (ORCPT ); Thu, 12 Dec 2019 12:13:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576170815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w/9RPsLV3hmHV/aDZLnceRyys47s4obu7zT1ywSY+3U=; b=YTAZqjSCLBiEE8kML0HOJn5E9JOKVc33ekj4DXHQypAKD/iRzyytggRDD8Q9P340+IZhbb 1cO/fkgBUnhgu1N4vj3T3VILZS86pNh/NSvgpU7yYOCWhbEA+bBpOzsbD8rJfuiDphBQsg R17b1xCkZDcGayWbhRQedmmm+AuUXXk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-ugnwkmHgMqya7HmLmDbz_g-1; Thu, 12 Dec 2019 12:13:31 -0500 X-MC-Unique: ugnwkmHgMqya7HmLmDbz_g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 546F1800053; Thu, 12 Dec 2019 17:13:29 +0000 (UTC) Received: from t480s.redhat.com (ovpn-117-65.ams2.redhat.com [10.36.117.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id C082A5C1C3; Thu, 12 Dec 2019 17:13:25 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, 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@vger.kernel.org Subject: [PATCH RFC v4 13/13] virtio-mem: Drop slab objects when unplug continues to fail Date: Thu, 12 Dec 2019 18:11:37 +0100 Message-Id: <20191212171137.13872-14-david@redhat.com> In-Reply-To: <20191212171137.13872-1-david@redhat.com> References: <20191212171137.13872-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 Cc: Andrew Morton Cc: Michal Hocko Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Oscar Salvador Cc: Igor Mammedov Cc: Dave Young Cc: Dan Williams Cc: Pavel Tatashin Cc: Stefan Hajnoczi Cc: Vlastimil Babka Cc: linux-fsdevel@vger.kernel.org Signed-off-by: David Hildenbrand --- 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);