Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1044200ybv; Fri, 7 Feb 2020 13:19:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxyUsOTfSzZ4UkqqkLJz75jjaDF8YpxAqLQQOBFqk/jpj6kSPR+dv+YKe3V3qhOBzOU2OL4 X-Received: by 2002:a9d:6c06:: with SMTP id f6mr1101601otq.318.1581110357755; Fri, 07 Feb 2020 13:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581110357; cv=none; d=google.com; s=arc-20160816; b=npoo1ceAjygLkRG1SnqxCiTP9B3/OUpZUP3YmHQuvIB4LiLncLM1g8iDew4XHeCQOS NrY+Pq1Z46QsqDszD+RNsnQ12+FvB4ObI9P4sV20yqTk21Z8q2n6w68uab7b+uDBUVFg 58j5MmQzdpC67RBsNDtyI8KuCkh9fnojS9DB8EFHX8CMcTMBlZQYuc/swDM1AYbn33k3 r+LaAvlQqhb/5azv3MEc4ulgV8dTzCU+lGXaI/yUj/EDS8xf/qHpobCDwZM8VDUj9fDw 6+QvnT0svZBsZXxv2FtQePEw9aU25++BXfeNHEj1xRJMWumRpeXj3IKf+5eLNkeLVDGt 60Gg== 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=s3/+t3C/iGaUgSEBBn4UBiEXAA3Z2xiPjiTjCVmDGl8=; b=cGlRGuEdTKaS9qrD+uLZAiJG7p59wZxMBQWaA6NivqWsu2a651aHZf/wYQ1SWC4PFQ cbV2fNvpE/6tcyLCyXPXdthl5g7TAgNlgQrXr2Ctp6VsQplZJp+yjQbdTIREfuLGFPzh 5yFHJKfAbD7qGzuNOV7HKK5snImMe9n/2RCIxbIJIvIg8iFNyxYsUNqTNeQKKkfaStUP wT+8ZXFCwE/7nkBI7sFvUEXxW/90voWPIVyjglcx365/POtdQ67pxVt//lya+KlgClEc Zw7X/Mxb9RvdDw9A8j6df2Ep1jhxqwDyp7JuI0ENNy/SJSfZZVG8K7Ea+hTc6jt2uPqK QVBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b="GfoGaC+/"; 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=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11si287452otq.112.2020.02.07.13.19.05; Fri, 07 Feb 2020 13:19:17 -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=@chrisdown.name header.s=google header.b="GfoGaC+/"; 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=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbgBGVSM (ORCPT + 99 others); Fri, 7 Feb 2020 16:18:12 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38961 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbgBGVSL (ORCPT ); Fri, 7 Feb 2020 16:18:11 -0500 Received: by mail-wr1-f65.google.com with SMTP id y11so544335wrt.6 for ; Fri, 07 Feb 2020 13:18:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=s3/+t3C/iGaUgSEBBn4UBiEXAA3Z2xiPjiTjCVmDGl8=; b=GfoGaC+/D2IbhwLnfJa3biAe5iPkr+OuRXLKcIZgOZFgYGtGR/dc32KDVeiUu1TXk0 eWPSWbZikyLpSAEg8CB0va7Ozm1hhXJZLf0Y/bQn/fhxnQL9eZUGeWjN+xq/u9jl7qtc WAnaA0kz6pznkybaVC/dd561pV315aJX4mGaU= 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=s3/+t3C/iGaUgSEBBn4UBiEXAA3Z2xiPjiTjCVmDGl8=; b=ZjVMSlUem8dA2NBBQ6ImhFkeFZKJujUwgcSpVD32fzUTI3G5n8FSntRR3nxBVT7gP9 zh322aWnDiZt8SVEaAI5kX6R5CWPuzv55hmaWSzWesD0nI2/ZUDrbW7OCH0F1QpdfBW/ sT6z6k1uKr4eNVtabVZR1J/9k9m41hZhpMYDMamrXH/MXP3ZHcbewLPGYOW5VfbKOO/0 GM9ol8ztNqktWHYvb0P8gaBsQ/roxIli7pvAKWz+bfbNStGzBHJH9fuLEgQllb6B3gmQ TjB6Ia73HU+Y+Iy8SZ6ECpu2/aPPOsdOw6BTzm64Sfe7n4AyodQR57im0hmC/ynZWeq0 tt+Q== X-Gm-Message-State: APjAAAVNjfGnkWSgbpfOZBQBiMdeuR3SAqet6QuVta/rGvFUL4LTq/h4 4DwG9vVAjX/3W8+SVp+OVharAQ== X-Received: by 2002:adf:e88f:: with SMTP id d15mr912024wrm.186.1581110288231; Fri, 07 Feb 2020 13:18:08 -0800 (PST) Received: from localhost ([2a01:4b00:8432:8a00:63de:dd93:20be:f460]) by smtp.gmail.com with ESMTPSA id c9sm4672886wme.41.2020.02.07.13.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 13:18:07 -0800 (PST) Date: Fri, 7 Feb 2020 21:18:07 +0000 From: Chris Down To: Dan Schatzberg Cc: Jens Axboe , Tejun Heo , Li Zefan , Johannes Weiner , Michal Hocko , Vladimir Davydov , Hugh Dickins , Andrew Morton , Roman Gushchin , Shakeel Butt , Thomas Gleixner , "open list:BLOCK LAYER" , open list , "open list:CONTROL GROUP (CGROUP)" , "open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)" Subject: Re: [PATCH v2 2/3] mm: Charge active memcg when no mm is set Message-ID: <20200207211807.GA138184@chrisdown.name> References: <8e41630b9d1c5d00f92a00f998285fa6003af5eb.1581088326.git.dschatzberg@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <8e41630b9d1c5d00f92a00f998285fa6003af5eb.1581088326.git.dschatzberg@fb.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dan Schatzberg writes: >This is a dependency for 3/3 This can be omitted, since "3" won't mean anything in the change history (and patch series are generally considered as a unit unless there are explicit requests to split them out). >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. > >Signed-off-by: Dan Schatzberg >Acked-by: Johannes Weiner Thanks, this seems reasonable. One (minor and optional) suggestion would be to make the title more clear that this is a change in try_charge/memalloc_use_memcg behaviour overall rather than a charge site, since this wasn't what I expected to find when I saw the patch title :-) I only have one other question about behaviour when there is no active_memcg and mm/memcg in try_charge are NULL below, but assuming that's been checked: Acked-by: Chris Down >--- > 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 f7da3ff135ed..69935d166bdb 100644 >--- a/mm/memcontrol.c >+++ b/mm/memcontrol.c >@@ -6812,7 +6812,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. >@@ -6856,8 +6857,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); >+ } Just to do due diligence, did we double check whether this results in any unintentional shift in accounting for those passing in both mm and memcg as NULL with no current->active_memcg set, since previously we never even tried to consult current->mm and always used root_mem_cgroup in get_mem_cgroup_from_mm? It's entirely possible that this results in exactly the same outcome as before just by different means, but with the number of try_charge callsites I'm not totally certain of that. > > ret = try_charge(memcg, gfp_mask, nr_pages, false); > >diff --git a/mm/shmem.c b/mm/shmem.c >index ca74ede9e40b..70aabd9aba1a 100644 >--- a/mm/shmem.c >+++ b/mm/shmem.c >@@ -1748,7 +1748,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 >