Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4453225imm; Tue, 7 Aug 2018 01:35:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf8e2GqLaO9ylsr4PJ3UfmHS/sZKXfEFw5CPG9qkF+hU54U6NaZEy/XyX0okolD2YBw0LAo X-Received: by 2002:a17:902:599b:: with SMTP id p27-v6mr16634756pli.191.1533630943567; Tue, 07 Aug 2018 01:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533630943; cv=none; d=google.com; s=arc-20160816; b=nxeZ1yG6H+SwuYm0cAJeOape+OJx6u54oK0r3iiuCo4jDxGpe+6+SphP5WCItiIUgy MJrF1TfeDIRr4EaTSJeGc0bvI39MbHb/YKijbKQiaDGT/XPJTZFEs7VQIXXeNJURBuxv 2R7aE+rOmB5wSF2LW2BB/dTkedkOEGyxB5rPDvYQ8Yp5orznNOmKwoNc/oLlxNU0jm5K /X6i9/w9oGr+YJCbFllObYxZXvREz33nh5anI73hypPMAlHrUUMvUJRlwN7W5mbtvppH hxGv8IvZPzoWTXoBp3myMgj8ya768HLHE1SAr6G4R14ZkxfUFGSNbD92qDf1ci3Go+kA UV8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :arc-authentication-results; bh=ujdBM/tW95L08UNIltAADV1Emw05U29KuLq3Q94gZPA=; b=Ii83+J2mUpC1xH5HC7SiAKbT2SWApbRLt8boBCX5HAyrfpz89lxI912AOqhWQGJBtB xcjPp+Rb6tkOLiQhNq4t6qZHQbMRaBX2eGh64jziVlFTu2X8deDrD2MGwABp9JgRrifV 5YWuye+eIBXAZvySkhfijaT27Mgai8APnNPc1u3t/9pDaPAM/dA092izxt/BbkH5RrYP tAlN9j1iPfubgMmG49LtSwrSikOeBfOCoMlGEI04go41B8j757iuwRNbipqrzzssfoP3 ic0jociCwPghXfLP78YIphQWvei4/F7MIC4UkdJkmWtpQP49HPCVWlAQ+YbN1zPl40kC kyxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3-v6si642675plb.270.2018.08.07.01.35.16; Tue, 07 Aug 2018 01:35:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388578AbeHGIrf (ORCPT + 99 others); Tue, 7 Aug 2018 04:47:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:56394 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733217AbeHGIrf (ORCPT ); Tue, 7 Aug 2018 04:47:35 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7C255ACEF; Tue, 7 Aug 2018 06:34:44 +0000 (UTC) Subject: Re: [PATCH 1/4] xen/blkback: don't keep persistent grants too long To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, konrad.wilk@oracle.com, axboe@kernel.dk, boris.ostrovsky@oracle.com References: <20180806113403.24728-1-jgross@suse.com> <20180806113403.24728-2-jgross@suse.com> <20180806155852.7jvudjpzzq6fdp33@mac> From: Juergen Gross Openpgp: preference=signencrypt Aut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Cwu2sqkI3LLbTdrnyDZaixT2T0f4tyF5Lfs+Ha8xVMhIyzNb1byDI5FKCb Message-ID: Date: Tue, 7 Aug 2018 08:34:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180806155852.7jvudjpzzq6fdp33@mac> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/08/18 17:58, Roger Pau Monné wrote: > On Mon, Aug 06, 2018 at 01:33:59PM +0200, Juergen Gross wrote: >> Persistent grants are allocated until a threshold per ring is being >> reached. Those grants won't be freed until the ring is being destroyed >> meaning there will be resources kept busy which might no longer be >> used. >> >> Instead of freeing only persistent grants until the threshold is >> reached add a timestamp and remove all persistent grants not having >> been in use for a minute. >> >> Signed-off-by: Juergen Gross >> --- >> drivers/block/xen-blkback/blkback.c | 77 +++++++++++++++++++++++-------------- >> drivers/block/xen-blkback/common.h | 1 + >> 2 files changed, 50 insertions(+), 28 deletions(-) > > You should document this new parameter in > Documentation/ABI/testing/sysfs-driver-xen-blkback. Yes. > >> >> diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c >> index b55b245e8052..485e3ecab144 100644 >> --- a/drivers/block/xen-blkback/blkback.c >> +++ b/drivers/block/xen-blkback/blkback.c >> @@ -84,6 +84,18 @@ MODULE_PARM_DESC(max_persistent_grants, >> "Maximum number of grants to map persistently"); >> >> /* >> + * How long a persistent grant is allowed to remain allocated without being in >> + * use. The time is in seconds, 0 means indefinitely long. >> + */ >> + >> +unsigned int xen_blkif_pgrant_timeout = 60; >> +module_param_named(persistent_grant_unused_seconds, xen_blkif_pgrant_timeout, >> + uint, 0644); >> +MODULE_PARM_DESC(persistent_grant_unused_seconds, >> + "Time in seconds an unused persistent grant is allowed to " >> + "remain allocated. Default is 60, 0 means unlimited."); >> + >> +/* >> * Maximum number of rings/queues blkback supports, allow as many queues as there >> * are CPUs if user has not specified a value. >> */ >> @@ -123,6 +135,13 @@ module_param(log_stats, int, 0644); >> /* Number of free pages to remove on each call to gnttab_free_pages */ >> #define NUM_BATCH_FREE_PAGES 10 >> >> +static inline bool persistent_gnt_timeout(struct persistent_gnt *persistent_gnt) >> +{ >> + return xen_blkif_pgrant_timeout && >> + (jiffies - persistent_gnt->last_used >= >> + HZ * xen_blkif_pgrant_timeout); >> +} >> + >> static inline int get_free_page(struct xen_blkif_ring *ring, struct page **page) >> { >> unsigned long flags; >> @@ -278,6 +297,7 @@ static void put_persistent_gnt(struct xen_blkif_ring *ring, >> { >> if(!test_bit(PERSISTENT_GNT_ACTIVE, persistent_gnt->flags)) >> pr_alert_ratelimited("freeing a grant already unused\n"); >> + persistent_gnt->last_used = jiffies; >> set_bit(PERSISTENT_GNT_WAS_ACTIVE, persistent_gnt->flags); >> clear_bit(PERSISTENT_GNT_ACTIVE, persistent_gnt->flags); >> atomic_dec(&ring->persistent_gnt_in_use); >> @@ -374,23 +394,23 @@ static void purge_persistent_gnt(struct xen_blkif_ring *ring) >> bool scan_used = false, clean_used = false; >> struct rb_root *root; >> >> - if (ring->persistent_gnt_c < xen_blkif_max_pgrants || >> - (ring->persistent_gnt_c == xen_blkif_max_pgrants && >> - !ring->blkif->vbd.overflow_max_grants)) { >> - goto out; >> - } >> - >> if (work_busy(&ring->persistent_purge_work)) { >> pr_alert_ratelimited("Scheduled work from previous purge is still busy, cannot purge list\n"); >> goto out; >> } >> >> - num_clean = (xen_blkif_max_pgrants / 100) * LRU_PERCENT_CLEAN; >> - num_clean = ring->persistent_gnt_c - xen_blkif_max_pgrants + num_clean; >> - num_clean = min(ring->persistent_gnt_c, num_clean); >> - if ((num_clean == 0) || >> - (num_clean > (ring->persistent_gnt_c - atomic_read(&ring->persistent_gnt_in_use)))) >> - goto out; >> + if (ring->persistent_gnt_c < xen_blkif_max_pgrants || >> + (ring->persistent_gnt_c == xen_blkif_max_pgrants && >> + !ring->blkif->vbd.overflow_max_grants)) { >> + num_clean = 0; >> + } else { >> + num_clean = (xen_blkif_max_pgrants / 100) * LRU_PERCENT_CLEAN; >> + num_clean = ring->persistent_gnt_c - xen_blkif_max_pgrants + >> + num_clean; >> + num_clean = min(ring->persistent_gnt_c, num_clean); >> + pr_debug("Going to purge at least %u persistent grants\n", >> + num_clean); >> + } >> >> /* >> * At this point, we can assure that there will be no calls >> @@ -401,9 +421,7 @@ static void purge_persistent_gnt(struct xen_blkif_ring *ring) >> * number of grants. >> */ >> >> - total = num_clean; >> - >> - pr_debug("Going to purge %u persistent grants\n", num_clean); >> + total = 0; >> >> BUG_ON(!list_empty(&ring->persistent_purge_list)); >> root = &ring->persistent_gnts; >> @@ -419,39 +437,42 @@ static void purge_persistent_gnt(struct xen_blkif_ring *ring) >> >> if (test_bit(PERSISTENT_GNT_ACTIVE, persistent_gnt->flags)) >> continue; >> - if (!scan_used && >> + if (!scan_used && !persistent_gnt_timeout(persistent_gnt) && >> (test_bit(PERSISTENT_GNT_WAS_ACTIVE, persistent_gnt->flags))) > > If you store the jiffies of the time when the grant was last used it > seems like we could get rid of the PERSISTENT_GNT_WAS_ACTIVE flag and > instead use the per-grant jiffies and the jiffies from the last scan > in order to decide which grants to remove? True. This might make the control flow a little bit easier to understand. Juergen