From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753645AbaAQTZn (ORCPT ); Fri, 17 Jan 2014 14:25:43 -0500 Received: from relay.parallels.com ([195.214.232.42]:54337 "EHLO relay.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753629AbaAQTZj (ORCPT ); Fri, 17 Jan 2014 14:25:39 -0500 From: Vladimir Davydov To: CC: , , , Mel Gorman , Michal Hocko , Johannes Weiner , Rik van Riel , Dave Chinner , Glauber Costa Subject: [PATCH 3/3] mm: vmscan: shrink_slab: do not skip caches with < batch_size objects Date: Fri, 17 Jan 2014 23:25:31 +0400 Message-ID: <461628a5763b31bb36cc3dd7f6b89b06a907234f.1389982079.git.vdavydov@parallels.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <4e2efebe688e06574f6495c634ac45d799e1518d.1389982079.git.vdavydov@parallels.com> References: <4e2efebe688e06574f6495c634ac45d799e1518d.1389982079.git.vdavydov@parallels.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.24.24.241] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In its current implementation, shrink_slab() won't scan caches that have less than batch_size objects. If there are only a few shrinkers available, such a behavior won't cause any problems, because the batch_size is usually small, but if we have a lot of slab shrinkers, which is perfectly possible since FS shrinkers are now per-superblock, we can end up with hundreds of megabytes of practically unreclaimable kmem objects. For instance, mounting a thousand of ext2 FS images with a hundred of files in each and iterating over all the files using du(1) will result in about 200 Mb of FS caches that cannot be dropped even with the aid of the vm.drop_caches sysctl! Fix this. Signed-off-by: Vladimir Davydov Cc: Andrew Morton Cc: Mel Gorman Cc: Michal Hocko Cc: Johannes Weiner Cc: Rik van Riel Cc: Dave Chinner Cc: Glauber Costa --- mm/vmscan.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index f6d716d..2e710d4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -275,7 +275,7 @@ shrink_slab_node(struct shrink_control *shrinkctl, struct shrinker *shrinker, * a large delta change is calculated directly. */ if (delta < freeable / 4) - total_scan = min(total_scan, freeable / 2); + total_scan = min(total_scan, max(freeable / 2, batch_size)); /* * Avoid risking looping forever due to too large nr value: @@ -289,21 +289,34 @@ shrink_slab_node(struct shrink_control *shrinkctl, struct shrinker *shrinker, nr_pages_scanned, lru_pages, freeable, delta, total_scan); - while (total_scan >= batch_size) { + /* + * To avoid CPU cache thrashing, we should not scan less than + * batch_size objects in one pass, but if the cache has less + * than batch_size objects in total, and we really want to + * shrink them all, go ahead and scan what we have, otherwise + * last batch_size objects will never get reclaimed. + */ + if (total_scan < batch_size && + !(freeable < batch_size && total_scan >= freeable)) + goto out; + + do { unsigned long ret; + unsigned long nr_to_scan = min(total_scan, batch_size); - shrinkctl->nr_to_scan = batch_size; + shrinkctl->nr_to_scan = nr_to_scan; ret = shrinker->scan_objects(shrinker, shrinkctl); if (ret == SHRINK_STOP) break; freed += ret; - count_vm_events(SLABS_SCANNED, batch_size); - total_scan -= batch_size; + count_vm_events(SLABS_SCANNED, nr_to_scan); + total_scan -= nr_to_scan; cond_resched(); - } + } while (total_scan >= batch_size); +out: /* * move the unused scan count back into the shrinker in a * manner that handles concurrent updates. If we exhausted the -- 1.7.10.4