Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1016308imm; Wed, 15 Aug 2018 09:57:10 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwu3Q+pfJL7c9KaLdNGT6cpPXiFwpIaY8DZIyYv1Fg4OBRgPIpX8mE9JnG09HX4X3PppLe0 X-Received: by 2002:a17:902:2e01:: with SMTP id q1-v6mr25267663plb.40.1534352230635; Wed, 15 Aug 2018 09:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534352230; cv=none; d=google.com; s=arc-20160816; b=C1Z4GHjpqdg09uM+djSSbUsBNkotEhWrGo3q7CcFQtVLukoJvwm+67o1FHS1QdFAtn fsbiI66bvJwu1hA+rXA1R+B1MTbNI6rWDP46AbeCz2R4okQ2U5ExVwv7/MOUDHyKCfKn +Q1O/RlZ23l3kC4pTXQj/EoyExf1gE5DVJf/JeIu6Vi0nRvSkRUuUcK45EIVWitwENSN cvNWkdhDN2jCkmjKlJqNZDVDId1KdfEc/YN+b7a5ah4bWqRcjjPav31MT+k9XKy5O7GV 2t1qz3Mxi9T64tJRkT/fyVSdeAktAXKiMD8yFSJrSyvKuhzoMrnaE6E9p95RkoCk8aEC Q7GA== 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=63L+FYLZ5r2I5JwDiCG5/mGiMnlwAR7/rObgQjydjAQ=; b=Kp3DWdGlnsH6zpb0XO+9ETMijB6FYxHZEGujZYddQl4RLDNx5GnObnAKAi64gCql0a QA37Hk25rTxkJyag7curwU/LthDn4DZ5oixzCzFzO2Z4zIzaVRQX93lIeHAEcnNKntY0 mW87KoeVmxcqVBKfDepqeihNuTZSuJIjGhKgSQXqAudlWu4y5tCPGXJdZJwH5UQwpKNr 9V/ivRhDhVavBMU/eP14d22KdrkmL4KidzR0s7Q3jppRPdMSW6McJULffh3/hxLtgNkG XYLu0DYLI6ODaD93qwcTp/knee9bbQiIX3denE67v/I8a5LDZtU1c+VjZdTOyOQWgj/F yW0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=he6roAuh; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=dbhY7K+7; 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 bh12-v6si19185355plb.425.2018.08.15.09.56.55; Wed, 15 Aug 2018 09:57:10 -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=he6roAuh; dkim=fail header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=dbhY7K+7; 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 S1729950AbeHOTsj (ORCPT + 99 others); Wed, 15 Aug 2018 15:48:39 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:45800 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729347AbeHOTsi (ORCPT ); Wed, 15 Aug 2018 15:48:38 -0400 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7FGtcXq003292; Wed, 15 Aug 2018 09:55:38 -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=63L+FYLZ5r2I5JwDiCG5/mGiMnlwAR7/rObgQjydjAQ=; b=he6roAuhUGR9K+josHKYSUScQmxC5Je1NNDnNVvigy9dhL327TpwvthDAt0LdUE/t76v 00vhhz884PNW47TlEE0sGkz8TcKCOSTG5DnqiQ1GLeEKIhTAT34hteNxLcKYZReXcvi7 rSohbMe0rTxg5J1pLYmtuQDdSYSlfojjkgo= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kvn0rrmfq-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 15 Aug 2018 09:55:38 -0700 Received: from NAM05-BY2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.17) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 15 Aug 2018 09:55:27 -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=63L+FYLZ5r2I5JwDiCG5/mGiMnlwAR7/rObgQjydjAQ=; b=dbhY7K+7QjcuzNR2jkPNh9Obi1BI91sLI08DdPZYxsnlFTFazefWR+RkK2OTw1ayVh56wTrBC+8m+rAHlExTzH1lbJoqMlESbh8KlOCj+CQ9rffE3/hxFJZv4oqFhuhRRPHIiy1SNFJV8+s9PXBwEd3OpY7s+MWqC/i+ppvV+xM= Received: from castle.DHCP.thefacebook.com (2620:10d:c090:200::5:abf7) 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.1038.21; Wed, 15 Aug 2018 16:55:23 +0000 Date: Wed, 15 Aug 2018 09:55:17 -0700 From: Roman Gushchin To: Johannes Weiner CC: , , , Michal Hocko , Andy Lutomirski , Konstantin Khlebnikov , Tejun Heo Subject: Re: [RFC PATCH 1/2] mm: rework memcg kernel stack accounting Message-ID: <20180815165513.GA26330@castle.DHCP.thefacebook.com> References: <20180815003620.15678-1-guro@fb.com> <20180815163923.GA28953@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180815163923.GA28953@cmpxchg.org> User-Agent: Mutt/1.9.2 (2017-12-15) X-Originating-IP: [2620:10d:c090:200::5:abf7] X-ClientProxiedBy: MWHPR2201CA0033.namprd22.prod.outlook.com (2603:10b6:301:28::46) To BLUPR15MB0161.namprd15.prod.outlook.com (2a01:111:e400:5248::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22c8e998-1e58-4978-c16d-08d602cfe4f3 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:BLUPR15MB0161; X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0161;3:N/pubUeskhz+vF7GstNHBOXBNvKQ/T8EnmpgD4d4J/dFqckKjdwJYaP2YBAH1D0gg0J+8OHbG/pzyKVDBrPQqC3q7Raj1s44S9aAwkCHqNLxY1gsiplq+BEGYFIkjTzvXJydv6rz5GGZu/2yvZpxTdWA1ciYB4h8sAtmRNx88ziRATNGEQcvPxKZpr7fPd5BEaUMJWWReKcGcfe3FtldqX+LcUuHLy5xKnJdCBwJkYlwb08gTaZZqg1cC6QKvL8i;25:NA+M8zZ/5GGZbidqK385C4yCMWZBKTvgIposhmg/oUFu5y3O2TCBuwUKnpvD5QjQZFRlM9zqYa2UF+RvhAk8tfKV6JS1DWxFD5oJHsYGzlLkA+8HJ8e2b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qC3wj5p+mEItv8EuFpBcG+yemBTfFmJU7FIo8875mFTvBTLlOiYSrBI6lYM1Y7n8qw+W/8Vs4744JgNW++H6KvalJfoYuz3AYMFVELZ7W3j7l5QsQi6XC9Y8u2wuqbrWvbexaNOSgiuyoT87WiWiFOrPV6+O7PFxI3rGdPc2oBoeCLaeR/EBXYXVFiCWC1Om6cPiEXilQh9em75xFDN7ERvxDz8vmGFCVR4pKSLaW6X6MKAqoZkJO1BnOQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231311)(11241501184)(944501410)(52105095)(93006095)(93001095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011)(7699016);SRVR:BLUPR15MB0161;BCL:0;PCL:0;RULEID:;SRVR:BLUPR15MB0161; X-Forefront-PRVS: 07658B8EA3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(136003)(366004)(346002)(376002)(39860400002)(396003)(199004)(189003)(6116002)(52116002)(86362001)(8676002)(81166006)(81156014)(316002)(8936002)(9686003)(25786009)(478600001)(6506007)(7696005)(386003)(486006)(52396003)(50466002)(46003)(229853002)(1076002)(97736004)(15650500001)(68736007)(76176011)(14444005)(58126008)(446003)(305945005)(2906002)(105586002)(55016002)(6666003)(11346002)(106356001)(7736002)(23726003)(16586007)(54906003)(6916009)(53936002)(217873002)(39060400002)(4326008)(47776003)(33656002)(5660300001)(476003)(186003)(6246003)(16526019)(18370500001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR15MB0161;H:castle.DHCP.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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?m2Rt8E8dILStk/jojEyVNQr9478ztiCc4VWCOgBmYXFlgXqLeZxXZshBGbn2?= =?us-ascii?Q?V5MsY0/tlyi3nsQv3B0p2M2p2Z38mh1bK/KOnku4vJ1+7nI8siECh0YoOj2S?= =?us-ascii?Q?ucNpxcD45vvV1Sne/0uQoF4vKMy8FPNZT0a+nfceKVf9I5T3YjlXro6arT57?= =?us-ascii?Q?bsVCzu2NTI+H2TW5eza5vVObxZwXMxXIDx9Qd/cNLc4zoBkyvPvqvxgcSh6p?= =?us-ascii?Q?NvYX4lK8p6J5CeCIVVSwi1yx9PEv7UPsxOnLcNwwFWkFEuwsVmP/KgviBYXt?= =?us-ascii?Q?htvVLl2bdv0hHs6GQxPzAj+NGYIVqc622VJDv+X9055DnuENAWgC2g5VzrK1?= =?us-ascii?Q?+8xfseXf/ket0u+pkdViIf3bjgsBG5ZqLCfgsO4eWOlBO7+t1X2k8H9+Jja+?= =?us-ascii?Q?+36oMcF2E1MRryLXibJ6M37nrCO9ibx9t9JUv34J4BQ5AC4mLhES8XnTFZjU?= =?us-ascii?Q?M+vrsHJU+Kf+rOviBQx5yBxGmt5nqbXET8BvnyvCj/q?= X-Microsoft-Antispam-Message-Info: bR3MbMA0krcYwBM8elmeMq7WXBjCtNbaDgf0WnyAE/6iZZYJy8qqfG6rArauiQE6zrZ0VWlBug6FrtBGX0i2lZkdzBTzD+oSCx52Xei2usZkEhzTh2H8fKiDoTuX0OWbguMOBV7B3jkqDqQPe3AIgHRLS+V5pEdr+SBRMZcIkNsBwjYo05HZyqWk+D8QR1cRD0Gye37znlbmm9Qe57mJnzb9HztVWaxS+cEuMzKwjaHuHqOrDlcpQS1NmR7xto1j0WkfVLmDopZa76AQNWeUEBxYbrPQH0zHOgEa22DkzqS9JIwTK2NPLEJMhxf60D7s9qqe+V9saQrW02/2zAQcNUrr3d4xnEiMt3XVUBhXXro= X-Microsoft-Exchange-Diagnostics: 1;BLUPR15MB0161;6:ih292WXSueys1AoYpgv5upcKAJ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400Pox8WAp0uMhoWlrmBNOZJegqqF+xGZ1dMf1bXMdQiPQotEcMBWLeWhQ6r/u8O4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2018 16:55:23.1660 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22c8e998-1e58-4978-c16d-08d602cfe4f3 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-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 Wed, Aug 15, 2018 at 12:39:23PM -0400, Johannes Weiner wrote: > On Tue, Aug 14, 2018 at 05:36:19PM -0700, Roman Gushchin wrote: > > @@ -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 > > +} > > Before this change, the memory limit can fail the fork, but afterwards > fork() can grow memory consumption unimpeded by the cgroup settings. > > Can we continue to use try_charge() here and fail the fork? We can, but I'm not convinced we should. Kernel stack is relatively small, and it's already allocated at this point. So IMO exceeding the memcg limit for 1-2 pages isn't worse than adding complexity and handle this case (e.g. uncharge partially charged stack). Do you have an example, when it does matter?