Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1020403ybv; Thu, 13 Feb 2020 14:09:35 -0800 (PST) X-Google-Smtp-Source: APXvYqzNJ2REl1ydJGi0V2zvaYaC76NX15vEs0VPwt41rSaSQfxQj7WFvoNgxh/fcok2B6Qc87rL X-Received: by 2002:a05:6830:2154:: with SMTP id r20mr15735653otd.131.1581631775359; Thu, 13 Feb 2020 14:09:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581631775; cv=none; d=google.com; s=arc-20160816; b=vb9tqd+FXQIF+ccuMbo8IkgHr7TAITyhFovRAmxo3jGDjOK2dTAaPYSgtqiet7gfQt kndf0CTwSzIJsAPbLvESDn6EYiOVOaFx/HNVs0pinFqRxAm2qi4ExrATFYN+4n0xE4Qp w3dswIuRlAT4ZTLZ+MfxYvNZ2GJ2/gNmWTRG7lBqNn8BY5ejNTOfKlg9BUModEg68aEr mGlnrRnQ2T5zwebuLBP+wgyyFMBz0xlLA6KH1pNOUw7bEb8VCepT2LMdcVe4ZyKLI09C PrMI06m0wZrYQ/kjF++6lCyhtX6yQcWWD4bDWnaFFQYVg1afHtQI0fZkqQlfe4lLPotw 2LoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PvTmvGfvJmOv7sMbAjwocI81PqYWLyNw6wRoKoHV6qg=; b=vMI7TjOAmFvoyoM676dD0G04lWr8MH7rUrPFsuccY/M0fwyelpeldrrWplHqsMH91e xREQNhJOGqRVVtZpFk/YIdOlGByQthYSxFum6T++1TyxG7WDeyrHYi3QxLNOfCEPLC4t hF9rW+EjKLzzNA0NOs940iCiqORG/KDtTdLHou8qJY0Z7WnorhPfsjp7HZxjAvk2H1Zi zVtm2fczRe3OFDaSjfNQSKiaajo7r/9Bx+3feISPPbAkpS1cX0UAmGY99Kh68hSPKYsM GFe1KGMKFdUd/Ig6tuELgVX0qOLjJkzakgoo6gzkzVvhNtCxJXQ8ZRBK0pBETb6jSJ0J u1FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=txT4jK1J; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 94si1710041otw.297.2020.02.13.14.09.21; Thu, 13 Feb 2020 14:09:35 -0800 (PST) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=txT4jK1J; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727794AbgBMWIS (ORCPT + 99 others); Thu, 13 Feb 2020 17:08:18 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:37329 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbgBMWIS (ORCPT ); Thu, 13 Feb 2020 17:08:18 -0500 Received: by mail-io1-f66.google.com with SMTP id k24so8329780ioc.4 for ; Thu, 13 Feb 2020 14:08:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PvTmvGfvJmOv7sMbAjwocI81PqYWLyNw6wRoKoHV6qg=; b=txT4jK1J0pBtT9kg3vVsCO4+fPlEEgl0mw/PQqXHnDzVPHf1XFGMXXGWSOkx36QT+M VpDhUw85bVIZAXgTqTvaEkxT48Z8Ur8OA2/wpwNXs6gXisBx2OlaYnAJBEFD9B//46qP t/oHlKKxqFBmo9MBOeYDZDgAE3p14qbAeZ+dlEVwugWXswqi914wl6jAMHuAR0eTPAi6 y2eJbwjJolAzw2xqxyimpS0RmJ3n9f6jKJ+20Q4ytQasqPlrw6fasVslAvVjRc/uCcvM FauQ1mtCSUfKUPi83ludoUvB9+x1qfE9UyUxicbj//+lSrh9DMaC/nCAo/wZ26XukEI5 5yRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PvTmvGfvJmOv7sMbAjwocI81PqYWLyNw6wRoKoHV6qg=; b=INRkkd93lNHwc3JUCSlAioASldQM/d/2S4eefSY4IzkYpqcl62N2y9FYwKmLq4LxHe WYTOeSpQ/4NDUTvKXolCa2gJrGeyh2GhmSYHXmPa4uDLtaITZG8kcfxZa8XrsVmWYGaa EwT3bf80wEOOHmA4D8jnwUDb0buiPEYghvRr2QPVwLvXZt0IgvI/agAyAInENgjNxb89 sQQ4DAmGZVW+ZLdGgGBxYEziGQelmfJT7PGwojcRnrfqx4EoNkF4nlYCE9nm1ltBhuUU 9S0syGTDJE28oygPFoxElFADlKdEPNkbieq3aIzbZ7kA4RVO8kuQYnBPTxf+iLhiH/Dw TWAQ== X-Gm-Message-State: APjAAAVYWWvvec5enoCcf10gjZ6wF6n5nhdZYweK/6xOPa1+s94XM/hc 78KVf04EJJrv/k8wfMLoEFwi61VZTQFVGD9SzLhcr6qaeREl6g== X-Received: by 2002:a02:7fd0:: with SMTP id r199mr94717jac.126.1581631696132; Thu, 13 Feb 2020 14:08:16 -0800 (PST) MIME-Version: 1.0 References: <20200213082643.GB9144@ming.t460p> In-Reply-To: From: Salman Qazi Date: Thu, 13 Feb 2020 14:08:04 -0800 Message-ID: Subject: Re: BLKSECDISCARD ioctl and hung tasks To: Bart Van Assche Cc: Ming Lei , Jens Axboe , Christoph Hellwig , Linux Kernel Mailing List , linux-block@vger.kernel.org, Gwendal Grignou , Jesse Barnes Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 13, 2020 at 11:21 AM Salman Qazi wrote: > > On Thu, Feb 13, 2020 at 9:48 AM Bart Van Assche wrote: > > > > On 2/13/20 12:26 AM, Ming Lei wrote: > > > The approach used in blk_execute_rq() can be borrowed for workaround the > > > issue, such as: > > > > > > diff --git a/block/bio.c b/block/bio.c > > > index 94d697217887..c9ce19a86de7 100644 > > > --- a/block/bio.c > > > +++ b/block/bio.c > > > @@ -17,6 +17,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #include > > > #include "blk.h" > > > @@ -1019,12 +1020,19 @@ static void submit_bio_wait_endio(struct bio *bio) > > > int submit_bio_wait(struct bio *bio) > > > { > > > DECLARE_COMPLETION_ONSTACK_MAP(done, bio->bi_disk->lockdep_map); > > > + unsigned long hang_check; > > > > > > bio->bi_private = &done; > > > bio->bi_end_io = submit_bio_wait_endio; > > > bio->bi_opf |= REQ_SYNC; > > > submit_bio(bio); > > > - wait_for_completion_io(&done); > > > + > > > + /* Prevent hang_check timer from firing at us during very long I/O */ > > > + hang_check = sysctl_hung_task_timeout_secs; > > > + if (hang_check) > > > + while (!wait_for_completion_io_timeout(&done, hang_check * (HZ/2))); > > > + else > > > + wait_for_completion_io(&done); > > > > > > return blk_status_to_errno(bio->bi_status); > > > } > > > > Instead of suppressing the hung task complaints, has it been considered > > to use the bio splitting mechanism to make discard bios smaller? Block > > drivers may set a limit by calling blk_queue_max_discard_segments(). > > From block/blk-settings.c: > > > > /** > > * blk_queue_max_discard_segments - set max segments for discard > > * requests > > * @q: the request queue for the device > > * @max_segments: max number of segments > > * > > * Description: > > * Enables a low level driver to set an upper limit on the number of > > * segments in a discard request. > > **/ > > void blk_queue_max_discard_segments(struct request_queue *q, > > unsigned short max_segments) > > { > > q->limits.max_discard_segments = max_segments; > > } > > EXPORT_SYMBOL_GPL(blk_queue_max_discard_segments); > > > > AFAICT, This is not actually sufficient, because the issuer of the bio > is waiting for the entire bio, regardless of how it is split later. > But, also there isn't a good mapping between the size of the secure > discard and how long it will take. If given the geometry of a flash > device, it is not hard to construct a scenario where a relatively > small secure discard (few thousand sectors) will take a very long time > (multiple seconds). > > Having said that, I don't like neutering the hung task timer either. In fact, it's worse than that. Today, I was able to construct a case of a 4K discard on a particular device that took 100 seconds. I did this by arranging to write a single copy of page 0 for every erase unit of the device, and wrote random LBAs to the rest of the erase unit. I suspect the slow speed comes from the need to copy almost the entire device to erase all the stale copies of page 0. #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include char page[8192]; int main(int argc, char **argv) { unsigned long start; int fd; int i; char *page_aligned = (char *)(((unsigned long)page + 4095) & ~4095UL); unsigned long range[2]; fd = open(argv[1], O_RDWR | O_DIRECT); assert(fd >= 0); range[0] = 0; assert(ioctl(fd, BLKGETSIZE64, &range[1]) >= 0); for (i = 0; i < range[1]; i += 4096) { /* paranoia: incase there is any deduping */ page_aligned[0] = i; /* * Almost always write randomly */ if (i % (4*1024*1024) != 0) assert(pwrite(fd, page_aligned, 4096, (lrand48() % range[1]) & ~4095UL) == 4096); else /* except, once per erase block, write page 0 */ assert(pwrite(fd, page_aligned, 4096, 0) == 4096); } start = time(NULL); /* discard exactly one page */ range[1] = 4096; printf("Starting discard %lu!\n", start); assert(ioctl(fd, BLKSECDISCARD, &range) >= 0); printf("Finished discard. Took %lu!\n", time(NULL) - start); close(fd); } > > > Thanks, > > > > Bart.