Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2884938ybv; Mon, 24 Feb 2020 13:39:18 -0800 (PST) X-Google-Smtp-Source: APXvYqz1DRvdX2MH6eZvlO0c5QSCXuPPX7HBJ5FtzcsJHzoHT2O2Mp18jUYcur4J96NNrkO/5soY X-Received: by 2002:a9d:7a96:: with SMTP id l22mr41453329otn.217.1582580358250; Mon, 24 Feb 2020 13:39:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582580358; cv=none; d=google.com; s=arc-20160816; b=1KO+CBSyHQC/c7oyhtTnwzIrj3tyaBgQI4hPgr5e8hyW4CMKfm7F7NItC2Wd+Rwj/m S+r0orz8F8TfFgeL6Ev+eHopDGaoNMr8u7Mb9z8RDK6tAvaC0tKkDbXTHSxb0V0rfo/N T27h9AUAr9sE9otvPt8smgFvpoCCkQA3gpzNsWlguApquXfNpglC+gPcr0QD3wOr+aaE G/lkoeT3mlzOzD1e81JCvhppzYoKXGgvTwXpjXWaTuKeN8HKgrJ9Yigo1nCf580F/z5Y wg8yrlhzknNG1Tsr6cMCL64nPhKr0rLaeUebwgStObtIz5WujDjGUX8VtLJs9Wtll/if 3Tvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=/oLy8oVuts+NDR86rWT12f1DfuTi/T+KFkIcevjcIVk=; b=AHHtCAj0LIMLtQzYHKExVKScqS0Sv9tFEjSW31VcjutLxVFVxAN7eRSRBsjkNmC0cp wxG30+CcwAETuhomxrCVYBm65/DfkDmkxtmtxuTiXn3OiYOx5vraFtAuH0tywaeTvkZs bQ4wsm1b+cOs6OkFVwi114Qr/7vPPycecDkojJXvWyryP4BV7qqPZDkpcoMg94NLJQkc /GsOnwT5c36dgErV5OZJYasD3/PdFIE4qYgzD5oNcoF1j2/mWQMwxVQKLZoM0c6Ho8l3 zzdE/LgvlfOBJKrghDgXK2uC++Km5oCfZfTpx76ZiRuX+dZGMW1jdcSxCO/uPjJRD++6 BssQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="G/dqJBKU"; 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=QUARANTINE 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 d26si6374633otc.6.2020.02.24.13.39.05; Mon, 24 Feb 2020 13:39:18 -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="G/dqJBKU"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727998AbgBXVhy (ORCPT + 99 others); Mon, 24 Feb 2020 16:37:54 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:37254 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726980AbgBXVhy (ORCPT ); Mon, 24 Feb 2020 16:37:54 -0500 Received: by mail-qt1-f196.google.com with SMTP id w47so7630020qtk.4; Mon, 24 Feb 2020 13:37:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/oLy8oVuts+NDR86rWT12f1DfuTi/T+KFkIcevjcIVk=; b=G/dqJBKUaChhHiklV5Lw+49KVuJF9AbPOpkfS+2n6Qk8wkhPUVDGGMJD5uvSfRAwOx xzJfG8b8FMlMdMb4KndOLEFwTqa8kpbf1gnvD3wJ7DmQ3+a0myrZMyoZ7gQm/CiO1t8Y AQ2niiTydeDa2Tm4yZZQAzuwao4ut8S7wQoFQU7h30tlwtv05ivIKuBQl9CAbTmUQykG vhhobIrRrVhM0SrntztkE7e08WvFc+q24oNp6mNiqulz617fl7f3YoSmNWXPrsOexSXk /3UsPWtixv84JHg6mkf5BwIRJHok/gkKO/3aAOD4Hc4Tpta4BGbVr3rVA37at/r8be18 XmfA== 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; bh=/oLy8oVuts+NDR86rWT12f1DfuTi/T+KFkIcevjcIVk=; b=n+6QsJu2ObyNHEveuhnu+qYroaJy0gAsJTXbcQsYvc9dVStvuojn0mPEGi1dgX2OoZ /7S9zDtKdYrMAE1QGffFdzgWTEQPqGvhgQaqI/9sabhFQ/VeCF9Ryf4IAp3cd4i/4j4c cVw4jdWwRfUwe1BH/IVBfzZK4639Vdmx0ZxztSDEcoEnEDpjgQHzFLjL81/ywHhrmvCK 6Sw595eXAgAvvLdes0FKvMpuZFnhIgdszjNjHqhDRLVUOoqD6+RW65sYZ3niVktzZmoh wOyMeg6n/Io/V26hBbE3TUojHB12qduptw3MW6LTx37qw6/QTr0fGA/OcTaktSkdGdZC CqyA== X-Gm-Message-State: APjAAAUuxBOFYrrwCsWdtRvVTUzMdFYvLbB6K/Fe3kA9bgmOcQrwewDD cKiYcMuuf3vSTVPYfyJ4TTM= X-Received: by 2002:ac8:5419:: with SMTP id b25mr51215597qtq.390.1582580273055; Mon, 24 Feb 2020 13:37:53 -0800 (PST) Received: from dschatzberg-fedora-PC0Y6AEN.dhcp.thefacebook.com ([2620:10d:c091:500::2:b19b]) by smtp.gmail.com with ESMTPSA id c10sm6404718qkb.4.2020.02.24.13.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 13:37:52 -0800 (PST) Date: Mon, 24 Feb 2020 16:37:50 -0500 From: Dan Schatzberg To: Hugh Dickins Cc: Jens Axboe , Tejun Heo , Li Zefan , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Roman Gushchin , Shakeel Butt , Chris Down , Yang Shi , Thomas Gleixner , "open list:BLOCK LAYER" , open list , "open list:CONTROL GROUP (CGROUP)" , "open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)" Subject: Re: [PATCH v3 2/3] mm: Charge active memcg when no mm is set Message-ID: <20200224213750.GA3773@dschatzberg-fedora-PC0Y6AEN.dhcp.thefacebook.com> References: <0a27b6fcbd1f7af104d7f4cf0adc6a31e0e7dd19.1582216294.git.schatzberg.dan@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 23, 2020 at 05:11:12PM -0800, Hugh Dickins wrote: > On Sun, 23 Feb 2020, Hugh Dickins wrote: > > On Thu, 20 Feb 2020, Dan Schatzberg wrote: > > > > > memalloc_use_memcg() worked for kernel allocations but was silently > > > ignored for user pages. > > > > > > This patch establishes a precedence order for who gets charged: > > > > > > 1. If there is a memcg associated with the page already, that memcg is > > > charged. This happens during swapin. > > > > > > 2. If an explicit mm is passed, mm->memcg is charged. This happens > > > during page faults, which can be triggered in remote VMs (eg gup). > > > > > > 3. Otherwise consult the current process context. If it has configured > > > a current->active_memcg, use that. Otherwise, current->mm->memcg. > > > > > > Previously, if a NULL mm was passed to mem_cgroup_try_charge (case 3) it > > > would always charge the root cgroup. Now it looks up the current > > > active_memcg first (falling back to charging the root cgroup if not > > > set). > > > > > > Signed-off-by: Dan Schatzberg > > > Acked-by: Johannes Weiner > > > Acked-by: Tejun Heo > > > > Acked-by: Hugh Dickins > > > > Yes, internally we have some further not-yet-upstreamed complications > > here (mainly, the "memcg=" mount option for all charges on a tmpfs to > > be charged to that memcg); but what you're doing here does not obstruct > > adding that later, they fit in well with the hierarchy that you (and > > Johannes) mapped out above, and it's really an improvement for shmem > > not to be referring to current there - thanks. > > I acked slightly too soon. There are two other uses of "try_charge" in > mm/shmem.c: we can be confident that the userfaultfd one knows what mm > it's dealing with, but the shmem_swapin_page() instance has a similar > use of current->mm, that you also want to adjust to NULL, don't you? > > Hugh Yes, you're right. I'll change shmem_swapin_page as well