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=-15.8 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 DDBFBC35666 for ; Sun, 23 Feb 2020 19:09:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6B4A2206ED for ; Sun, 23 Feb 2020 19:09:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JSZ7Tv7F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B4A2206ED 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 B6B1E6B0003; Sun, 23 Feb 2020 14:09:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B1C916B0006; Sun, 23 Feb 2020 14:09:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E2726B0007; Sun, 23 Feb 2020 14:09:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id 8313B6B0003 for ; Sun, 23 Feb 2020 14:09:19 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 391FA1264 for ; Sun, 23 Feb 2020 19:09:19 +0000 (UTC) X-FDA: 76522330038.15.neck50_8b831c7c1671c X-HE-Tag: neck50_8b831c7c1671c X-Filterd-Recvd-Size: 6861 Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Sun, 23 Feb 2020 19:09:18 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id i6so6774218otr.7 for ; Sun, 23 Feb 2020 11:09:18 -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=htLN1mwGdJtRnyqYUCPJp+OPGglRrhjiWXYVtDt/NKM=; b=JSZ7Tv7F6nQ3YH2jP3HFLdPAhZhy2Y/RM9Au69XuF7TR0GzciTC0aj+0Tv4uRV+9XJ S4Wu6jcRiaRdgV38hOL3giTmwn97IzhRnjQRKVCoYK+wbKxwIa24ektK26DJ43CkLtwN ZT9IiL8y9//RQ99zTTNcqBJXNSogX2r+AwY/uH8cqaruxnp5gzlWpx+9El5byimG0jnA gwXKIGTFa3/cNEDFtAyjXJOHNCZOiszkR89nBIjCVQRfXSF+Sr/HRB0GuxP8BmqtZijN wiRvUQvVfqVjVfedH3LtBOG9DpYU+DUoB1Db0YG0GDCRe4xQFuaaRpiYbX5PICYUsE9L PPqw== 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=htLN1mwGdJtRnyqYUCPJp+OPGglRrhjiWXYVtDt/NKM=; b=j6+Ot8GnxK49AE/I9EogVuJNp5powIcVDfcgBKnaPAWcT5uXlnScqZwXyBmHYP9qBV FjMTdqv+oF1unHaJ2XDNh4nXzb4QPO6QoTfs08XJcJVvm1TDQ4KE+eqwoPVfYq/egi2d eu4T9VszhSzIl1UrKM8dooikjAv2qR7WMrtKhxOW3gzHmKPj/TKz6BwJJKwDYEXjoIyV +gu17K5vSQqK6QwWUZ1CZTuKcmreslki5xpduTwPBZWgCuyCPgU6CfIhADtcWxhJp47z wEUWWlSCbHlCAec3EWMkba22S8zFmWqYtPhu4UrfxLLEKu14eFbtPS0RPhAPgevlBEqW NIdQ== X-Gm-Message-State: APjAAAW3QRw4j3UtaC4VJtptNUgNJAfl42Uz6NnAAIa5IMFJGo0e0UT3 N5o59XYjX9zZ1/HxQKB2KQTQ8w== X-Google-Smtp-Source: APXvYqy/p/O4TAQu54lEWny6r9jlQDTbURDNigwuqgFSiLk69KhcFalHKOOJrks6IaVeMj9w1BHaEg== X-Received: by 2002:a9d:5786:: with SMTP id q6mr36062007oth.164.1582484957514; Sun, 23 Feb 2020 11:09:17 -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 i6sm3575702oto.62.2020.02.23.11.09.15 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Feb 2020 11:09:16 -0800 (PST) Date: Sun, 23 Feb 2020 11:08:56 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Dan Schatzberg cc: Jens Axboe , Tejun Heo , Li Zefan , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Hugh Dickins , 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: <0a27b6fcbd1f7af104d7f4cf0adc6a31e0e7dd19.1582216294.git.schatzberg.dan@gmail.com> 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 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. > --- > mm/memcontrol.c | 11 ++++++++--- > mm/shmem.c | 2 +- > 2 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 6f6dc8712e39..b174aff4f069 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -6317,7 +6317,8 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, > * @compound: charge the page as compound or small page > * > * Try to charge @page to the memcg that @mm belongs to, reclaiming > - * pages according to @gfp_mask if necessary. > + * pages according to @gfp_mask if necessary. If @mm is NULL, try to > + * charge to the active memcg. > * > * Returns 0 on success, with *@memcgp pointing to the charged memcg. > * Otherwise, an error code is returned. > @@ -6361,8 +6362,12 @@ int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, > } > } > > - if (!memcg) > - memcg = get_mem_cgroup_from_mm(mm); > + if (!memcg) { > + if (!mm) > + memcg = get_mem_cgroup_from_current(); > + else > + memcg = get_mem_cgroup_from_mm(mm); > + } > > ret = try_charge(memcg, gfp_mask, nr_pages); > > diff --git a/mm/shmem.c b/mm/shmem.c > index c8f7540ef048..7c7f5acf89d6 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1766,7 +1766,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, > } > > sbinfo = SHMEM_SB(inode->i_sb); > - charge_mm = vma ? vma->vm_mm : current->mm; > + charge_mm = vma ? vma->vm_mm : NULL; > > page = find_lock_entry(mapping, index); > if (xa_is_value(page)) { > -- > 2.17.1