Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1093673ybv; Thu, 20 Feb 2020 13:05:14 -0800 (PST) X-Google-Smtp-Source: APXvYqy9OEeKeEeNkZ43Ipki1/7M3nWjXBzdFDB9I84jU4RgDOTf6SgEqG6gPCQBkNgelgAwI8hP X-Received: by 2002:a54:4011:: with SMTP id x17mr3403297oie.35.1582232713922; Thu, 20 Feb 2020 13:05:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582232713; cv=none; d=google.com; s=arc-20160816; b=XCGvrKcHj9FIdfZbLeRVM14AceCLEisP7FooSLhaRrx5WSdluDLmGpqzVbD/wb4udm yW1tk3ofac8tTrahVl7Zz8Om5hXVfdOCBArmtVHhvjpNdfLuKo8ErrvTzsipo2rxGqVg FJU1y1mI8NrxchHeXovx++8teSpVUtsahL72E6Y15oOf3Aqa9WK7rr0/tFiEVU+3h4Jj HR4PrDcWiISipmmTABqGhBC188074LzyjoRCs7keyuBuA1g2iEla5mryCDqhIuCx4zuK g8UtRr50LCqroiH+klmnk5bQJIV1yvRrg0P1OuaJurDtoYyViWXHbcNn8lnhgmfh5b6N c8GA== 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=6QH645NYVKdQbEm2dIlQdYX121ucp0jcY5IFqd2iTAM=; b=ELOWkhkgNtYjnB3JfDX/K966EVvrT8UoqUEn2LzbfVOkdbyR6z+tzEqyNHWe0/6j8N PYW4SgZG4uvF7J0C0wWXqiz6PG44ovfrQmUslkInyW2LoR+9/GKX4nk7BN99xjCHkTaB akD+YweQAUvFRph1PYLRS3OIyEXUrLKTMfm60o2ArxOVsYqsVT23e00Zl6gNv/NmaFop ORQeKWEPA3wBhaX4GHiIAoTr+Fnd71eHSw+mS5ciUrUlLO+UaQfYilj3K7nyZD5sXWjK X7oSwNDMjICm8lAxTl2D43IwXrT3Xlafx5TMXdw5mfiPhYCB/Tp4M2V0Z/VyedbrQQO+ SC8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=m1KDQ49I; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si318822otr.8.2020.02.20.13.05.00; Thu, 20 Feb 2020 13:05:13 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=m1KDQ49I; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729099AbgBTVDr (ORCPT + 99 others); Thu, 20 Feb 2020 16:03:47 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:45148 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729055AbgBTVDr (ORCPT ); Thu, 20 Feb 2020 16:03:47 -0500 Received: by mail-qt1-f195.google.com with SMTP id d9so3935736qte.12 for ; Thu, 20 Feb 2020 13:03:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6QH645NYVKdQbEm2dIlQdYX121ucp0jcY5IFqd2iTAM=; b=m1KDQ49IVlT6YDlcrR6kEHfCL5+o2vBShdjFVu+ROsFCINUdPBhVp7ZfyQt8YkI4V1 ApmRefafOkHmPeBqAw+aOBORpbSSPQvei4ZebQKB6lbePikwbuyMsGeJXjPGkKyhKF37 9o1/9zImGJswylC3buBORrbYwImOCEp6dvqkw7OsG2kKvjpLcZYbIMBWEEJBGIfSfePm lGuJBobkL/67AGpQYKeKwnKNQ1SI7SGZF6n4xEHA6Fr1dU2rHcyXW6iOC4YReVB3nvXP 1eTMKYwJmvRR0MRNpnHb4fLXuhiRnQktysIIIW6duWgeu98O/ehaOE4y54nOMfsUxX8A 5c/w== 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=6QH645NYVKdQbEm2dIlQdYX121ucp0jcY5IFqd2iTAM=; b=lfp5bn97sr9iSNoC0ytBENCE+7umewqYUGaXzEeSLsDpmTWxr1wlU09E/WYzivI6rf boW4pEpc4sI23A9hVdwAV/mOVcwQkmv9M4g5KSdor8JKAf3UMAyoMunIRWERo1KMmbUu YNqEGhoAZHR8aeONBNXHl2Y57wJO1NnxQdVw9uL5QUfEo7vCvdJLQkA74qyDWzEjN4kU G20aIc1Bdm/Cjav6Ow6taM1IB8v6HNEqjYNGtfjp5KG1LgIYjyx4pu4H2bZNn8dKBAQ0 Ud6kgjoYyhN8jpFZksR43z6B/NMi45zxDNWb0TRr0Kv5UqEa0pEQ7PJBMMWpXuaD2rkd LxOA== X-Gm-Message-State: APjAAAWBVs6gCh4U9/oIpZ3FsrfASnvKHT4C7uQgCAlyTy/v0g5D4UWw AV/1FoFp4ff06HbquH63EJ4KAA== X-Received: by 2002:ac8:7258:: with SMTP id l24mr27935548qtp.154.1582232625787; Thu, 20 Feb 2020 13:03:45 -0800 (PST) Received: from localhost ([2620:10d:c091:500::1:3504]) by smtp.gmail.com with ESMTPSA id h6sm420212qtr.33.2020.02.20.13.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 13:03:44 -0800 (PST) Date: Thu, 20 Feb 2020 16:03:44 -0500 From: Johannes Weiner To: Shakeel Butt 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)" Subject: Re: [PATCH v3 2/3] mm: Charge active memcg when no mm is set Message-ID: <20200220210344.GK54486@cmpxchg.org> 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 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. Would you mind sending a separate patch for this? AFAICS similar concerns apply to all users of foreign charging. 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 */