Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4936794imm; Tue, 7 Aug 2018 09:45:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeLY99P9xYlknL3vjM0TNrorw9D69HTH6GkhT5VpwUL9ftrqcH+S5uarcUYdMz9hX1fN19U X-Received: by 2002:a62:4898:: with SMTP id q24-v6mr22398794pfi.58.1533660315132; Tue, 07 Aug 2018 09:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533660315; cv=none; d=google.com; s=arc-20160816; b=uvcLbE75zyNYSmXB9D1a5YHEZQbONitRNQAmcnSgCOHXlZSlzEcCYYBQ+Iq1GeGVl6 Q1rzuqjbaB75Np/ahmYrfK+RKaBwV3/opjXb1RWYqfTY7G1WOKnRm2u8suh93q+lfnXk A6Ja9K/tJKmS1NjJNOHEdBKaC1qGSdfDZkZJci47WydNaIDzgFTc5/dVsvkR3kz0DLTc mYjz2JKNA+GGbZxvJGaAiRdE0BfGev3gLev5PlrLNO+Rq2ik9j6+kZmYK1DiIqpHIZgM dTxTSaQX04zr+w2PJTNXCSt+djMzkM2l/qwkz3jNrtETulpk9RID+jd6gboQ9dZ+Mau6 kP4w== 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=/YB0gVj/7bidIFP/sNTldxg+gtydNJHOcSB9FfPg27s=; b=GXXm6eAQrfa3n7WcwD0X0oUsb5KKW6J/QQ1BhoPmQZE/fla1/wOuv6PdYXiS9lVysq BpR7OhWpSswYTRz5AcDhw20Va4dUUUq3wCeRyR8dYZckdTu/gaLcQtxGUos0e+q04/bD mf+UKyqrMsuSS7QsDVSHjFHJitTHcWb0ikkMI7wLTktoXzP0m0enfXIBuYLQ0RvzT8m5 BzYrjU68hNVgOtNkbHTJFssNwrGgsLDH3N86fbn3xv3oh9Sc8rU9AhZwByCb2ZFGH0xF 59PwTpgpS+U3j9Je+H8V59xDFptIsnL9yA19uo5uStHhrgV5VhfSFEXnib7Nc0X3IYHc 2kSg== 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 200-v6si1826111pgf.378.2018.08.07.09.45.00; Tue, 07 Aug 2018 09:45:15 -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 S2390087AbeHGSLj (ORCPT + 99 others); Tue, 7 Aug 2018 14:11:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:44542 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388481AbeHGSLj (ORCPT ); Tue, 7 Aug 2018 14:11:39 -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 82B71AE78; Tue, 7 Aug 2018 15:56:39 +0000 (UTC) Subject: Re: [PATCH 2/4] xen/blkfront: cleanup stale persistent grants 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-4-jgross@suse.com> <20180806161638.nmjamflckekeuyzb@mac> <20180807141404.lzsqtdd2seqgwtgx@mac> From: Juergen Gross Openpgp: preference=signencrypt Autocrypt: addr=jgross@suse.com; prefer-encrypt=mutual; keydata= xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOB ycWxw3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJve dYm8Of8Zd621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJ NwQpd369y9bfIhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvx XP3FAp2pkW0xqG7/377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEB AAHNHkp1ZXJnZW4gR3Jvc3MgPGpncm9zc0BzdXNlLmRlPsLAeQQTAQIAIwUCU4xw6wIbAwcL CQgHAwIBBhUIAgkKCwQWAgMBAh4BAheAAAoJELDendYovxMvi4UH/Ri+OXlObzqMANruTd4N zmVBAZgx1VW6jLc8JZjQuJPSsd/a+bNr3BZeLV6lu4Pf1Yl2Log129EX1KWYiFFvPbIiq5M5 kOXTO8Eas4CaScCvAZ9jCMQCgK3pFqYgirwTgfwnPtxFxO/F3ZcS8jovza5khkSKL9JGq8Nk czDTruQ/oy0WUHdUr9uwEfiD9yPFOGqp4S6cISuzBMvaAiC5YGdUGXuPZKXLpnGSjkZswUzY d9BVSitRL5ldsQCg6GhDoEAeIhUC4SQnT9SOWkoDOSFRXZ+7+WIBGLiWMd+yKDdRG5RyP/8f 3tgGiB6cyuYfPDRGsELGjUaTUq3H2xZgIPfOwE0EU4xwFgEIAMsx+gDjgzAY4H1hPVXgoLK8 B93sTQFN9oC6tsb46VpxyLPfJ3T1A6Z6MVkLoCejKTJ3K9MUsBZhxIJ0hIyvzwI6aYJsnOew cCiCN7FeKJ/oA1RSUemPGUcIJwQuZlTOiY0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1v4Z1wthmoyUgGN0LPTIm+B5vdY82wI5qe9uN6UOGyTH2B3p hRQUWqCwu2sqkI3LLbTdrnyDZaixT2T0f4tyF5Lfs+Ha8xVMhIyzNb1byDI5FKCb Message-ID: Date: Tue, 7 Aug 2018 17:56:38 +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: <20180807141404.lzsqtdd2seqgwtgx@mac> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/08/18 16:14, Roger Pau Monné wrote: > On Tue, Aug 07, 2018 at 08:31:31AM +0200, Juergen Gross wrote: >> On 06/08/18 18:16, Roger Pau Monné wrote: >>> On Mon, Aug 06, 2018 at 01:34:01PM +0200, Juergen Gross wrote: >>>> Add a periodic cleanup function to remove old persistent grants which >>>> are no longer in use on the backend side. This avoids starvation in >>>> case there are lots of persistent grants for a device which no longer >>>> is involved in I/O business. >>>> >>>> Signed-off-by: Juergen Gross >>>> --- >>>> drivers/block/xen-blkfront.c | 99 ++++++++++++++++++++++++++++++++++++++++++-- >>>> 1 file changed, 95 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c >>>> index b5cedccb5d7d..19feb8835fc4 100644 >>>> --- a/drivers/block/xen-blkfront.c >>>> +++ b/drivers/block/xen-blkfront.c >>>> @@ -46,6 +46,7 @@ >>>> #include >>>> #include >>>> #include >>>> +#include >>>> >>>> #include >>>> #include >>>> @@ -121,6 +122,9 @@ static inline struct blkif_req *blkif_req(struct request *rq) >>>> >>>> static DEFINE_MUTEX(blkfront_mutex); >>>> static const struct block_device_operations xlvbd_block_fops; >>>> +static struct delayed_work blkfront_work; >>>> +static LIST_HEAD(info_list); >>>> +static bool blkfront_work_active; >>>> >>>> /* >>>> * Maximum number of segments in indirect requests, the actual value used by >>>> @@ -216,6 +220,7 @@ struct blkfront_info >>>> /* Save uncomplete reqs and bios for migration. */ >>>> struct list_head requests; >>>> struct bio_list bio_list; >>>> + struct list_head info_list; >>>> }; >>>> >>>> static unsigned int nr_minors; >>>> @@ -1764,6 +1769,12 @@ static int write_per_ring_nodes(struct xenbus_transaction xbt, >>>> return err; >>>> } >>>> >>>> +static void free_info(struct blkfront_info *info) >>>> +{ >>>> + list_del(&info->info_list); >>>> + kfree(info); >>>> +} >>>> + >>>> /* Common code used when first setting up, and when resuming. */ >>>> static int talk_to_blkback(struct xenbus_device *dev, >>>> struct blkfront_info *info) >>>> @@ -1885,7 +1896,10 @@ static int talk_to_blkback(struct xenbus_device *dev, >>>> destroy_blkring: >>>> blkif_free(info, 0); >>>> >>>> - kfree(info); >>>> + mutex_lock(&blkfront_mutex); >>>> + free_info(info); >>>> + mutex_unlock(&blkfront_mutex); >>>> + >>>> dev_set_drvdata(&dev->dev, NULL); >>>> >>>> return err; >>>> @@ -1996,6 +2010,10 @@ static int blkfront_probe(struct xenbus_device *dev, >>>> info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); >>>> dev_set_drvdata(&dev->dev, info); >>>> >>>> + mutex_lock(&blkfront_mutex); >>>> + list_add(&info->info_list, &info_list); >>>> + mutex_unlock(&blkfront_mutex); >>>> + >>>> return 0; >>>> } >>>> >>>> @@ -2306,6 +2324,15 @@ static void blkfront_gather_backend_features(struct blkfront_info *info) >>>> if (indirect_segments <= BLKIF_MAX_SEGMENTS_PER_REQUEST) >>>> indirect_segments = 0; >>>> info->max_indirect_segments = indirect_segments; >>>> + >>>> + if (info->feature_persistent) { >>>> + mutex_lock(&blkfront_mutex); >>>> + if (!blkfront_work_active) { >>>> + blkfront_work_active = true; >>>> + schedule_delayed_work(&blkfront_work, HZ * 10); >>> >>> Does it make sense to provide a module parameter to rune the schedule >>> of the cleanup routine? >> >> I don't think this is something anyone would like to tune. >> >> In case you think it should be tunable I can add a parameter, of course. > > We can always add it later if required. I'm fine as-is now. > >>> >>>> + } >>>> + mutex_unlock(&blkfront_mutex); >>> >>> Is it really necessary to have the blkfront_work_active boolean? What >>> happens if you queue the same delayed work more than once? >> >> In case there is already work queued later calls of >> schedule_delayed_work() will be ignored. >> >> So yes, I can drop the global boolean (I still need a local flag in >> blkfront_delay_work() for controlling the need to call >> schedule_delayed_work() again). > > Can't you just call schedule_delayed_work if info->feature_persistent > is set, even if that means calling it multiple times if multiple > blkfront instances are using persistent grants? I don't like that. With mq we have a high chance for multiple instances to use persistent grants and a local bool is much cheaper than unneeded calls of schedule_delayed_work(). Juergen