Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1321374imm; Fri, 17 Aug 2018 16:21:05 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwQGANzPjev5jDUqE/lPhQB+IgJuG+mOfAieyvB0rUBJv/v65pBzaAfsGk34+BO4r1lszJN X-Received: by 2002:a17:902:654b:: with SMTP id d11-v6mr35285225pln.8.1534548065279; Fri, 17 Aug 2018 16:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534548065; cv=none; d=google.com; s=arc-20160816; b=G1pH+KiFwGAZEzWhekUwNnnqKcX8BTjmfcKubX6MriVABN+8Q9CepBpDxDlPrpIDSk mVcv4DwWVu7qPeWxRoyRF/cJpa3HeE7rkVYWqNw5hSWakadEAsEY1+oEavbak/XgaNaM NKdlRQWHlGUG6cYfbJ8PT6A8Xi11o+LGwFrpD0NXdtmNmVt/kcPQDlxL8P20QwNmZ3SI L++3gBYM814yWdhixtpJlwbzA+pkRJb1Od8OJo/r7xIj6Zzw5ajMIziDSK1VcTNnUHw5 1keWPBSCevWfYOxO+AHaoXdwLsncGOTvC0/lG7QMg0tQlJi+jKUvEurnysL+PoInrb/Y BYjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:arc-authentication-results; bh=JwnQ//iDGj/U4pEq62LtaL1J9jgb7d7UJC1X/cTmk2I=; b=mPzEmukIFDr2//tUo6NKy4NDshngN6L68BXtB+PfX66wEdzFWG67e5Nt9fZDSjWpb/ cc/Ys0DghbZZv03mvzk+h3xSroSO0MSZWCYXDlq4wOjv+4YBE4iGXcYtNH0K3MoszGcP ldn8xOp8PIKYrnPjkmnMOIujmVD/k4AKLr9461AgCeYFRJnky12OJ0S7rouhr4cIvJrH 1ByHccT/g+j7IGYxtvl1+rugsjaak5azXzpoHOKcIbs+cabBn3IHncucfUWgdlsMVIT9 zBJe62p7FNRFsbVjft62vaPQqsKPhLXCKXZpvoNnV3OaFIf8WMq5vryWIteTM9BDseIW a1sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=lLoJnYgE; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=c2Q5Ddgf; 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=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u19-v6si2773309pgk.100.2018.08.17.16.20.49; Fri, 17 Aug 2018 16:21:05 -0700 (PDT) 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=@fb.com header.s=facebook header.b=lLoJnYgE; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=c2Q5Ddgf; 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=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726215AbeHRCZD (ORCPT + 99 others); Fri, 17 Aug 2018 22:25:03 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:54908 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725967AbeHRCZC (ORCPT ); Fri, 17 Aug 2018 22:25:02 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w7HNJ2k3013162; Fri, 17 Aug 2018 16:19:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=JwnQ//iDGj/U4pEq62LtaL1J9jgb7d7UJC1X/cTmk2I=; b=lLoJnYgEaCYeWdLMapt+RLtkeeywFmPRn/ojvxlMX4sYkwViAyL2++Vl1wBAEBgbREKt cSCOg16ouvLhOcDSnRpUiBH2aRUcM0fGFVqo314HeM61ksIPFh65LvjWUxalRYaj1nj4 kxTtKablojA3iLK5MCxlEa7ItPrzGmrAe10= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2kwxebskvk-7 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 17 Aug 2018 16:19:28 -0700 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.16) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 17 Aug 2018 16:19:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JwnQ//iDGj/U4pEq62LtaL1J9jgb7d7UJC1X/cTmk2I=; b=c2Q5Ddgf9+DboW+u04cbtkfJCocZ/4jYvi0RhYTOvSdNTlYBNvGiFPN1yia/GQkN2quHx2PszyW0EhbDD4iJoEErhebkZjTqBPSo9PQGnShZ74Eo4USurQpd1hWBhNk6fEpRyJa/gkx7XtMfFo+AMb1NgBY693nREUJRt0S5XMA= Received: from castle.thefacebook.com (2620:10d:c090:200::5:6176) by BLUPR15MB0161.namprd15.prod.outlook.com (2a01:111:e400:5248::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1059.21; Fri, 17 Aug 2018 23:19:05 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Andrew Morton , Johannes Weiner , Michal Hocko , Tejun Heo , Rik van Riel , Konstantin Khlebnikov Subject: [PATCH RFC] mm: don't miss the last page because of round-off error Date: Fri, 17 Aug 2018 16:18:34 -0700 Message-ID: <20180817231834.15959-1-guro@fb.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::5:6176] X-ClientProxiedBy: MWHPR14CA0044.namprd14.prod.outlook.com (2603:10b6:300:12b::30) To BLUPR15MB0161.namprd15.prod.outlook.com (2a01:111:e400:5248::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab94a184-28fc-4220-00b0-08d60497d452 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BLUPR15MB0161; X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0161;3:LOzCmJGOUUVeODJfwUHdeF9KDIWsSHwNjlMj9Xf60MOQB5htsU/RU6dnzdOa8rhh1S7avDpWQJkJUg+agHndCq5HsSU00eIh5QEvtD+3nhrqlo5a/gweHJAW395BSFRof+3NPhAilCAeWToTuoL+2GDTzJvIQqc+//ndnQstK8URmg9rJz/HgsumIvyJKT4QztshRvdmy4rpd37JMNocxrS3IswDmgjZ6nrGKoRRmDv4euMv+iidP/MpxORgfV9y;25:5PoMWE2QcB14pIoiCj803guytv5dintKMW4EZL+wRS6X6n6vYWS+6RMum17lCEoIFOfFuYcz7le9oMorzdxW8/A0FqltUsivq1XlfNwDL64TGB8PM/a5B6HM4jqhiikAiPqAbiepPFGrM9mLt2JEu2l4t8KTBIdcOV+wFM2ZXAMWwWsrtwaV2wieTEviZOHsWLm9QanxGXRDBRUYcSjm/Mh4Y3FMxSkz/FLJGHT9bMmqGyyVqfq8t4X0XiXyrFoles9N6lFdMs1CoIOu6HSRPAikNvnBL+pPftb/O3Ba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KOFX/rA9ODw2y2CZ/q5eHQKIKzswN/52QNuApdQmBtBVW2t241kH0PG3JySRHVHM/+C8Cy3oZk+FxmNharelICv+GddcuH2jmbmutG6b1Cz5Lw9TxphZqwgIvIb3r8J/6dSv1wGIzjgQVfqrvkfMxPx1iBn319Ymh98xOqYbac4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823301068)(3002001)(93006095)(93001095)(10201501046)(3231311)(11241501184)(944501410)(52105095)(149027)(150027)(6041310)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699016);SRVR:BLUPR15MB0161;BCL:0;PCL:0;RULEID:;SRVR:BLUPR15MB0161; X-Forefront-PRVS: 076777155F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(376002)(396003)(366004)(136003)(199004)(189003)(86362001)(39060400002)(6512007)(4326008)(53936002)(486006)(8936002)(2616005)(50226002)(81166006)(1076002)(81156014)(8676002)(478600001)(476003)(47776003)(386003)(6506007)(7736002)(25786009)(305945005)(69596002)(97736004)(2351001)(6666003)(316002)(2361001)(53416004)(16586007)(54906003)(6916009)(36756003)(48376002)(5660300001)(186003)(2906002)(16526019)(6116002)(51416003)(52116002)(52396003)(50466002)(46003)(106356001)(68736007)(6486002)(105586002)(32033001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR15MB0161;H:castle.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR15MB0161;23:sRowkWS/SuvKD+yq4pgo4SoJ9qhkwA3+H1rHA0I5c?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NEsl2Tff1Z3nDg7a96AN+ms+/Ft?= =?us-ascii?Q?6hZIjx59HXEBPe90i6SHlz9YcoAYle7uozlS8WZ5K1fC8yI7S7E6qprxDHle?= =?us-ascii?Q?XTXuuCsP3f3jppMnRMU29+CEDr0A7o98JwGKnmvrA4XYtl8TrQXN2gzo1itP?= =?us-ascii?Q?S+9pfjBx5EsoXokjEZ1ftvAx9SKggAzYSyIUoBid+DpjxA0vO0RDWSpMKr1N?= =?us-ascii?Q?cFG4mIXFnuEwwJ3QTv0OI8WfnIwy4xjIcfidDwI8JKgVdwyHdEi8uv+sOefS?= =?us-ascii?Q?r1sqUiqMBRQ2CCG2AnTAaPGlMdAGfyklU9JKxmNWzwkgYasRUJ3em009b9/P?= =?us-ascii?Q?K44IonyGW0urt7XOA+PjHsoL9dJstQBcXqJgMYG?= X-Microsoft-Antispam-Message-Info: FRmPvDRLRSaMlhu33ulF1AUjEq5KNc90FsrrRyjCoPUcadhFTpkHkOr8NS3j1pcYk64xMgVWnRm2C8FjmaUR9uie8SZIdFNDmW1ePJtwfjxVaFf1XxKuvWr8YUcJB6e6pM94CYkwoBEgaXxRdzgZyi7p0asXQExq0wm8zsof5FFS3StszHFegjJbL8HPhNyEsDLIaWMz2M3sB9SB0zRbiSH27VX12DWCagRfZNHyXRjVER/3l53GPohas9y+y793kS02XXTt6ayLv2/HzLKoGVt1i1J6w8LQfhd4nH/LcEFOg89pvpnB7MfQd+wf2YvvQEGTH03kxER6LcqCHnubtB8FuE8GJPwybspxx8sTWS8= X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0161;6:6QgByZFWe4S6beWLskbdX7qq4iHZzVpRxpQrdKNnNLJqZ/66LIeY2zZQkP4J8uOS2KfOVvjX/GMtqFYViK+szx6BCdMFDpB3tg4LPQlgsdFteSWI0037/fRcVqkb4TBjVCZ37IaVMhQLMPw66zKZ+1I+hYsjUX1X7uxMJBEiGk5NzOUW0nMlB7w2+zqDKimcpOec+pxh/XauzF4iq5hCgeiLH8wGKhbHQTbxORv5NPsx9UHUQuvo8MRsHxRz1hY5Zh8pcTJ5o8DjRzW+rPryfQNkDwNwkQvKI08kQXzNhoIoXQkPI2SWKdlmnomojsbHXkoZgO0qIVEdU+I5jYypiLqsKG4UvfQIovbp4yJ9Nry6kqq3P1UW8n3Aq+0mgOroXjJsHcEjc1CIvg1pag+/7jCuLWS/rf7PCpDgnQ4TjxSWeavyokIKx3/vc7z/FXaFbxG8eJjHxUjdVts/e7ywRA==;5:vOUNM2ulB0+pL6eSzpBAy6FqltV4Ns0IOI4Lx7cQPSII+X99PSXbqYmZW9fhgZv1j9FBrtuRAm/Bqcp55gBww6U6RPhB5CmEsMVFIZYUiGhWwqYX1GFt35IgJ58aRCFIQjE3Azr2KZm5vuJAR0nNOslwwIlytmi/KmZ46307cvU=;7:hrQjGZywCfNuudRdFv8BKLhd8nSIttGw+XYLS5ebCpdRBYXZwNodj5ReyO9WhGWPNzjHllpUbchCv2gL74Qdk8j0dt28msVthaqMV9dq/6rhU/Ewj0/MHDSMd5SUM9Hfxy6v+wCYQ3UVlBDb+D3UGcLiyb1bJmUR0hEjKaLkrhn9SuNHcsESfYjVsaEjP2smJcLGMms6XMLy+Gc3cJBVV1qMxvgm1EYNg8V32kYvvvL58b/Q5LNcvPOOPfAbqaXH SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0161;20:+YI0IY45h0VOKbf46BVlr+o+42nBfB2ctAJUL8j1kZPvlcsTBR+a6VXQHncCt5MPTioamZPDhQtJKso/jcZwIN/WUlZwK/hVnBn1fBgqiQ5Vq1D+opiVJElZcF+NnDWiYtuvxXlAo8wn1lf3jlN1ulo2kvEeJ9T9FfrJq0v0tkA= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2018 23:19:05.5959 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab94a184-28fc-4220-00b0-08d60497d452 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR15MB0161 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-17_07:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I've noticed, that dying memory cgroups are often pinned in memory by a single pagecache page. Even under moderate memory pressure they sometimes stayed in such state for a long time. That looked strange. My investigation showed that the problem is caused by applying the LRU pressure balancing math: scan = div64_u64(scan * fraction[lru], denominator), where denominator = fraction[anon] + fraction[file] + 1. Because fraction[lru] is always less than denominator, if the initial scan size is 1, the result is always 0. This means the last page is not scanned and has no chances to be reclaimed. Fix this by skipping the balancing logic if the initial scan count is 1. In practice this change significantly improves the speed of dying cgroups reclaim. Signed-off-by: Roman Gushchin Cc: Andrew Morton Cc: Johannes Weiner Cc: Michal Hocko Cc: Tejun Heo Cc: Rik van Riel Cc: Konstantin Khlebnikov --- mm/vmscan.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 03822f86f288..f85c5ec01886 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2287,9 +2287,12 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg, /* * Scan types proportional to swappiness and * their relative recent reclaim efficiency. + * Make sure we don't miss the last page + * because of a round-off error. */ - scan = div64_u64(scan * fraction[file], - denominator); + if (scan > 1) + scan = div64_u64(scan * fraction[file], + denominator); break; case SCAN_FILE: case SCAN_ANON: -- 2.17.1