Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1102797ybv; Thu, 20 Feb 2020 13:15:47 -0800 (PST) X-Google-Smtp-Source: APXvYqyKRW435pWSrHCF7hF+0uFtXy5IrBnyBN9b4F7Ow1Qdr4WSdIq73Gcln0Rs+AYlsuS5kBNx X-Received: by 2002:a9d:bb8:: with SMTP id 53mr22873382oth.150.1582233346953; Thu, 20 Feb 2020 13:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582233346; cv=none; d=google.com; s=arc-20160816; b=p6KtkS9Hwj1Wvqtf30lOgIfI9nSjordcNgDewQYo7PAfDW4sTl83X87R2TkltwYyKA dcLPwBGt8tWxoTVgWItKSRJbD+ZE7VF9nwI3av+FKLFY63sfJab7qilY/myN5JSAMFmA 0UZrT9EZZquMVWH2zoaB5+uEVeHc7wVHM5hOGMKzh/JRJsnh6iDo3621qBSiM6spsRk8 QgBKBKS383fzv8nE3d3q0hwom5zfclYzRk8CxRxvli/f/kxVvOmRq9/uylkHD3//kt7J wLknN3esjCl+CaCGKmoBehb7x8wI7d2DnLRHv7DAChlakv9nlSkGAuCfR7KiMIG9YMYo FQzg== 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 :in-reply-to:references:mime-version:dkim-signature; bh=ktuN17gmiqlKE/I4GYw0sVSSXcxY6RgmY2JpLivgLB4=; b=yRpphS4cABOIWEfmtrULgAy31uDMzqjJ2eqs56fthiE75DI2cvH1uDP0iHRThwgfpD ven9AXzZXK8EfyzyYiwRKaP2bm20MvhwZ8sBgqUjbC1SZphQ+H2MV/EyfWXT2N6JyZ0r 9ygpswFuAWs3gkwaOGu5HRaNPlLNZ9e1QVbtxOmBwWWsC4qLTA57bfZyqKiwKYl3a6hw J8CLEDPmUj+9f6PpcJb2cZpKLNNrPt1PJsOcVckdibk40HhjET3Z3lsVEahyJPDY8z6s FvV+Eo4180G6v6Zmhm7uP/99FOM+roHn+DhJDvCBmBH6WVPv2HNWT2Q6UJQdN00C3+1P hbNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F18pix32; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n186si242099oig.191.2020.02.20.13.15.34; Thu, 20 Feb 2020 13:15:46 -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=@google.com header.s=20161025 header.b=F18pix32; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728993AbgBTVOa (ORCPT + 99 others); Thu, 20 Feb 2020 16:14:30 -0500 Received: from mail-vs1-f66.google.com ([209.85.217.66]:35822 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727561AbgBTVOa (ORCPT ); Thu, 20 Feb 2020 16:14:30 -0500 Received: by mail-vs1-f66.google.com with SMTP id x123so3650847vsc.2 for ; Thu, 20 Feb 2020 13:14:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ktuN17gmiqlKE/I4GYw0sVSSXcxY6RgmY2JpLivgLB4=; b=F18pix32o4K9RJdf3Ge/L+3NgYmCrMt8y8HZvV7+XlYsyAkPvClxTvbluEB0EVBNoS 9+5z76T7v66vZmEXr5Fa4C/xKMwaD8hX4VGSvj8eZYiZhBSzZACB9ZEorWg+DVYqunsU RFZh8hBBTc1wggIAqZQ8fPUMT+E336fsvX6EBArXEQTHs+Q6GmOMMeP/F2BbTvjRp3yP 38VdoqNYXn7SI2xBaY09WCr+qilbJTaiNEXxjdzAV9AQQ9JUqPWXdte/fUYO6KBM0A0C FpO9xdOiWJLrQSK1axpfwR42CRT4jmUVITnSPFR0HZjupTxdP02SIacYzr13JUNGmFkW yvWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ktuN17gmiqlKE/I4GYw0sVSSXcxY6RgmY2JpLivgLB4=; b=RXtUuuvouMDCSm0H4smAj9A+z8BGAOR+7cQJDKIVdn7FY9DLVT53c9EW+qC3pDQIL+ n83TXVxvxzpbc2d0HsO9SGgIDZ8ifUw/GHp28+SH2fGfjm1k0jlVvy6os9mJpIyI+5Pu HeGcSFQJsIGhJ1PrgGO5IgKLNhX6ijYA2BsD5ZYYJK/f9YVJziNEagPI3/nFZxPn6DMf ftQFCxxbxzw5QDBCfz8IUGqn9TcJz4tEXWxAOs3Tm9tDVtCZc0VsqCPDVhYfKZWllDGk q837lRXhhZqh4EAdrCwTxigw4vanQjiVsCiIZ++9Q7WKgr6U450UGISau0ZuMJSj1MjF b7vA== X-Gm-Message-State: APjAAAWaJxwjlVC4kaGDAKIWr3KWbkOrGTMzReghygUJAhrTuTHe4ZCL 4yVlyhXn8sxC9tWA1zFgUPNFgx/3Gz8+BKMFgOqxFQ== X-Received: by 2002:a67:fbcf:: with SMTP id o15mr17597426vsr.13.1582233268659; Thu, 20 Feb 2020 13:14:28 -0800 (PST) MIME-Version: 1.0 References: <0a27b6fcbd1f7af104d7f4cf0adc6a31e0e7dd19.1582216294.git.schatzberg.dan@gmail.com> <20200220210344.GK54486@cmpxchg.org> In-Reply-To: <20200220210344.GK54486@cmpxchg.org> From: Shakeel Butt Date: Thu, 20 Feb 2020 13:14:17 -0800 Message-ID: Subject: Re: [PATCH v3 2/3] mm: Charge active memcg when no mm is set To: Johannes Weiner Cc: Dan Schatzberg , Jens Axboe , Tejun Heo , Li Zefan , Michal Hocko , Vladimir Davydov , Andrew Morton , Hugh Dickins , Roman Gushchin , 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)" 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 Hi Johannes, On Thu, Feb 20, 2020 at 1:03 PM Johannes Weiner wrote: > > Hey Shakeel! > > On Thu, Feb 20, 2020 at 10:14:45AM -0800, Shakeel Butt wrote: > > On Thu, Feb 20, 2020 at 8:52 AM 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. > > > > What if css_tryget_online(current->active_memcg) in > > get_mem_cgroup_from_current() fails? Do we want to change this to > > css_tryget() and even if that fails should we fallback to > > root_mem_cgroup or current->mm->memcg? > > Good questions. > > I think we can switch to css_tryget(). If a cgroup goes offline > between issuing the IO and the loop layer executing that IO, the > resources used could end up in the root instead of the closest > ancestor of the offlined group. However, the risk of that actually > happening and causing problems is probably pretty small, and the > behavior isn't really worse than before Dan's patches. Agreed. > > Would you mind sending a separate patch for this? AFAICS similar > concerns apply to all users of foreign charging. Sure and yes similar concerns apply to other users as well. > > As for tryget failing: can that actually happen? AFAICS, all current > users acquire a reference first (get_memcg_from_somewhere()) that they > assign to current->active_memcg. We should probably codify this rule > and do WARN_ON(!css_tryget()) /* current->active_memcg must hold a ref */ Yes, we should WARN_ON(). Shakeel