From patchwork Tue May 24 08:49:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Davydov X-Patchwork-Id: 9133361 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 A26E3607D5 for ; Tue, 24 May 2016 10:22:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AB6628220 for ; Tue, 24 May 2016 10:22:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F96328233; Tue, 24 May 2016 10:22:32 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01E1A28220 for ; Tue, 24 May 2016 10:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755675AbcEXKWO (ORCPT ); Tue, 24 May 2016 06:22:14 -0400 Received: from mail-db3on0104.outbound.protection.outlook.com ([157.55.234.104]:64592 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754813AbcEXKWL (ORCPT ); Tue, 24 May 2016 06:22:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=b/7qjwPHb0VShXLKOcYo+fZY6AvCTrPhDjUw92qwqxg=; b=a5Yk5AVQp00zCf2lQVkGSfH74UZY7vXUCDbKlff3/7IRKoVyZ98eEABkd7PPMJetGRh6d4Q7M8Sjjbi9sBgUdzGPsw3Wgc/s9ik82Fphmqw0Oz93DTcBpFbMg5ZIKzUUnI+nkQsJ/JhbnUKHjwIBXY88VrM3e1CndOt0a27Rd9E= Authentication-Results: linux-foundation.org; dkim=none (message not signed) header.d=none; linux-foundation.org; dmarc=none action=none header.from=virtuozzo.com; Received: from virtuozzo.com (195.214.232.10) by VI1PR08MB0592.eurprd08.prod.outlook.com (10.163.169.22) with Microsoft SMTP Server (TLS) id 15.1.497.12; Tue, 24 May 2016 08:49:42 +0000 From: Vladimir Davydov To: Andrew Morton CC: Johannes Weiner , Michal Hocko , , , , , Subject: [PATCH RESEND 5/8] mm: memcontrol: teach uncharge_list to deal with kmem pages Date: Tue, 24 May 2016 11:49:27 +0300 Message-ID: <18d5c09e97f80074ed25b97a7d0f32b95d875717.1464079538.git.vdavydov@virtuozzo.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: VI1PR0901CA0081.eurprd09.prod.outlook.com (10.167.203.177) To VI1PR08MB0592.eurprd08.prod.outlook.com (10.163.169.22) X-MS-Office365-Filtering-Correlation-Id: 82a59574-0e21-4269-964e-08d383b05993 X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0592; 2:9xZBgOqv9qhAYEmwTfopz7CReVwNlI7UBEky/sGm48R2Dh2EbfYwzhqndLsdcSfvglMGS4xJLYi6IzP2EehzdwTDAKAV3hgbKbofYKBl0Fl3UJ68Gn8AErhZR8a8wkVoxmKYSMnlflDV8WgSXNLABJkBhQU0c+7FprYbQeKRCHh5UeNh9D0DlnCeayCESsVD; 3:/GFRF3qvh0H/RVSjuSrMioiDdi571r9bjn5ulHDKp/fR2Y/OSDw/82FoL/srRMVMEPk7GAuPE2p50/8dfYHSKTr8gQlFsaw1q6YeXTrAkcY42Jl1DBh+fAcyCxLoFX2l X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR08MB0592; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0592; 25:V/GzQR4n9Xbzi8ZJssayv+wtqucZwwUEc5hIl2cKlXSOH+3OnGqaIeL0QcsPdoEVs2rKfzJoHKLvV6rcLk91ZEWsYYlhBFDt5aavwnSIMrrQS6eGK0UIvCSK5ZQcedslZ34Ms6kDtU/KaCvzlErPhTeb3ELTm8AotOyWcYVEUfk3RoxytnItge6fJWJY9PdTmI4TWEwyhpOm8GwDhepDwug3D9MijHXBB8ejeGKmtkb/JuByHkN0fuTSNN68LPBu/+0EUnB5flG0dUR2jrpplDz0j01h7tyOjq4fi67a1NWObGrDyCMTbTLsRKb2ex2MDSJbj2n2/WFC9Jnocazjm8g2TfosperrdG12D4BnnoYgOASzw1GMHJxQwErzP0FFEKc5RnPTSEvqmPMKyt4frRBlZjCa6AuEszdUQW/Cjo/mRzZPicKgRz2RFqgwU1zMup3iEuXsUtL+UAWGV1RBEN+7Pc+ZH/9glhfqm46Rt+VOYo17cJhKYs0getMj+Ee7YyRk7QPSizGByCqmc/yPEvGNKOIpiLEB7Hd8dxfeuTuNnaucWEoihNTGMP/80dhS6CbNbfdJAMgCPIflaJmki3KV8ns2qTzYE7Ftg070hCdncdMsvAvpZET6QW8QUQK6KOEpTvYN7lKEKl23xKaw4CMKFL2RsZWbFO3OPl5sFdvaXbGgbITspZ9wX9uJdRnPUk9WtarUpB/f+62xADAIFA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040130)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041072)(6043046); SRVR:VI1PR08MB0592; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB0592; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0592; 4:n2BdE4s7abkEJvQ51EkYSVq0vU//m3kpfvdEPiGADdZAgi6xvqXM+DUo/Tgvc9LQWhho/ln+CkT6x0D11m09c7Wxxm6UbqejFbYHY5SrcnQD7+cIXyVgGcOeLxTECgLGhsbfu8I95jrby8NC2QQd+nr+5dqaB0Ss7cKgOFRz4VYmnlkSIkRz18ikOpkUCik/tkMWx1uLys6UvOCmQw7NJG2ty/ZPImA6tRbomT6YXNWTnRauGv/81eaheQiXQu0UQd36AfN2XoosUL8e+nFhRyo6Lg/+QHTwLRylY9emDv+mA5HsPcTwSaarSGs2iqOxMooahAF234NqiuDbaFgOaenDltfADczZkFuc7Or3N7qRPFCY2C+jw09n4VHv3Pk1I/GXjxzzIVx68+efsekPNljkkA+4RWOxWmpeCsvEcFc= X-Forefront-PRVS: 09525C61DB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(586003)(36756003)(3846002)(6116002)(2950100001)(77096005)(76176999)(50986999)(575784001)(86362001)(110136002)(92566002)(19580405001)(118296001)(19580395003)(5008740100001)(189998001)(229853001)(2906002)(4326007)(47776003)(5004730100002)(66066001)(50466002)(8676002)(80792005)(5003940100001)(33646002)(81166006)(42186005)(48376002)(50226002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB0592; H:virtuozzo.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0592; 23:lFBjISf1fFDf3f7oSG2/dvpkc4vM325pC2+o+85EJ?= =?us-ascii?Q?AVpnGY58YjLkTE/3XLuKufLuA6aadFG/b1Xqt1/lDe9G3xSw3j2a7NB7URwP?= =?us-ascii?Q?w47FxqDfA2k5TYSkeuIoEiXt7RnCJGSzIQz2NiCcNRhzTUlOntSp7vJlsveC?= =?us-ascii?Q?afnhACEqlWQtQwcTVZmA4MmX1wNTCVUrWLxNNnLjJR5UYlUuKAD+Uq5Dm7PM?= =?us-ascii?Q?ao81NSY/FTs1FmDnUbJRgloAyiF1ONO+qIdVxSSsjA6Ht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Q2HmeFTA==; 24:n4qF/QQlN9haxk04U5FGxqDTyftc24b322qZAlQ82vvRBOEZ+RnailS9OlaWrT9hxV8c7itmuRhyMthLtG+rnD8tDUVoX6+vRH/HwyNGSV4=; 7:JYCl4MVdraLB/loBgHFeTQsGi08J1n6YfNfhcm3wNn5EzRGIQmaAkWoXmwPOMGPjKM2K2aOdhoPK6Ud01Lc4mZibUxv0aaV8FryVebmy0b0ZvieCQVNg1Wo5Kt4Ta2lK6xyz/5KW7Ig3gJ6He4zAslPXQ51YKDpvNfQhT5hXdO22LVjVj7Bf9CRT1shpuvEF; 20:lGd6UfGktjs776qRICO6FOZWXLoWq0rqnogxIhG9tuEkn3qXyfohXOqPXiwKEGSMGSnDXHVquP3D9uYbd/WtJEeHbEXAPy+8ZFo7wzhBOrGOmEQ9V4zDSkCz7p0sJK+KSxgnxltoJetG39Wua38n1JRcq4RM2SHP2RQPDCf+9WU= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2016 08:49:42.0948 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB0592 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Page table pages are batched-freed in release_pages on most architectures. If we want to charge them to kmemcg (this is what is done later in this series), we need to teach mem_cgroup_uncharge_list to handle kmem pages. Signed-off-by: Vladimir Davydov --- mm/memcontrol.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 482b4a0c97e4..89a421ee4713 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5432,15 +5432,18 @@ void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg, static void uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout, unsigned long nr_anon, unsigned long nr_file, - unsigned long nr_huge, struct page *dummy_page) + unsigned long nr_huge, unsigned long nr_kmem, + struct page *dummy_page) { - unsigned long nr_pages = nr_anon + nr_file; + unsigned long nr_pages = nr_anon + nr_file + nr_kmem; unsigned long flags; if (!mem_cgroup_is_root(memcg)) { page_counter_uncharge(&memcg->memory, nr_pages); if (do_memsw_account()) page_counter_uncharge(&memcg->memsw, nr_pages); + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && nr_kmem) + page_counter_uncharge(&memcg->kmem, nr_kmem); memcg_oom_recover(memcg); } @@ -5463,6 +5466,7 @@ static void uncharge_list(struct list_head *page_list) unsigned long nr_anon = 0; unsigned long nr_file = 0; unsigned long nr_huge = 0; + unsigned long nr_kmem = 0; unsigned long pgpgout = 0; struct list_head *next; struct page *page; @@ -5473,8 +5477,6 @@ static void uncharge_list(struct list_head *page_list) */ next = page_list->next; do { - unsigned int nr_pages = 1; - page = list_entry(next, struct page, lru); next = page->lru.next; @@ -5493,31 +5495,35 @@ static void uncharge_list(struct list_head *page_list) if (memcg != page->mem_cgroup) { if (memcg) { uncharge_batch(memcg, pgpgout, nr_anon, nr_file, - nr_huge, page); - pgpgout = nr_anon = nr_file = nr_huge = 0; + nr_huge, nr_kmem, page); + pgpgout = nr_anon = nr_file = + nr_huge = nr_kmem = 0; } memcg = page->mem_cgroup; } - if (PageTransHuge(page)) { - nr_pages <<= compound_order(page); - VM_BUG_ON_PAGE(!PageTransHuge(page), page); - nr_huge += nr_pages; - } + if (!PageKmemcg(page)) { + unsigned int nr_pages = 1; - if (PageAnon(page)) - nr_anon += nr_pages; - else - nr_file += nr_pages; + if (PageTransHuge(page)) { + nr_pages <<= compound_order(page); + VM_BUG_ON_PAGE(!PageTransHuge(page), page); + nr_huge += nr_pages; + } + if (PageAnon(page)) + nr_anon += nr_pages; + else + nr_file += nr_pages; + pgpgout++; + } else + nr_kmem += 1 << compound_order(page); page->mem_cgroup = NULL; - - pgpgout++; } while (next != page_list); if (memcg) uncharge_batch(memcg, pgpgout, nr_anon, nr_file, - nr_huge, page); + nr_huge, nr_kmem, page); } /**