From patchwork Tue Aug 15 22:30:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 9902581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40E1D60244 for ; Tue, 15 Aug 2017 22:30:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D2EC28948 for ; Tue, 15 Aug 2017 22:30:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BD902894D; Tue, 15 Aug 2017 22:30:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ABCF728948 for ; Tue, 15 Aug 2017 22:30:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 781D589DA7; Tue, 15 Aug 2017 22:30:14 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id A5AE789DA7 for ; Tue, 15 Aug 2017 22:30:13 +0000 (UTC) Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8FC4F8D7; Tue, 15 Aug 2017 22:30:11 +0000 (UTC) Date: Tue, 15 Aug 2017 15:30:10 -0700 From: Andrew Morton To: Chris Wilson Message-Id: <20170815153010.e3cfc177af0b2c0dc421b84c@linux-foundation.org> In-Reply-To: <20170812113437.7397-1-chris@chris-wilson.co.uk> References: <20170812113437.7397-1-chris@chris-wilson.co.uk> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Cc: Michal Hocko , Minchan Kim , intel-gfx@lists.freedesktop.org, Hillf Danton , linux-mm@kvack.org, Shaohua Li , Johannes Weiner , Mel Gorman , Vlastimil Babka Subject: Re: [Intel-gfx] [PATCH] mm: Reward slab shrinkers that reclaim more than they were asked X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP On Sat, 12 Aug 2017 12:34:37 +0100 Chris Wilson wrote: > Some shrinkers may only be able to free a bunch of objects at a time, and > so free more than the requested nr_to_scan in one pass. Account for the > extra freed objects against the total number of objects we intend to > free, otherwise we may end up penalising the slab far more than intended. > > ... > > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -398,6 +398,7 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, > break; > freed += ret; > > + nr_to_scan = max(nr_to_scan, ret); > count_vm_events(SLABS_SCANNED, nr_to_scan); > total_scan -= nr_to_scan; > scanned += nr_to_scan; Well... kinda. But what happens if the shrinker scanned more objects than requested but failed to free many of them? Of if the shrinker scanned less than requested? We really want to return nr_scanned from the shrinker invocation. Could we add a field to shrink_control for this? --- a/mm/vmscan.c~a +++ a/mm/vmscan.c @@ -393,14 +393,15 @@ static unsigned long do_shrink_slab(stru unsigned long nr_to_scan = min(batch_size, total_scan); shrinkctl->nr_to_scan = nr_to_scan; + shrinkctl->nr_scanned = nr_to_scan; ret = shrinker->scan_objects(shrinker, shrinkctl); if (ret == SHRINK_STOP) break; freed += ret; - count_vm_events(SLABS_SCANNED, nr_to_scan); - total_scan -= nr_to_scan; - scanned += nr_to_scan; + count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned); + total_scan -= shrinkctl->nr_scanned; + scanned += shrinkctl->nr_scanned; cond_resched(); }