From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAE91C35670 for ; Mon, 24 Feb 2020 01:11:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4F41420836 for ; Mon, 24 Feb 2020 01:11:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kvTvYofZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F41420836 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 949126B0005; Sun, 23 Feb 2020 20:11:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F8A76B0006; Sun, 23 Feb 2020 20:11:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80D836B0007; Sun, 23 Feb 2020 20:11:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 68E9B6B0005 for ; Sun, 23 Feb 2020 20:11:46 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 364B333C4 for ; Mon, 24 Feb 2020 01:11:46 +0000 (UTC) X-FDA: 76523243412.07.hook62_66b3e58b7f517 X-HE-Tag: hook62_66b3e58b7f517 X-Filterd-Recvd-Size: 5670 Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 24 Feb 2020 01:11:45 +0000 (UTC) Received: by mail-oi1-f196.google.com with SMTP id 18so4494006oij.6 for ; Sun, 23 Feb 2020 17:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=HX1fJHLiNwnVKz7r+onFwX/niXbmKqUAA8UMhmaKQVk=; b=kvTvYofZbz9U3B5NUoEdMRddWJRK/T6OWfWosieMYrRCRmBG6eds6cFCmkYooinSxb 8VPn/Y70cjNOolZdgXXxZbXrOgCEDWU+L7iglCMwW+DF/5BFvXKY0G0dPLuQ4lQmY5WP JNK5G2q80TrH67xVPlf3bovornkAJZFsIRARlH+qEnAVUsgB1s6isDKWXfcJA0FwjoBY nRdSBFeW6FTnlcgIbbxsM8b/CY2eBs+XAdfipDCubdL5u0kKxae5lEJ6Fy2NEr7PkG2O ATHNhSb++IjMLmUksnNBie+sd/AN3rJrbjO2Xqcd8JLvVZlsIYm7dt+uer/M20dGt1FP 48pA== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=HX1fJHLiNwnVKz7r+onFwX/niXbmKqUAA8UMhmaKQVk=; b=gHYa4lBnFml5mZv7gUy/p6OVVMCclHZemomjdfXZAkBRQ5ZwxMh0Y/YA4guVdagADT ox4wVMIvdlOoXZ+t8MbVd0miDRI39PBgkgZesSJy8UyDtzMyz7/zLl2anBiwCXFCdtfZ pbd0CtbFFkl2ba4cyJ0RCYe3DJw3ioGwGsSdHbNxb2pGrIYzdTHg3J3iuouXCq9qQq0N +ZE0lP/zi5fokJLn9jP/IcaVlmFJvydRUcmFwkIDEO9XZWZVc/NHQEUI+IP2tDUl9/26 aOrbcNZuiFCdBjm8YgYj9kBMORVMJGZ286195yLyyWGEAx3GNk5uS1ngK5kPMGm3azNe Jqfg== X-Gm-Message-State: APjAAAWp2GgckPU1yOp1KpQxz4bPQDpKa1pSUc/r77+MmdBsLH3n74vk CGSfS7p6naNXjpUBTbyFy+/5Rg== X-Google-Smtp-Source: APXvYqxhhn1kZfC9aGeOzvgd6UOP1g9Z1kN2EROT2rl+Hr6et8C1VoRjmDndu2vyAIreE4N4uciOPg== X-Received: by 2002:a05:6808:84:: with SMTP id s4mr10963771oic.147.1582506704543; Sun, 23 Feb 2020 17:11:44 -0800 (PST) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id j5sm3881050otl.71.2020.02.23.17.11.42 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Feb 2020 17:11:43 -0800 (PST) Date: Sun, 23 Feb 2020 17:11:12 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Dan Schatzberg cc: Hugh Dickins , 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 In-Reply-To: Message-ID: References: <0a27b6fcbd1f7af104d7f4cf0adc6a31e0e7dd19.1582216294.git.schatzberg.dan@gmail.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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