Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4077697ybx; Mon, 4 Nov 2019 07:30:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyve02CCZvh11yWC9gMYmuLrOQ1Z4AuRAWswXaCTK4NCWZicyP3X3MPOtpwSlUaCYVvoS2g X-Received: by 2002:a17:906:6011:: with SMTP id o17mr23559737ejj.172.1572881448454; Mon, 04 Nov 2019 07:30:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572881448; cv=none; d=google.com; s=arc-20160816; b=z23OgNlObuQxuom8UHobiOBsMvdBLnsrSad96niGFA6zZSzu1DggWoRKsP4qSVYKh6 Oafhw0CS3yXzJO48eMui1JNjJBcfw8QeWpmEBeF3Z/3WeOKPLoSm3l2vIRXqKtsqTnCk /CoczatPazTrR+UX+1qIRm7R3+js2gZr+t91iiqjXRHsUkX68xOLfD5VX+jLDjffuzW3 +lFggIKeCc0WK5nBinfxtrehaWu4I/2xdpXy7Wmuc4Dynt+K8jgfinHRlm8p+eriQtsg eUAimnL0Gxa/VwqRkUmTiuwTuXS4Hh0mWcImgT4S+TBGS2vAqhmd8YeDbcc3owtU/W9W MWdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xnIpPAsEfh3l+jictAmtLN7RDDQx739S6dh9HTHu7Ag=; b=bxebOVNgpnI63Vo+uGb1DW6rieyFwgm6FtK4cNfqLIO2K1KzWqClmuLVJyEZs/yE+w WiaZ5gNisxQJXJY5W35hplsT+p278uwQccku8DLlVMOfRGf8yLMcwfNOomTbWfQ8JuBP lW6HMPiivXD2nt8z/dujL+4kzrlhxS1gxgEqXD1jfwUapap59DQ61GGRvrC1JzhaYog+ tAmya4b1TWHZ9NpnWg7bBmIxt2KigDCqWyTWcWKZT8rOyEcN8fWSIcjeML9LwEyD8Wv4 Ip1A+kJaox9ZrK1272oyd6Sh66oMVYV9FsElFZsKaj5B8VlxiiOEYUJVO/tIfWNZWgf+ qZxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UeLQQNw5; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m16si12474726ejd.306.2019.11.04.07.30.24; Mon, 04 Nov 2019 07:30:48 -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=@redhat.com header.s=mimecast20190719 header.b=UeLQQNw5; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728955AbfKDP3s (ORCPT + 99 others); Mon, 4 Nov 2019 10:29:48 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:37403 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728474AbfKDP3r (ORCPT ); Mon, 4 Nov 2019 10:29:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572881386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xnIpPAsEfh3l+jictAmtLN7RDDQx739S6dh9HTHu7Ag=; b=UeLQQNw5R/9L+OtIfUqDk3KFxOhKjhJu17dePzEvSVXLbk63Nlt/EiFrK0VK2EDrKPJq1s QMrmGMZfCRMsGVOOKxx6kaC7BIUDNEWzQaqWm8TbNF6llR3S5PG7GZ1CeKspDHYU9AfuZD vqA2tIrVqG3ktIz01TMjTXzXN/ArCKA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-PWExnVQ_PW6blTwMdJIEhg-1; Mon, 04 Nov 2019 10:29:42 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69C77800C73; Mon, 4 Nov 2019 15:29:41 +0000 (UTC) Received: from bfoster (dhcp-41-2.bos.redhat.com [10.18.41.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7A925D6C5; Mon, 4 Nov 2019 15:29:40 +0000 (UTC) Date: Mon, 4 Nov 2019 10:29:39 -0500 From: Brian Foster To: Dave Chinner Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 11/28] mm: factor shrinker work calculations Message-ID: <20191104152939.GB10665@bfoster> References: <20191031234618.15403-1-david@fromorbit.com> <20191031234618.15403-12-david@fromorbit.com> MIME-Version: 1.0 In-Reply-To: <20191031234618.15403-12-david@fromorbit.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: PWExnVQ_PW6blTwMdJIEhg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 01, 2019 at 10:46:01AM +1100, Dave Chinner wrote: > From: Dave Chinner >=20 > Start to clean up the shrinker code by factoring out the calculation > that determines how much work to do. This separates the calculation > from clamping and other adjustments that are done before the > shrinker work is run. Document the scan batch size calculation > better while we are there. >=20 > Also convert the calculation for the amount of work to be done to > use 64 bit logic so we don't have to keep jumping through hoops to > keep calculations within 32 bits on 32 bit systems. >=20 > Signed-off-by: Dave Chinner > --- I assume the kbuild warning thing will be fixed up... > mm/vmscan.c | 97 ++++++++++++++++++++++++++++++++++++++--------------- > 1 file changed, 70 insertions(+), 27 deletions(-) >=20 > diff --git a/mm/vmscan.c b/mm/vmscan.c > index a215d71d9d4b..2d39ec37c04d 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -459,13 +459,68 @@ EXPORT_SYMBOL(unregister_shrinker); > =20 > #define SHRINK_BATCH 128 > =20 > +/* > + * Calculate the number of new objects to scan this time around. Return > + * the work to be done. If there are freeable objects, return that numbe= r in > + * @freeable_objects. > + */ > +static int64_t shrink_scan_count(struct shrink_control *shrinkctl, > +=09=09=09 struct shrinker *shrinker, int priority, > +=09=09=09 int64_t *freeable_objects) > +{ > +=09int64_t delta; > +=09int64_t freeable; > + > +=09freeable =3D shrinker->count_objects(shrinker, shrinkctl); > +=09if (freeable =3D=3D 0 || freeable =3D=3D SHRINK_EMPTY) > +=09=09return freeable; > + > +=09if (shrinker->seeks) { > +=09=09/* > +=09=09 * shrinker->seeks is a measure of how much IO is required to > +=09=09 * reinstantiate the object in memory. The default value is 2 > +=09=09 * which is typical for a cold inode requiring a directory read > +=09=09 * and an inode read to re-instantiate. > +=09=09 * > +=09=09 * The scan batch size is defined by the shrinker priority, but > +=09=09 * to be able to bias the reclaim we increase the default batch > +=09=09 * size by 4. Hence we end up with a scan batch multipler that > +=09=09 * scales like so: > +=09=09 * > +=09=09 * ->seeks=09scan batch multiplier > +=09=09 * 1=09=09 4.00x > +=09=09 * 2 2.00x > +=09=09 * 3 1.33x > +=09=09 * 4 1.00x > +=09=09 * 8 0.50x > +=09=09 * > +=09=09 * IOWs, the more seeks it takes to pull the item into cache, > +=09=09 * the smaller the reclaim scan batch. Hence we put more reclaim > +=09=09 * pressure on caches that are fast to repopulate and to keep a > +=09=09 * rough balance between caches that have different costs. > +=09=09 */ > +=09=09delta =3D freeable >> (priority - 2); Does anything prevent priority < 2 here? > +=09=09do_div(delta, shrinker->seeks); > +=09} else { > +=09=09/* > +=09=09 * These objects don't require any IO to create. Trim them > +=09=09 * aggressively under memory pressure to keep them from causing > +=09=09 * refetches in the IO caches. > +=09=09 */ > +=09=09delta =3D freeable / 2; > +=09} > + > +=09*freeable_objects =3D freeable; > +=09return delta > 0 ? delta : 0; > +} > + > static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, > =09=09=09=09 struct shrinker *shrinker, int priority) > { > =09unsigned long freed =3D 0; > -=09unsigned long long delta; > =09long total_scan; > -=09long freeable; > +=09int64_t freeable_objects =3D 0; > +=09int64_t scan_count; > =09long nr; > =09long new_nr; > =09int nid =3D shrinkctl->nid; ... > @@ -487,25 +543,11 @@ static unsigned long do_shrink_slab(struct shrink_c= ontrol *shrinkctl, > =09 */ > =09nr =3D atomic_long_xchg(&shrinker->nr_deferred[nid], 0); > =20 > -=09total_scan =3D nr; > -=09if (shrinker->seeks) { > -=09=09delta =3D freeable >> priority; > -=09=09delta *=3D 4; > -=09=09do_div(delta, shrinker->seeks); > -=09} else { > -=09=09/* > -=09=09 * These objects don't require any IO to create. Trim > -=09=09 * them aggressively under memory pressure to keep > -=09=09 * them from causing refetches in the IO caches. > -=09=09 */ > -=09=09delta =3D freeable / 2; > -=09} > - > -=09total_scan +=3D delta; > +=09total_scan =3D nr + scan_count; > =09if (total_scan < 0) { > =09=09pr_err("shrink_slab: %pS negative objects to delete nr=3D%ld\n", > =09=09 shrinker->scan_objects, total_scan); > -=09=09total_scan =3D freeable; > +=09=09total_scan =3D scan_count; Same question as before: why the change in assignment? freeable was the ->count_objects() return value, which is now stored in freeable_objects. FWIW, the change seems to make sense in that it just factors out the deferred count, but it's not clear if it's intentional... Brian > =09=09next_deferred =3D nr; > =09} else > =09=09next_deferred =3D total_scan; > @@ -522,19 +564,20 @@ static unsigned long do_shrink_slab(struct shrink_c= ontrol *shrinkctl, > =09 * Hence only allow the shrinker to scan the entire cache when > =09 * a large delta change is calculated directly. > =09 */ > -=09if (delta < freeable / 4) > -=09=09total_scan =3D min(total_scan, freeable / 2); > +=09if (scan_count < freeable_objects / 4) > +=09=09total_scan =3D min_t(long, total_scan, freeable_objects / 2); > =20 > =09/* > =09 * Avoid risking looping forever due to too large nr value: > =09 * never try to free more than twice the estimate number of > =09 * freeable entries. > =09 */ > -=09if (total_scan > freeable * 2) > -=09=09total_scan =3D freeable * 2; > +=09if (total_scan > freeable_objects * 2) > +=09=09total_scan =3D freeable_objects * 2; > =20 > =09trace_mm_shrink_slab_start(shrinker, shrinkctl, nr, > -=09=09=09=09 freeable, delta, total_scan, priority); > +=09=09=09=09 freeable_objects, scan_count, > +=09=09=09=09 total_scan, priority); > =20 > =09/* > =09 * If the shrinker can't run (e.g. due to gfp_mask constraints), then > @@ -559,7 +602,7 @@ static unsigned long do_shrink_slab(struct shrink_con= trol *shrinkctl, > =09 * possible. > =09 */ > =09while (total_scan >=3D batch_size || > -=09 total_scan >=3D freeable) { > +=09 total_scan >=3D freeable_objects) { > =09=09unsigned long ret; > =09=09unsigned long nr_to_scan =3D min(batch_size, total_scan); > =20 > --=20 > 2.24.0.rc0 >=20