Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1003027imm; Wed, 15 Aug 2018 09:42:25 -0700 (PDT) X-Google-Smtp-Source: AA+uWPylkAOoTS15OuhYPBgiK6l8ORJQdQlFevciucZ9aY4gvgf9KJftgnvfCMtC/Jv8eOtByCHp X-Received: by 2002:a62:768f:: with SMTP id r137-v6mr28672396pfc.250.1534351345348; Wed, 15 Aug 2018 09:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534351345; cv=none; d=google.com; s=arc-20160816; b=pTR6T6F5d7kbxJ2+KtGw2GH+Sjs4ADvEbnjqE6kmK2H0KM/c/Nml2DMbGttwOx0GxM DJZU0LbbQ4QifnuVvpI7aOZz+HWOz8BTZEtUtPtrcJphOeuksNw5p+vyeG2lg98JPf3e 1eeTIaX8zxCMdSXeYjv8RQib7ENTvLEEiHqSTBt6jRKhBs/YAnc1hWc7vEqjVsg3JRb2 JeiOICm6loO6zvhReVdIXXXwJ+WiOJw3vPYShachYcGK5wg9iSzjorKyUxLQIAUY8+7Z DWMyWlisK76G1jfgFxxubKAmdibI0uRfEBzpOJ2AsYmBvNrrm/jAKFA+KHjgYbUi/Yur mG7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=vw8oH0yPD0vgtmJLJkDjGwEryVYk6Pm/sYpfzldQLmQ=; b=f6EPdHg6VrfVOEgEh4OtRc9hoW2CVRWSi4yrFtfpMjOoh1h7H0Tv6k8eYdvXJtpQ/N zRfXP8FL5dSXQtY7IOmxgf38D81mSn9ORg1YVfk0iJfBkpEYFepjiIMAwfXvUt/aRYCq iK/dB4hZl5k/e89VshhRNe+pROTOhE300IoWQ8B74KUG0iUKX19AM/2GTIg44C5T8Vph 7OhEl8oHWnJUkkglojkwXIbACOUZiFS1e7BNeeqzXPfm1qrRG/VjD58OQqrG09rDhALr rexJwKp81hcBsNq9OEM7mN+tSO8R+Gd/Z+wwvU2+k9LVC7/+PGGuzYWyRcN5lQ5RM4YZ 3Svw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=BY7FZLhh; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6-v6si20195284pgq.240.2018.08.15.09.42.10; Wed, 15 Aug 2018 09:42:25 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=BY7FZLhh; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730208AbeHOTcT (ORCPT + 99 others); Wed, 15 Aug 2018 15:32:19 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:33648 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729464AbeHOTcT (ORCPT ); Wed, 15 Aug 2018 15:32:19 -0400 Received: by mail-yw1-f66.google.com with SMTP id c135-v6so1278896ywa.0 for ; Wed, 15 Aug 2018 09:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=vw8oH0yPD0vgtmJLJkDjGwEryVYk6Pm/sYpfzldQLmQ=; b=BY7FZLhhwpiX7FgXINIZJAnAeHNZ1Jvj7o0ZqOi2ubKr1gKayM6Xym5wskmZCAhPgf iPKRCsEmwvk7RM8eDFKIokRam+j1IwmUEHS9G81yHmWkg56hAz9rVPDsUEneQZDFkh0W 0gaDuzDM7/5OnMcXnlNaCEy1tqjMWxiM88ecM5vgutNFY7JqN3zgfoZPW0eqhlLUT5Qh PyaWaTgIOOcBSYkAvy4xXoBVNIx3pn7ZQBzyWvEwA2WHPxTW1Bei8Og247fHnPPi/2Qb MU1UFhgPw63XzqmhyJxjJPYlqdGm7fGjXBGDcyLZK07qDvMV92C7roR9Pw/hbs7VT+AZ MJ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=vw8oH0yPD0vgtmJLJkDjGwEryVYk6Pm/sYpfzldQLmQ=; b=rdsP9+o66q//nJkcaAMpdhSC98zC8EmuYv7sdM9jgt0Pba6lA9v8Ybfe7PF8ourJ+N f1d5r5Zr2zB0kvnNumyBiBBufckUsPhfYchFeRSCriOL+JD8yEtxg+3Uopno1MFQbVRd hhKfNo0KLLXs1rbpQvyxZAwnZxwPUENiyDgz1whuX7gDJO9wPz+O9qAblq63cNSe7r63 ZHxEn0Z6KLikB1rJxdqYW9gK97gj1bD6XyA8HagRQjpUADvBk0KkEI6kHaQkeGnVBYAz zvzHDYLa4xF7fglxe1YakeTpO73FqUaRoSvyahpLzNnYEthP+J9nVJKM7exlxSMB9ItW C1rw== X-Gm-Message-State: AOUpUlHsHMkU2vHeh8N2xfLrPu+GQ5F7t1gch+o0WNyDGktIIKp3u4GM j+xcSo5Jp3A3k7yVDsM/XO6FnQ== X-Received: by 2002:a25:addf:: with SMTP id d31-v6mr197706ybe.98.1534351166352; Wed, 15 Aug 2018 09:39:26 -0700 (PDT) Received: from localhost ([2620:10d:c091:200::9380]) by smtp.gmail.com with ESMTPSA id h65-v6sm9836056ywe.75.2018.08.15.09.39.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Aug 2018 09:39:25 -0700 (PDT) Date: Wed, 15 Aug 2018 12:39:23 -0400 From: Johannes Weiner To: Roman Gushchin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Michal Hocko , Andy Lutomirski , Konstantin Khlebnikov , Tejun Heo Subject: Re: [RFC PATCH 1/2] mm: rework memcg kernel stack accounting Message-ID: <20180815163923.GA28953@cmpxchg.org> References: <20180815003620.15678-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180815003620.15678-1-guro@fb.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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 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?