From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A1BCC433ED for ; Thu, 20 May 2021 13:26:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5343A60C3E for ; Thu, 20 May 2021 13:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237947AbhETN2E (ORCPT ); Thu, 20 May 2021 09:28:04 -0400 Received: from mail-vk1-f173.google.com ([209.85.221.173]:41816 "EHLO mail-vk1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234137AbhETN2D (ORCPT ); Thu, 20 May 2021 09:28:03 -0400 Received: by mail-vk1-f173.google.com with SMTP id n71so2664221vkf.8; Thu, 20 May 2021 06:26:41 -0700 (PDT) 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=kVftqxA9v+JvVyYELD56NQzbqBmkwWKJa852Ut1Tatg=; b=cizpZg5tH2uwNSjCBET5vFzhEZJDZUb7/lrohZLAnRbtoZT98NPnNPrsZvZdeTYT3/ 4l6+dvVlys2zYMVQlVYIznMgj8j1sAcgQjUliSYKnxhIRRDXQ9gQcCuEjlh+YL6BLLIu o4ln6nn0FaGcHG1eyzOcuGtw3qditlNs69HnaEWopwMsRZY839vW2eQNo7TKenT1gQHN p2m/DZy59YW65u0zCq7pJD/vXNbSNZjMx1bQ3ZxVHnk0BNS6397lRKNwAzSGF++LMbh4 89fhuefNjW08r173lkjBPE39grEhr5PSW2gz+oFVYf0d5bCs7gm8tRooJrmmn/SYmsmO 0GNQ== X-Gm-Message-State: AOAM531NJz1ZbZpGwUZh9I1GEEnZa4HDHl+76JRmaq0I/xDfE0cLTgXQ M7XJEFrUPuP9GgVwQlsgBHwVXsbLVRZd5FgeKqg7fsFn X-Google-Smtp-Source: ABdhPJyl6lYJFVdz57nxN6fV6GjRxgWNrWyvP7/aAFid7dKsdHsMIlU4xz5jVMI7LURDD/Z0d7DIpJvvUvqOcKvyAZE= X-Received: by 2002:a1f:a388:: with SMTP id m130mr4145273vke.1.1621517200867; Thu, 20 May 2021 06:26:40 -0700 (PDT) MIME-Version: 1.0 References: <20210518144935.15835-1-dsterba@suse.com> In-Reply-To: From: Geert Uytterhoeven Date: Thu, 20 May 2021 15:26:29 +0200 Message-ID: Subject: Re: [PATCH] btrfs: scrub: per-device bandwidth control To: Arnd Bergmann Cc: David Sterba , linux-btrfs , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Hi Arnd, On Thu, May 20, 2021 at 3:15 PM Arnd Bergmann wrote: > On Thu, May 20, 2021 at 9:43 AM Geert Uytterhoeven wrote: > > On Tue, 18 May 2021, David Sterba wrote: > > > --- a/fs/btrfs/scrub.c > > > +++ b/fs/btrfs/scrub.c > > > @@ -1988,6 +1993,60 @@ static void scrub_page_put(struct scrub_page *spage) > > > } > > > } > > > > > > +/* > > > + * Throttling of IO submission, bandwidth-limit based, the timeslice is 1 > > > + * second. Limit can be set via /sys/fs/UUID/devinfo/devid/scrub_speed_max. > > > + */ > > > +static void scrub_throttle(struct scrub_ctx *sctx) > > > +{ > > > + const int time_slice = 1000; > > > + struct scrub_bio *sbio; > > > + struct btrfs_device *device; > > > + s64 delta; > > > + ktime_t now; > > > + u32 div; > > > + u64 bwlimit; > > > + > > > + sbio = sctx->bios[sctx->curr]; > > > + device = sbio->dev; > > > + bwlimit = READ_ONCE(device->scrub_speed_max); > > > + if (bwlimit == 0) > > > + return; > > > + > > > + /* > > > + * Slice is divided into intervals when the IO is submitted, adjust by > > > + * bwlimit and maximum of 64 intervals. > > > + */ > > > + div = max_t(u32, 1, (u32)(bwlimit / (16 * 1024 * 1024))); > > > + div = min_t(u32, 64, div); > > > + > > > + /* Start new epoch, set deadline */ > > > + now = ktime_get(); > > > + if (sctx->throttle_deadline == 0) { > > > + sctx->throttle_deadline = ktime_add_ms(now, time_slice / div); > > > > ERROR: modpost: "__udivdi3" [fs/btrfs/btrfs.ko] undefined! > > > > div_u64(bwlimit, div) > > If 'time_slice' is in nanoseconds, the best interface to use > is ktime_divns(). Actually this one is not a problem... > > > > + sctx->throttle_sent = 0; > > > + } > > > + > > > + /* Still in the time to send? */ > > > + if (ktime_before(now, sctx->throttle_deadline)) { > > > + /* If current bio is within the limit, send it */ > > > + sctx->throttle_sent += sbio->bio->bi_iter.bi_size; > > > + if (sctx->throttle_sent <= bwlimit / div) > > > + return; > > Doesn't this also need to be changed? ... but this is. Sorry. I added the annotation to the wrong line, after devising which code caused the issue from looking at the generated assembly ;-) Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds