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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB6DFC433FE for ; Wed, 16 Feb 2022 18:08:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 231126B0074; Wed, 16 Feb 2022 13:08:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DF626B0075; Wed, 16 Feb 2022 13:08:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0812D6B0078; Wed, 16 Feb 2022 13:08:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id EC41E6B0074 for ; Wed, 16 Feb 2022 13:08:57 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AD04422029 for ; Wed, 16 Feb 2022 18:08:57 +0000 (UTC) X-FDA: 79149429114.01.B4088B2 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf06.hostedemail.com (Postfix) with ESMTP id 0916E180007 for ; Wed, 16 Feb 2022 18:08:56 +0000 (UTC) Received: by mail-qv1-f48.google.com with SMTP id fh9so3467361qvb.1 for ; Wed, 16 Feb 2022 10:08:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=CU/AXfwa3Im1uRiNONAlogBiTBFdbTVUfdiUCLuEKiU=; b=yiK42wLBMgMpyLohAN1o3Njdrw1GDrndn/LnvGp1r/2/zpQQ19LDq26SHKCoy4MABR KnxhFYtTwOz86H7aytfUSLMEqPySVagV3hwu/eHxBVMcZ+urO7BETp5mTcoi4NO/XgkK Tv15THJP3UINtYcAQ6rhbrjp0fnwzUYkzGsjWdBC8HSW9U1klmFXz6mTaIZ6VhliM1HV Qf7FqeaE4l2ShY8jI6dBkaUF5j9eg0KZcydK99isY/wyAgg/OBAHndTRvv7SYEG49fO7 nuIfwtpUfWaqZa5ANse9pWfIHdyqGc3Lt3FgZxZ+FRNW3Kk56RBywgCH3RKsxKRAgl/2 54sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=CU/AXfwa3Im1uRiNONAlogBiTBFdbTVUfdiUCLuEKiU=; b=oz4C3jrJkvbmx+7UZn8iQW3DVimHKV07weie+dRK/IoZc4rhwF5ANJQPbM44YbsKKV j5yYq1aOcMXiOmPklYDAgRJ6kEfCCWwRaOwnDrbXCEtbTCcKVae+vaDXhIQK6jd60xmj Eiy+sXW9rW3Fyp9eLXm/jGdP5QtsdAdg6/c2Z4YnJK7O4kVdjd6aD6DTjwgM9+yCOSYQ pmsXLFzapKA07/N1E8RJ5wToGjlQ+kS27I7+vzf0vyHD7ES9wSy5nGIAT/Ma00ZKyFO/ Dx1k9N6AVUsXutC/LHTFX6YrD6brJMAht9xQKJ7HOQxvmXKusjsJ5VHrcW8IiMfAmi9M LVqg== X-Gm-Message-State: AOAM531KfeKucdk7r+lE1AXYnGYJPIBUadSS4kKiAvE6M6HYdH1sNz7E 9YQ2kBOiVnrtL3UYP2I5I/0EOg== X-Google-Smtp-Source: ABdhPJz8/GbVoZCrQP4OvM+Ha+RfFhBpB2GEpiccs/C8aRkP3wcv/kZSfTgk3i1QLt0I41Lvm86nFw== X-Received: by 2002:a05:6214:2342:b0:42d:7c8b:9eac with SMTP id hu2-20020a056214234200b0042d7c8b9eacmr2657405qvb.5.1645034936263; Wed, 16 Feb 2022 10:08:56 -0800 (PST) Received: from localhost (cpe-98-15-154-102.hvc.res.rr.com. [98.15.154.102]) by smtp.gmail.com with ESMTPSA id bm27sm18247425qkb.5.2022.02.16.10.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 10:08:55 -0800 (PST) Date: Wed, 16 Feb 2022 13:08:55 -0500 From: Johannes Weiner To: Sebastian Andrzej Siewior Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Michal Hocko , Michal =?iso-8859-1?Q?Koutn=FD?= , Peter Zijlstra , Thomas Gleixner , Vladimir Davydov , Waiman Long , kernel test robot Subject: Re: [PATCH v2 4/4] mm/memcg: Protect memcg_stock with a local_lock_t Message-ID: References: <20220211223537.2175879-1-bigeasy@linutronix.de> <20220211223537.2175879-5-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0916E180007 X-Stat-Signature: dcme73gzdb4chi4oo8oes9x9ffz4gnjq Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=yiK42wLB; spf=pass (imf06.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.48 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-HE-Tag: 1645034936-763963 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 Wed, Feb 16, 2022 at 04:51:14PM +0100, Sebastian Andrzej Siewior wrote: > On 2022-02-14 11:23:11 [-0500], Johannes Weiner wrote: > > Hi Sebastian, > Hi Johannes, > > > This is a bit dubious in terms of layering. It's an objcg operation, > > but what's "locked" isn't the objcg, it's the underlying stock. That > > function then looks it up again, even though we have it right there. > > > > You can open-code it and factor out the stock operation instead, and > > it makes things much simpler and clearer. > > > > I.e. something like this (untested!): > > This then: > > ------>8------ > > From: Johannes Weiner > Date: Wed, 16 Feb 2022 13:25:49 +0100 > Subject: [PATCH] mm/memcg: Opencode the inner part of > obj_cgroup_uncharge_pages() in drain_obj_stock() > > Provide the inner part of refill_stock() as __refill_stock() without > disabling interrupts. This eases the integration of local_lock_t where > recursive locking must be avoided. > Open code obj_cgroup_uncharge_pages() in drain_obj_stock() and use > __refill_stock(). The caller of drain_obj_stock() already disables > interrupts. > > [bigeasy: Patch body around Johannes' diff ] > > Signed-off-by: Johannes Weiner > Signed-off-by: Sebastian Andrzej Siewior I thought you'd fold it into yours, but separate patch works too, thanks! Signed-off-by: Johannes Weiner One important note, though: > @@ -3151,8 +3155,17 @@ static void drain_obj_stock(struct memcg_stock_pcp *stock) > unsigned int nr_pages = stock->nr_bytes >> PAGE_SHIFT; > unsigned int nr_bytes = stock->nr_bytes & (PAGE_SIZE - 1); > > - if (nr_pages) > - obj_cgroup_uncharge_pages(old, nr_pages); > + if (nr_pages) { > + struct mem_cgroup *memcg; > + > + memcg = get_mem_cgroup_from_objcg(old); > + > + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) > + page_counter_uncharge(&memcg->kmem, nr_pages); > + __refill_stock(memcg, nr_pages); This doesn't take "memcg: add per-memcg total kernel memory stat" queued in -mm into account and so will break kmem accounting. Make sure to rebase the patches to the -mm tree before sending it out. You can find it here: https://github.com/hnaz/linux-mm