Received: by 10.223.164.202 with SMTP id h10csp1199467wrb; Fri, 17 Nov 2017 16:02:53 -0800 (PST) X-Google-Smtp-Source: AGs4zMaaJ1+EC/XEZu0DL29x4Z9ZqjU6AuOfoelzUc7Xa1SC5ZroMP3hD86RaervwfAjSW5Es91O X-Received: by 10.84.130.41 with SMTP id 38mr6783280plc.387.1510963372922; Fri, 17 Nov 2017 16:02:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510963372; cv=none; d=google.com; s=arc-20160816; b=wOuNI5kpVTNFMpcyZ7dAbN3VBV9X9K1fP0s4mx4MdBnEdBQha3lbMAry7bBhXgBYyc V9s2q6t5Zo2caMAyRfD6NMKOP3TLZMCMu82aqKoVu2qabgr/owCiwu+v9RXwKRY+Sz8r /T/MBaeKYsKPpA8eOKdEV+tSKDM9A08IhI+nkCC06zAkqjJsLj5yTH7fmwqrn833FI0l nqotS047zqh/GmKUPL1PBXmOq8e7g3Ix93/HJIk0JL72Iv5QCf83DxtE5jJqkufVHwyB /BidGLRNzHBJWb9aBRinPjnS1N1W+qf5q4NDMVeIvT6oBO4wt+qOWP1RtSbAVwTY+kPa 1HVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=agX1LT3B9veP+cDVBbntjcJ5bsveLW8uUgJelrf9UiA=; b=hS/mFUWQzgpUH3eS7OPbAXWwo0dPfqoohaFjtKWEAMrZmKC+QlxVfDk8CXkw4oIypp AwthgiruqYUOvID1baQAUqSBEorT3qQP2f8OVEg+HFTmcTcXtKleN0RpML6yX8hH5ezV 8j6qLIpjKeIgBdKgIl1i7qMoJDSmt43R/kQc0716VMpSmrfiV3rrbB0w6XwCTV7UN9FU V23vNU+v8HGUZNaQ+FLDXXYpXVp+DawV+XeUPa7mhImpqaFhUTjai1E4GUPTJujfPh/Q m/StuPXhhgAbQ2SD+D6YqR4nwVdzd1ceHFurV8RPJCQ7tVmelgwxkybEt+Qri6Fc0I9Y IQAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HP+k0dxM; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si3481962pgf.713.2017.11.17.16.02.39; Fri, 17 Nov 2017 16:02:52 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=HP+k0dxM; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161061AbdKQRll (ORCPT + 93 others); Fri, 17 Nov 2017 12:41:41 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:40088 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752831AbdKQRlc (ORCPT ); Fri, 17 Nov 2017 12:41:32 -0500 Received: by mail-io0-f194.google.com with SMTP id 71so9521318ior.7; Fri, 17 Nov 2017 09:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=agX1LT3B9veP+cDVBbntjcJ5bsveLW8uUgJelrf9UiA=; b=HP+k0dxMyRQ70e9QkrJfDCuxj9+8PviHWwmG7EeGsjEG6Pl4yrCMrYOjkOB6FNWL8/ 6Bm8EQnnvg79fPSbT3h05ov3B1MPhzsAqv23+XB3M5vxTCO4PN1Pv5OJU+D75RvTzkvO B0a8rKdcrANzl+HxU+rZxek8EsB64Jq/A9TxXVUcH+ne8bNIaC1MoFsy7Z8RJEMuyXTl u4B31edWGKwRPuEje5Gx57SLrV85z/5vylbtA2eIgWZV9IdimA6MADCUV+tEboZnBxK3 o0KFFycaaUaJ0qgdxrfU9ZrRIc5sJ20XL/TDA+bldEHWfoOLPs69aKQAUabKvvoclDeB Z6Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=agX1LT3B9veP+cDVBbntjcJ5bsveLW8uUgJelrf9UiA=; b=DUyqCMpD6zza2zK9M3TesjGF/dnIvAyl07cPX2bH9zMr3hfzNwqueK4bGPQmbxT1Jx noGMU/68ENjDrZSe/qj4F1SnoU0+FZrcIWctAEZQ1RV+e4dUHbHWKZm1a+ZbURM4T/K/ rJ9aWDl/6jywSJ+kGw8bD0/FovPwxmI9ZU8bjSE0hT9j7cc20TYUolwHz3BCNPpuR3WD eW0oAEP4nQNf3NTg49myarpmAtTgso1AH6LG+BY7R/9iW76xe2ATxWbDA6hTaccfmgnf 8XSt31tTni7tTV5H7KfV/cp542QDl1J2mH6vdZEK4rsdcLefDV+cxZlByZ7j0Obu5/Ko hYXQ== X-Gm-Message-State: AJaThX62yFpKXnxwwQEaCAQRl9yzuq5LdFLIKuSaPknsEzzkQsc25xPw DcyUiesTT7EsTvi4pdbhXaT/vG2KNvRO69NcxhQ= X-Received: by 10.107.38.2 with SMTP id m2mr3650288iom.272.1510940491985; Fri, 17 Nov 2017 09:41:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.160.73 with HTTP; Fri, 17 Nov 2017 09:41:31 -0800 (PST) In-Reply-To: References: <1510888199-5886-1-git-send-email-laoar.shao@gmail.com> <20171117155509.GA920@castle> <20171117164531.GA23745@castle> From: Yafang Shao Date: Sat, 18 Nov 2017 01:41:31 +0800 Message-ID: Subject: Re: [PATCH] mm/shmem: set default tmpfs size according to memcg limit To: Shakeel Butt Cc: Roman Gushchin , Andrew Morton , Johannes Weiner , Vladimir Davydov , Michal Hocko , Tejun Heo , khlebnikov@yandex-team.ru, mka@chromium.org, Hugh Dickins , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-18 1:35 GMT+08:00 Shakeel Butt : > On Fri, Nov 17, 2017 at 9:09 AM, Yafang Shao wrote: >> 2017-11-18 0:45 GMT+08:00 Roman Gushchin : >>> On Sat, Nov 18, 2017 at 12:20:40AM +0800, Yafang Shao wrote: >>>> 2017-11-17 23:55 GMT+08:00 Roman Gushchin : >>>> > On Thu, Nov 16, 2017 at 08:43:17PM -0800, Shakeel Butt wrote: >>>> >> On Thu, Nov 16, 2017 at 7:09 PM, Yafang Shao wrote: >>>> >> > Currently the default tmpfs size is totalram_pages / 2 if mount tmpfs >>>> >> > without "-o size=XXX". >>>> >> > When we mount tmpfs in a container(i.e. docker), it is also >>>> >> > totalram_pages / 2 regardless of the memory limit on this container. >>>> >> > That may easily cause OOM if tmpfs occupied too much memory when swap is >>>> >> > off. >>>> >> > So when we mount tmpfs in a memcg, the default size should be limited by >>>> >> > the memcg memory.limit. >>>> >> > >>>> >> >>>> >> The pages of the tmpfs files are charged to the memcg of allocators >>>> >> which can be in memcg different from the memcg in which the mount >>>> >> operation happened. So, tying the size of a tmpfs mount where it was >>>> >> mounted does not make much sense. >>>> > >>>> > Also, memory limit is adjustable, >>>> >>>> Yes. But that's irrelevant. >>>> >>>> > and using a particular limit value >>>> > at a moment of tmpfs mounting doesn't provide any warranties further. >>>> > >>>> >>>> I can not agree. >>>> The default size of tmpfs is totalram / 2, the reason we do this is to >>>> provide any warranties further IMHO. >>>> >>>> > Is there a reason why the userspace app which is mounting tmpfs can't >>>> > set the size based on memory.limit? >>>> >>>> That's because of misuse. >>>> The application should set size with "-o size=" when mount tmpfs, but >>>> not all applications do this. >>>> As we can't guarantee that all applications will do this, we should >>>> give them a proper default value. >>> >>> The value you're suggesting is proper only if an app which is mounting >>> tmpfs resides in the same memcg >> >> Yes. >> But maybe that's mostly used today? >> >>> and the memory limit will not be adjusted >>> significantly later. >> >> There's a similar issue for physical memory adjusted by memory hotplug. >> So what will happen if the physical memory adjusted significantly later ? >> >>> Otherwise you can end up with a default value, which >>> is worse than totalram/2, for instance, if tmpfs is mounted by some helper, >>> which is located in a separate and very limited memcg. >> >> That may happen. >> Maybe we could improve the solution to handle this issue ? >> >> > > Let's backtrack, what is the actual concern? If a user/process inside > a memcg is allocating pages for a file on a tmpfs mounted without size > parameter, you want the OS to return ENOSPC (if allocation is done by > write syscall) earlier to not cause the user/process's memcg to OOM. > Is that right? > Right. > First, there is no guarantee to not cause OOM by restricting tmpfs to > half the size of memcg limit due to the presence of other memory > charged to that memcg. The memcg can OOM even before the tmpfs hits > its size. > Just guarantee that the OOM not caused by misuse of tmpfs. > Second, the users who really care to avoid such scenario should just > set the size parameter of tmpfs. Of couse that is the best way. But we can not ensue all applications will do it. That's why I introduce a proper defalut value for them. Thanks Yafang From 1584358149324446308@xxx Fri Nov 17 23:34:34 +0000 2017 X-GM-THRID: 1584307723039976913 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread