Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp219406imm; Tue, 14 Aug 2018 17:39:41 -0700 (PDT) X-Google-Smtp-Source: AA+uWPynYbF/ahES3klPyzvW6xdVJ/hiMAehPTIi1xokUaFJHPv11QkFZcRFlKkcB1eDUfxuibD0 X-Received: by 2002:a62:5302:: with SMTP id h2-v6mr25725601pfb.183.1534293581460; Tue, 14 Aug 2018 17:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534293581; cv=none; d=google.com; s=arc-20160816; b=siT0Eg1JYJy34puRiWmFMY5eQsvwnPhVpZdEFH8GFWs/0jVTWU4qk8DhQgsZCvkpIR IjwBXkhk7GWo5au+PguqgpiwP29WjQW6JU+PgGbRGT01FBK9uRAh37H3xr+3qOpLeWRQ QzXRNMXOKABxe77SY3ow2wukh5ABCeFTShGAKiEfPhlXDOtcvSoQ94UDmJgvFgBsZP/f JmwxeAqmwIfhAYswcdzurS/afRt5/KZGz8UOa9v/D+QEjrsXorEG4AVrTWKxrVQLofIK UDYxZyQ1Tj03ybLj0Uokln4nJ/Nby0GUNpAVnv8NaG7qPSRctB595BPAkBKi8IWtgO4O BPeg== 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=msuVjdyVfTRbspscaCDwIy7tMM2QtYrgmrKRNFFQspQ=; b=Sc3ZH3x1CYIJ0Vmum1HK3WCEw4rKrQlMP+0CLbiYQmEDILr1mm1G2WDyqeNxnMEg3d hlNh3QFzHJAqyRXrrD2K1kvPObGaJzh/RNkC48c1nXooZenTudOnj04CL6chRoBP1O5l yGPRjgrJpCAZ6y4mGMBjKVxY+/U5M+52gwt00Bgd/qJxqLcqDqARKofS+ELvmipY9FNv eMEcK0h2+pjRa04JcUVfYlUJi0BvysruLgzieg5qKfJ9LAoE/YtcDLWtZeXx89ESK0b8 m3dLBJy7ucPVqhl/YOpmzE2PQ06RctJIKkKTDeAkUP3hK1fPzi3swY8q+ZMQSjeiEMZM nVsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=GIt6juWo; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=XPi77NN+; 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 k13-v6si21902037pgh.213.2018.08.14.17.39.26; Tue, 14 Aug 2018 17:39:41 -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=GIt6juWo; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=XPi77NN+; 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 S1728302AbeHOD0b (ORCPT + 99 others); Tue, 14 Aug 2018 23:26:31 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:35832 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728144AbeHOD0b (ORCPT ); Tue, 14 Aug 2018 23:26:31 -0400 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7F0UOnZ028091; Tue, 14 Aug 2018 17:36:45 -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=msuVjdyVfTRbspscaCDwIy7tMM2QtYrgmrKRNFFQspQ=; b=GIt6juWoRAuoQ/eHrtOBOWswvnmHcp2oluRtAtqJEoVtzj9tjwsoA0Z53J+9O9nV6JAY CxxdzI/Dq08sZ1RMAu4eMjXle3+wjMHyzY8rKrPoqd/uXK4uwZc8JJjP9SqQt7303os6 YTAEz24Abvt05gaZVWyexfBp+WejkTEtWaU= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kv6hqgg7w-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 14 Aug 2018 17:36:45 -0700 Received: from NAM05-BY2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.20) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 14 Aug 2018 17:36:43 -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=msuVjdyVfTRbspscaCDwIy7tMM2QtYrgmrKRNFFQspQ=; b=XPi77NN+JiTx1ADpNQleVwh/AY/CKp7MPzKQhyYQ9PHD6kCPh2V2FxiijPqEhqF31DnZqTK/3fDUXZ7SQLD2pOTE2Vss97KTtNlqd/6paEeOZ0d0E1jFIxApAds2wOMwJmQmkSnVfhVz2lHmJ8RKx2djexWEe0s3alp5NRg/Ozs= Received: from castle.thefacebook.com (2620:10d:c090:200::7:b884) by CY1PR15MB0169.namprd15.prod.outlook.com (2a01:111:e400:58bb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.19; Wed, 15 Aug 2018 00:36:40 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Johannes Weiner , Michal Hocko , Andy Lutomirski , Konstantin Khlebnikov , Tejun Heo Subject: [RFC PATCH 1/2] mm: rework memcg kernel stack accounting Date: Tue, 14 Aug 2018 17:36:19 -0700 Message-ID: <20180815003620.15678-1-guro@fb.com> X-Mailer: git-send-email 2.14.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::7:b884] X-ClientProxiedBy: MWHPR19CA0006.namprd19.prod.outlook.com (2603:10b6:300:d4::16) To CY1PR15MB0169.namprd15.prod.outlook.com (2a01:111:e400:58bb::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9a5cdb32-0da4-4c4d-f667-08d602472af8 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:CY1PR15MB0169; X-Microsoft-Exchange-Diagnostics: 1;CY1PR15MB0169;3:LRPc4/4L52F3p92MLwHhcDS1GgNCWW+aDFitu4cOjVbvhMKnamUv9GJab1wWcjzsCqj03dlDRg68gVv9JyvDJ/1yXVtgwLDCKOOS7AS6LOnlVvHW33wzYzQ7Rc/exldgfArZJFtSTriKzInl7FMiv0teCM2/i41/8Ws3utRGDVQ7WxhpxM2YbNnPoL7b1nLyrPJpqgUwRbruKAKJYF0HrpUYHWb+1UaqQTjF3sQa5x4rCDnMAtlcbrgq9egnvGTk;25:o6pCE9DuT7YO2itXB/7za9CkxvdbemYmvFSLo6KhggXzUWum13ceyNPdMJDv/42pCW2mZYxsMB4JAT0tjXzGgM9b51vkuU1uq8YbKAgMqrM4SEoQEmthkD8CM312SpvV4Vy5F2lgxJdBg2uo/p8V7I59KyO+YXXYvx3Oc6YkYUnS8lR/eK+VUIV+Yq2atKSjXnPe97TLP0FEeV6t2RGfWncFnw00ikeblESrqAfbnHkZjCTTZFJdMwJacIuUUw9BKzHXJyHH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oEeTkVqLbQB7z37LCqaqIPnrTKXuAh6ZzkAjcQjgqKvAUne5tEFvMkg0it4oXTOdgArQR75Cn9jSIvXzgyQCFmV383gb7VLuvOvKM569ohUm7ZGOHoNrrykjaQYYiL3j0kdGMYR9wslpaoEWkr+Ysh64PRyf2B3ucBNN2hYykEXn5r8Hx4yARjE7ido+i0TBNhX9P1oocHP8= 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)(93006095)(93001095)(3231311)(11241501184)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:CY1PR15MB0169;BCL:0;PCL:0;RULEID:;SRVR:CY1PR15MB0169; X-Forefront-PRVS: 07658B8EA3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(396003)(346002)(376002)(366004)(39860400002)(136003)(199004)(189003)(316002)(2906002)(52396003)(54906003)(105586002)(4326008)(39060400002)(69596002)(51416003)(25786009)(16586007)(53416004)(52116002)(36756003)(305945005)(50466002)(7736002)(106356001)(48376002)(2361001)(97736004)(68736007)(8676002)(81166006)(81156014)(6512007)(6486002)(53936002)(46003)(8936002)(2616005)(486006)(476003)(386003)(6506007)(186003)(1076002)(86362001)(6116002)(2351001)(6916009)(14444005)(6666003)(47776003)(5660300001)(217873002)(478600001)(15650500001)(16526019)(50226002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:CY1PR15MB0169;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;CY1PR15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+2Z1bZE= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2018 00:36:40.0458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9a5cdb32-0da4-4c4d-f667-08d602472af8 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR15MB0169 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-14_12:,, 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 If CONFIG_VMAP_STACK is set, kernel stacks are allocated using __vmalloc_node_range() with __GFP_ACCOUNT. So kernel stack pages are charged against corresponding memory cgroups on allocation and uncharged on releasing them. The problem is that we do cache kernel stacks in small per-cpu caches and do reuse them for new tasks, which can belong to different memory cgroups. Each stack page still holds a reference to the original cgroup, so the cgroup can't be released until the vmap area is released. To make this happen we need more than two subsequent exits without forks in between on the current cpu, which makes it very unlikely to happen. As a result, I saw a significant number of dying cgroups (in theory, up to 2 * number_of_cpu + number_of_tasks), which can't be released even by significant memory pressure. As a cgroup structure can take a significant amount of memory (first of all, per-cpu data like memcg statistics), it leads to a noticeable waste of memory. Signed-off-by: Roman Gushchin Cc: Johannes Weiner Cc: Michal Hocko Cc: Andy Lutomirski Cc: Konstantin Khlebnikov Cc: Tejun Heo --- kernel/fork.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 69b6fea5a181..91872b2b37bd 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -224,9 +224,14 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) return s->addr; } + /* + * Allocated stacks are cached and later reused by new threads, + * so memcg accounting is performed manually on assigning/releasing + * stacks to tasks. Drop __GFP_ACCOUNT. + */ stack = __vmalloc_node_range(THREAD_SIZE, THREAD_ALIGN, VMALLOC_START, VMALLOC_END, - THREADINFO_GFP, + THREADINFO_GFP & ~__GFP_ACCOUNT, PAGE_KERNEL, 0, node, __builtin_return_address(0)); @@ -246,12 +251,41 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) #endif } +static void memcg_charge_kernel_stack(struct task_struct *tsk) +{ +#ifdef CONFIG_VMAP_STACK + struct vm_struct *vm = task_stack_vm_area(tsk); + + if (vm) { + int i; + + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) + memcg_kmem_charge(vm->pages[i], __GFP_NOFAIL, + compound_order(vm->pages[i])); + + /* All stack pages belong to the same memcg. */ + mod_memcg_page_state(vm->pages[0], MEMCG_KERNEL_STACK_KB, + THREAD_SIZE / 1024); + } +#endif +} + static inline void free_thread_stack(struct task_struct *tsk) { #ifdef CONFIG_VMAP_STACK - if (task_stack_vm_area(tsk)) { + struct vm_struct *vm = task_stack_vm_area(tsk); + + if (vm) { int i; + /* All stack pages belong to the same memcg. */ + mod_memcg_page_state(vm->pages[0], MEMCG_KERNEL_STACK_KB, + -(int)(THREAD_SIZE / 1024)); + + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) + memcg_kmem_uncharge(vm->pages[i], + compound_order(vm->pages[i])); + for (i = 0; i < NR_CACHED_STACKS; i++) { if (this_cpu_cmpxchg(cached_stacks[i], NULL, tsk->stack_vm_area) != NULL) @@ -352,10 +386,6 @@ static void account_kernel_stack(struct task_struct *tsk, int account) NR_KERNEL_STACK_KB, PAGE_SIZE / 1024 * account); } - - /* All stack pages belong to the same memcg. */ - mod_memcg_page_state(vm->pages[0], MEMCG_KERNEL_STACK_KB, - account * (THREAD_SIZE / 1024)); } else { /* * All stack pages are in the same zone and belong to the @@ -809,6 +839,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) if (!stack) goto free_tsk; + memcg_charge_kernel_stack(tsk); + stack_vm_area = task_stack_vm_area(tsk); err = arch_dup_task_struct(tsk, orig); -- 2.14.4