From owner-freebsd-hackers@freebsd.org Wed Aug 22 00:19:07 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 41CCA10844AF for ; Wed, 22 Aug 2018 00:19:07 +0000 (UTC) (envelope-from rwmaillists@googlemail.com) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B679176373 for ; Wed, 22 Aug 2018 00:19:06 +0000 (UTC) (envelope-from rwmaillists@googlemail.com) Received: by mail-wr1-x42b.google.com with SMTP id u12-v6so132236wrr.4 for ; Tue, 21 Aug 2018 17:19:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jGzFuB72oOCMHdEDG357l+BI08Y19KIsGiXsjOMMhxQ=; b=I9rQ7O3g/mDosFeCdylMoyd4doaYHHCRsq+c1za85KOGMfAQJk54OCvb75ZYbMQMb/ 1xSCD76UlNIrJYTmTS0l82Z0YAbf6q3OwOelPI1kKnKZ14sPmFH57Qo1pXz671vtNcnl OjxPPzCFYJky2HIyPzh5ypGFRj+XpPP7dzMYmMoB0/3+5Fyogmp1RwQY5ExcYMmQaYkd ix69gGmQM1vjXV/sVdUpP0k0oBacFkglYFhrtfB9yu2x6WUmYrtZkDDiWCeQD3s88KZn j5F/R579Pb/fhjqixp8w7XCkY8u6ql0QWw/abpgjGg3iJyP10VaWpZTZcOKf3OsDijfO q+/w== X-Gm-Message-State: AOUpUlF9SAB2DxJjDNGNqSB1UgrDb6OdT5/tHBsnMUdwgHHABYx5MyNV Ok+qIYYr6UdumYr0u+CGXdwT5cki6j0= X-Google-Smtp-Source: AA+uWPz+0z2OdqPE+Rfe8h6BC6iT6ydgQA+esU9FdSDGlDSXHoH6g3CvCdvY+IyqyjPgin/0WgTo0w== X-Received: by 2002:adf:b642:: with SMTP id i2-v6mr32211873wre.54.1534897145565; Tue, 21 Aug 2018 17:19:05 -0700 (PDT) Received: from gumby.homeunix.com ([90.210.182.138]) by smtp.gmail.com with ESMTPSA id l18-v6sm147837wru.75.2018.08.21.17.19.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Aug 2018 17:19:04 -0700 (PDT) Date: Wed, 22 Aug 2018 01:19:01 +0100 From: RW To: freebsd-hackers@freebsd.org Subject: Re: rand_harvestq high cpu usage when /dev/urandom is used Message-ID: <20180822011901.6eb678cb@gumby.homeunix.com> In-Reply-To: <20180820184337.6e07e951@gumby.homeunix.com> References: <20180820184337.6e07e951@gumby.homeunix.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; amd64-portbld-freebsd11.1) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Aug 2018 00:19:07 -0000 On Mon, 20 Aug 2018 18:43:37 +0100 RW wrote: > On Mon, 20 Aug 2018 13:27:33 +0200 > Ali Abdallah wrote: > > > Hello, > > > > I was just sorting randomly some jpg image files using: > > > > ls *.jpg | sort -R --random-source=/dev/urandom > > urandom is a sim-link to random, so --random-source=/dev/urandom > does nothing useful > > > The above command never exited. Later I noticed that > > one of my CPU is always running 100%. top -S reveals that it is > > rand_harvestq kernel service. > > > > Is this is a bug? This occurs on 12-ALPHA1 and 11.2 > > It's a bit excessive I think I see what is going on. If you have a hardware entropy source then when you read N bytes out of /dev/random, random_sources_feed() tries to put at least that amount into each of the entropy pools (32 for fortuna). So if you are reading at 100MB/s, you are trying to feed 3.2GB/s into the pools. Overwriting a slow drive from /dev/random seems to be enough to waste a CPU core my PC. Fortuna is only allowed to resend after 100ms, and anything more than 1kB/reseed (pools*keysize) is a waste of CPU cycles. IMO random_sources_feed() should limit itself to RANDOM_KEYSIZE bytes per call for each pool/source combination - even that's overkill.