Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1047289imm; Wed, 15 Aug 2018 10:27:28 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxJ3zXg2OJUJMB/a5weSYyis+T1707aE2KkE+O+SXxkUQCeqFHWSCM/D6+fUgT7hxKTVHGR X-Received: by 2002:a63:1810:: with SMTP id y16-v6mr8271791pgl.48.1534354048155; Wed, 15 Aug 2018 10:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534354048; cv=none; d=google.com; s=arc-20160816; b=F1x87YHzm/22InhHJKhD53zVVi8ciMpuMgvGDLnqzXL7EjabGzxxK8mdQUp+5/1Q2d 3yM/HNJlwtFiPwvceoB3Sm7NYU3cOndJiKFXfl03iy/fXsof+AkCm/jRKa/whI0+FHy2 UJ6OcDR4F8EJNST0DFE5HDY7hE0rQGJoY04Le8oIOpjIkDGe16EDNHohXjjS0hDl6gTK mW1JWUQgfEea/+6+70UUOB8Kce98f9l2X46QK6JIVgnJFbFm+VaL6QDvaefUebXoYouf SwzKfFZ5VqxEZkPiIwxLXnOM1QdfN/rHOwOHGJHZ4m3Ipz2j2AtHIazjVjK1JE343hMa FM+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature:arc-authentication-results; bh=Z3XsjA3uq+Ih9vIkLFTDGXoAdhvZSoZdeBd6FcdaUi4=; b=tVthSVObqVo5ThiExqa6u3Am08U/B6hlbBA9B/Q6keSi6cSagJOIHxIHtV0U2j7u/3 aVgoaz0wXozK384H1hV0hASMrR1mPnynHiG9iakJppYXR9aJazEbvkmM8AFVqmQk8gk7 Eirdd9sEE+VeD/N50zmcSIVlHz5ptASUHEYlHyksB1Equ6QiT6aGXsiDMgq7g5pWcXUP 4gbTYTSDB4ymvqAwI29jxDhob6ypCb9khOQc7CJMmzuYpTibjT6XGo/tmCUekE4uboju bfZn7zunvJjKz/DuYALQngeFEYlwkRsvq9lz/yoW7By0Pwhvk4PwyYw5whM3O35gLjn7 KlOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Fuyosn1n; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=Y2F1Q6B7; 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 r2-v6si20962426pgd.138.2018.08.15.10.27.13; Wed, 15 Aug 2018 10:27:28 -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=Fuyosn1n; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=Y2F1Q6B7; 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 S1729889AbeHOUJd (ORCPT + 99 others); Wed, 15 Aug 2018 16:09:33 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:59056 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727604AbeHOUJd (ORCPT ); Wed, 15 Aug 2018 16:09:33 -0400 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7FH53fd025327; Wed, 15 Aug 2018 10:16:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=facebook; bh=Z3XsjA3uq+Ih9vIkLFTDGXoAdhvZSoZdeBd6FcdaUi4=; b=Fuyosn1nPSgj/nZBRcGdyP37ER2t5p9XrfMSCfW/vHXBRrgMENjiA2BUs3FDJ/sIUe+L pjN7Bwh2mx1SJiwUJvNXPbLhTdUyslQ3K5Voreyy8QiGNFNR3JOT2SajpEB188gYnhfW 7Agyjc9xjG24S09Oh7O+Re/kwp3qVSZIO/s= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kvp5w0g82-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 15 Aug 2018 10:16:26 -0700 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.34) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 15 Aug 2018 13:16:23 -0400 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=Z3XsjA3uq+Ih9vIkLFTDGXoAdhvZSoZdeBd6FcdaUi4=; b=Y2F1Q6B7BKm3n8HyI+m2dbAZhpXVKjiB8H3CwqIjE1TUgD7lBSv89MPNTMb0k1yMU2fNtBEQbZ5jtaYkai1fSIPlDcTtIq9G9x7mJYCKK4zEE/11nNQ1gDhW0ObHa4+/PQ4yzyL9vW3Mjh/BEddB8LoQCheQITPp/IB7jEW0EO0= Received: from castle.DHCP.thefacebook.com (2620:10d:c090:200::5:abf7) by BLUPR15MB0162.namprd15.prod.outlook.com (2a01:111:e400:5249::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.22; Wed, 15 Aug 2018 17:16:16 +0000 Date: Wed, 15 Aug 2018 10:16:05 -0700 From: Roman Gushchin To: Shakeel Butt CC: Linux MM , LKML , , Johannes Weiner , Michal Hocko , , , Tejun Heo Subject: Re: [RFC PATCH 1/2] mm: rework memcg kernel stack accounting Message-ID: <20180815171605.GB26330@castle.DHCP.thefacebook.com> References: <20180815003620.15678-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-Originating-IP: [2620:10d:c090:200::5:abf7] X-ClientProxiedBy: MWHPR22CA0025.namprd22.prod.outlook.com (2603:10b6:300:69::11) To BLUPR15MB0162.namprd15.prod.outlook.com (2a01:111:e400:5249::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 177280c8-5bda-4055-c7b6-08d602d2d01e X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BLUPR15MB0162; X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0162;3:trQQPY96uuw/OPLbLDLYc8T4MThrF4wSfuN+rOgTjFgixzqqBCLYeoWudG/oppqsp0y0ryifYsjmDPegF7crl7q59i8nO+nSkn4AU4UCRSaGHbNpv9urH7FfhnRkYnEEpURhJEvVbnZ3qNCuqIIYNIEFKrSgUg/5Q0JCR6hbmpXcwdzEnbrYNL5xFwk45eeXIZjzikejqcCH9i7SuzGq46ciMI34OI0CjikMhE+mN3TZAiLVLYEZ8yyxCJ7y46q9;25:IKyoS9GpRa8wQUP7B7jpC2rl5B6OVW+Pu541w2dlP56FYiRtcd5NiFxGxMe+RT2jXcW9qIoq0/eavmQvcWZzVP33VOri+WuCf+G8v48LF31cDrTU0wUCogpeO3Pzdr22zTBxkgCV3rhadJuznQYJ8m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4AmEVk0M2HHwXoDESyfWw/tL+tTCcOOfV6RKPUJQkcJyQSC4+JCjryjwr85KJny5SuEK/RfPT4PmehQtOxuW7ZQFle48qQLucErvysJ4phjAHQXg9CbUKLtgSfeKkUfRnMYgTSTmat9VGzFma+R8ZOUDd5gNTGa6adatZopatYKoVrKRicQOzm8iTdcvNSO3ivnB0sg+3njGKQsYb+T55W7RxtyXyznySe6NA25QZyVrT1rQXqGbBAjd6jj3JPNiqTKYd/roSQ2LcTA/RQCKPZorsFw7VEEl1UzbtkVDhECa3EGdyQOVBlZEzLfziX5Gd1WmAW6v1Bsg4XML0Z9cnNv0meEccdEO1Vz8iFLQGWxp4NCibxdjTJ8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(67672495146484)(211936372134217)(153496737603132); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823301033)(3231311)(11241501184)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011)(7699016);SRVR:BLUPR15MB0162;BCL:0;PCL:0;RULEID:;SRVR:BLUPR15MB0162; X-Forefront-PRVS: 07658B8EA3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(376002)(366004)(136003)(346002)(396003)(39860400002)(189003)(199004)(15650500001)(217873002)(2906002)(16586007)(6506007)(97736004)(52116002)(9686003)(86362001)(7696005)(386003)(53546011)(76176011)(5660300001)(55016002)(25786009)(54906003)(6916009)(50466002)(186003)(4326008)(46003)(58126008)(6666003)(16526019)(11346002)(316002)(52396003)(446003)(8676002)(81166006)(81156014)(47776003)(68736007)(105586002)(23726003)(476003)(486006)(6116002)(1076002)(478600001)(8936002)(305945005)(7736002)(229853002)(14444005)(39060400002)(106356001)(53936002)(6246003)(33656002)(18370500001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR15MB0162;H:castle.DHCP.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR15MB0162;23:3iis7H57KE6igwvN5qd18IAFV6vYWwgOXU8took5X?= =?us-ascii?Q?96yTe6aD6eq+f8R9x4g7XaycEgpKesnhY9sVGP9Oqnfew3et4CkEZii798pL?= =?us-ascii?Q?ZdEef2urdEN/PXxJSJE9U466o+RQP6zLFJF8lYJhgIsDZKtM1svF7EenHWPc?= =?us-ascii?Q?G4Vv9t1PUYVxSM1JxX7Bl417ePGmY8Ga++8eQyaB6EJntn/cQdV5TOKMhiHP?= =?us-ascii?Q?rz+bYVc95RWxk7V7PZb0J5L4clUOzIUtESsGJhgTMG4y+2OGDClI9YKGOJyE?= =?us-ascii?Q?t20RlPuPki9pHB/IhxBZDY8DMnWFy4Zpnw3vwLP8gXranWcW22wZTuSWfpHY?= =?us-ascii?Q?BzMbNMhUmPmtn2DYrjcQu4cPAAPyFUH3Rl+xqIq1h6cA3fcOx01I40iIyfiL?= =?us-ascii?Q?02l65dc2mc6/tHScncy3Np4Drp6o5x1zIpwdH4Lnu+rrbB6RdqblqQAirElN?= =?us-ascii?Q?IMoW2p2NFk/S+5mGFRCfWDJEDxZzhWRo1YUeA+ReuFnIecvJVI2iQg74N36p?= =?us-ascii?Q?Ftb67H1XQqedCdxwvodhWHKNk9a5KSx76k5/iOy+0rMdZNgsD3g3x3C9VRN1?= =?us-ascii?Q?EErua8Wlhbgjnbds05jBqzcMh1fyZ0ZZpl8nt4hQJclkQgZ4CAICfkIVRYDq?= =?us-ascii?Q?opQu31KgeziquGTPmYLipqsTI69QePsyZEzTIID7k9FHqitYUYMJIcraujAq?= =?us-ascii?Q?gGCj3+eFw+vrdH3r8W2Y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ticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0162;20:p7HwX/C/mTaSA6ff2l6VxR85OcUSzK3HoRZHNcCtdCQyMYgOrmXFfBrK4Up9jPFQzEMMuYeyhR5XahlUJH4p4XzzTGb+PDoKoDOZyp00zc14+PNiFa/1Znms/EVXJo7bSoG6qPWnQABN1YBPhxiUh3lAluO5wdMEG+X8vM3abcE= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2018 17:16:16.5139 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 177280c8-5bda-4055-c7b6-08d602d2d01e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR15MB0162 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-15_06:,, 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 On Tue, Aug 14, 2018 at 06:18:01PM -0700, Shakeel Butt wrote: > On Tue, Aug 14, 2018 at 5:37 PM Roman Gushchin wrote: > > > > 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 > > I was also looking into this issue. I was thinking of having a > per-memcg per-cpu stack cache. However this solution seems much > simpler. I also thought about having per-memcg stack cache, but it seems that caching 2 * n(cpus) * n(cgroups) stacks is an overkill, and there is nothing memcg-specific in these stacks except that they are pre-charged. > Can you also add the performance number for a similar simple > benchmark done in ac496bf48d97 ("fork: Optimize task creation by > caching two thread stacks per CPU if CONFIG_VMAP_STACK=y"). Sure, will do in v2. > > Reviewed-by: Shakeel Butt Thanks! > > > 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 > >