Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1400885pxj; Fri, 21 May 2021 13:20:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyig+tx+LFVR6/6xNhJawveAIRICKEhhExmssw8IHKTAciQf13T5GrrG3XHAfeDjbOf8eGS X-Received: by 2002:a6b:6c0b:: with SMTP id a11mr628193ioh.37.1621628427983; Fri, 21 May 2021 13:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621628427; cv=none; d=google.com; s=arc-20160816; b=S+lh9I993EaOCYbywFzyOBOirbOyQL6+eNFDTYT9Yxycq1pqeSdfQurgmJFKspV1yI rIJLRYEVsAFxGVSrX+3cil3G8r9mZoRYdo7HP1OfJoJV+Rd9tyH1YcnH1dNlMKG49n+r 67l49HKbNkb+dbtBhLQ5gar7cTeEgAa3N2qUi/hAJ4BLN+qvOnNv5rXX5DdPlP+awfXS knN5a92a0MRuqmHgJ+JfYUE7Hzo0vnI5Pin8+Tnl+lgoWydHeE0km8D40bSEukg6Wf+z bBMBhIeDFokLpK2TvWJO1D6J50VuOpDJf97qMTjgC7Em3i9FWeB6zB3qkXyGpZRGa71Z SK9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:mail-followup-to:reply-to:message-id :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=3N2PUHGxNFtqL17T5oc1TOpT1nz6cla7cbqvtLWhevg=; b=g5Os7DKUpi+N2o36IZR94sfOfVUkg6YEWTtgBE6IwQw0k9Q60KW2kU5bUm//aAnExK I9hIRMDTY4WFIL6NIZdKO4TXFSb5S4YRwPx/R8Xr1umcKfIOE/ztNUzEdjW4mZpUNkKt rSdYq5OyIj8IkFKQvegj0+xCjBXhWGpGSnsST6tJXVEzy+AZoZvoGrxFXcdQfTB9gLfq Vq7H5zHLBEJcKhHLxa/++ZCbtE8E4N63UX81rG+JZYoeYjlSUSvM06gj0KWpZVbZ8TBB O88WxmWzl18KYvQ8QUGksZJnZ7uHThRAKr1ZEEOi2bpxTVVAnweG7cDWYRnqvbWYgNg2 tgVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=KFZastnG; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t3si5875933jaj.67.2021.05.21.13.20.15; Fri, 21 May 2021 13:20:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=KFZastnG; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232336AbhEUPUT (ORCPT + 99 others); Fri, 21 May 2021 11:20:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:54226 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234054AbhEUPUM (ORCPT ); Fri, 21 May 2021 11:20:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1621610327; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3N2PUHGxNFtqL17T5oc1TOpT1nz6cla7cbqvtLWhevg=; b=KFZastnGdCEXZrlOqAnzT4syC45AmB/ZYZl4OqTt5ERMjwaZevP2mpU0QImWSliNHxuvvk pn+RD6237Hf5mdW8SO0qOf4WJ2J4u0BizN3S/iQVk7geGI+L3JT8xgQAN8JoPQtfV8onY2 8f6ortDqmbwpka1LqX6484giz9i/Id8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1621610327; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3N2PUHGxNFtqL17T5oc1TOpT1nz6cla7cbqvtLWhevg=; b=KvTIHw2DJ6jwIyfQzOTPqNN+P4r2uvc5CJFvSJsw7y/kkfqJx/q2GpLPilHFLJ1fcu9O97 lB2vGzQqMJzHrTBA== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C586EACF5; Fri, 21 May 2021 15:18:47 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 5C013DA72C; Fri, 21 May 2021 17:16:13 +0200 (CEST) Date: Fri, 21 May 2021 17:16:13 +0200 From: David Sterba To: Arnd Bergmann Cc: Geert Uytterhoeven , David Sterba , linux-btrfs , Linux Kernel Mailing List Subject: Re: [PATCH] btrfs: scrub: per-device bandwidth control Message-ID: <20210521151613.GN7604@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Arnd Bergmann , Geert Uytterhoeven , David Sterba , linux-btrfs , Linux Kernel Mailing List References: <20210518144935.15835-1-dsterba@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 20, 2021 at 03:14:03PM +0200, Arnd Bergmann wrote: > On Thu, May 20, 2021 at 9:43 AM Geert Uytterhoeven wrote: > > On Tue, 18 May 2021, David Sterba wrote: > > > + /* 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(). It's in miliseconds and the division above is int/int, the problematic one is below. > > > > + 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? > > > > + /* We're over the limit, sleep until the rest of the slice */ > > > + delta = ktime_ms_delta(sctx->throttle_deadline, now); > > > + } else { > > > + /* New request after deadline, start new epoch */ > > > + delta = 0; > > > + } > > > + > > > + if (delta) > > > + schedule_timeout_interruptible(delta * HZ / 1000); > > > > ERROR: modpost: "__divdi3" [fs/btrfs/btrfs.ko] undefined! > > > > I'm a bit surprised gcc doesn't emit code for the division by the > > constant 1000, but emits a call to __divdi3(). So this has to become > > div_u64(), too. > > There is schedule_hrtimeout(), which takes a ktime_t directly > but has slightly different behavior. There is also an msecs_to_jiffies > helper that should produce a fast division. I'll use msecs_to_jiffies, thanks. If 'hr' in schedule_hrtimeout stands for high resolution, it's not necessary here.