Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1101153ybi; Fri, 21 Jun 2019 13:54:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuNnmh+6JT2EMFw/385Vs0oDtdAXixHAYnhbycoKSvSBWtXUGtDjSmL8w6nw1+hsi9k2Ag X-Received: by 2002:a17:90a:cb97:: with SMTP id a23mr8909177pju.67.1561150466039; Fri, 21 Jun 2019 13:54:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561150466; cv=none; d=google.com; s=arc-20160816; b=X54w8iPe8368LpmgBeNio6mXHLam6/P65xRRwaSZONrA8PEmdYohyv5EwYCRx8bhN+ HMntHz6CE8AR+esCQ9MDfYUrgnokt8Iyp3iP7WV3xakcWMX376LrJcPiiCWf69styM8m o8ro22O1jq1oNjGNljL/uLtCw5HCol6sa1it9cbwtW/04vbQRgWZ7jgvYkFF+VxN0hJM 7vEGJkAw8gsifQTlQDFUb9tD1ENpf5C+56HKgkU7/1BxL2X7etVwFcUeO7kEZz5dA6BI t/nHI9ou6DK5Nkge1F38JIX61HwZ+cqY55ItzcdRviC1hI3DFgyToY+lBlba9wgkhYsa awCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=+OoZ/yZue0TmErM/yxfWH2TRWbijAlEGvAbUYgMmZLE=; b=GBsPsHei0vGPOnZcfzx4rQJJPfxgv0mmXcd2zY2OFUohelcJcCKXW/kivmbaubzgQA th/LA9Fxoj3PtWKzb9w3M1d0EMQAy3Lj/0VE+lEg/sS6ldlWEyw2MSiDu+76M1XTbl+M BejR5Z8+7yZmwKlK21xupujLHwcJeMTfq++Bt/354BMZjc1YN7VYSY4MK9+MMWeHqlup dYfp5Toy2J4NwGMcVnnkoBHVss32OosmzaRasK4I/9443aKRKjFRnyg2xPkL23P7iuw5 fFtF3pOyHc2c7hk7FYRXfuIdFZ3310+ZAkOpElJFn14S9llF4uvbx0moqHbLtoDOitAg iVfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=BI31JsaF; 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 z8si3702385pjn.51.2019.06.21.13.54.10; Fri, 21 Jun 2019 13:54:26 -0700 (PDT) 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=BI31JsaF; 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 S1726141AbfFUUyF (ORCPT + 99 others); Fri, 21 Jun 2019 16:54:05 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39867 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbfFUUyF (ORCPT ); Fri, 21 Jun 2019 16:54:05 -0400 Received: by mail-pf1-f193.google.com with SMTP id j2so4177675pfe.6 for ; Fri, 21 Jun 2019 13:54:05 -0700 (PDT) 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=+OoZ/yZue0TmErM/yxfWH2TRWbijAlEGvAbUYgMmZLE=; b=BI31JsaFNk04cIzIG7G2Iuux9FOLoT2qKKw2WU8H0Ik+TyznIET6DVQHdEqq01bujf BlgOPh+di0+im7bkY+6BcKA1qJMkEpaICbiA140fphdP7ioHaU0V2Y1KbUmNKv6HtJvJ q11Hfb6hqGs9OsktfXSF36sxur281VGrljRHnobCHehWkWrtrTukpspeoSFtfdIX9E13 tePF4BRUqQdPGASkbxcqrU+oawmA6zCui7S7xqdYjH7dO3P22FqIvlwxJJgoSdJW3hOS 0tgF/+VJPsGAdZEp5efIYaFQ9Z5gz2yf3wMk1WheVkLluNuSJ/bnyX4fKNAznH01kikq SFJQ== 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=+OoZ/yZue0TmErM/yxfWH2TRWbijAlEGvAbUYgMmZLE=; b=b1RCmiCnxViuj1ZBaemxKWzF+uJa/sjhGk+BDv+7lTY3e+q36RfBw+eYsb/vg4yFMR T8ZPcBcY+O161Ogq4F/ijqEyG78sEuA8Ctirm8mtwDClYqOfXCBt3MeE5RShd86Ge73u ErKpHh4YVoJ36Ftf7tEpml6H8CpzH5KzcBixe0OjjPZ6zZLSYApmFEDEcRtLWwTSKdTi JVKrcD3/hERW1a4k1tzPJGbeEFv4yO5fgUOoDyliklnAtPdgkIiA04ZuRecmFcBZTBqL hp9lrSWXO2y4v0U+33IkadZH3MEA0twXQD+tEegfvZe4w3Bz7oBM7tILnD7Ce+ngvbeD 3DBA== X-Gm-Message-State: APjAAAX/0X86arVsLYMiJlamDKhAPHAritpQPcthDGvybTTUbIoTCHPe VwGBwTuZ3V1jlNTHt+pmNDPOVg== X-Received: by 2002:a17:90a:30e4:: with SMTP id h91mr8723116pjb.37.1561150444324; Fri, 21 Jun 2019 13:54:04 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id g8sm3704462pfi.8.2019.06.21.13.54.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 21 Jun 2019 13:54:03 -0700 (PDT) Date: Fri, 21 Jun 2019 13:54:03 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Roman Gushchin cc: Andrew Morton , Vladimir Davydov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Johannes Weiner , Shakeel Butt , Waiman Long , Andrei Vagin , Christoph Lameter , Michal Hocko , Joonsoo Kim , Pekka Enberg Subject: Re: [PATCH v2] mm: memcg/slab: properly handle kmem_caches reparented to root_mem_cgroup In-Reply-To: <20190620213427.1691847-1-guro@fb.com> Message-ID: References: <20190620213427.1691847-1-guro@fb.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 20 Jun 2019, Roman Gushchin wrote: > As a result of reparenting a kmem_cache might belong to the root > memory cgroup. It happens when a top-level memory cgroup is removed, > and all associated kmem_caches are reparented to the root memory > cgroup. > > The root memory cgroup is special, and requires a special handling. > Let's make sure that we don't try to charge or uncharge it, > and we handle system-wide vmstats exactly as for root kmem_caches. > > Note, that we still need to alter the kmem_cache reference counter, > so that the kmem_cache can be released properly. > > The issue was discovered by running CRIU tests; the following warning > did appear: > > [ 381.345960] WARNING: CPU: 0 PID: 11655 at mm/page_counter.c:62 > page_counter_cancel+0x26/0x30 > [ 381.345992] Modules linked in: > [ 381.345998] CPU: 0 PID: 11655 Comm: kworker/0:8 Not tainted > 5.2.0-rc5-next-20190618+ #1 > [ 381.346001] Hardware name: Google Google Compute Engine/Google > Compute Engine, BIOS Google 01/01/2011 > [ 381.346010] Workqueue: memcg_kmem_cache kmemcg_workfn > [ 381.346013] RIP: 0010:page_counter_cancel+0x26/0x30 > [ 381.346017] Code: 1f 44 00 00 0f 1f 44 00 00 48 89 f0 53 48 f7 d8 > f0 48 0f c1 07 48 29 f0 48 89 c3 48 89 c6 e8 61 ff ff ff 48 85 db 78 > 02 5b c3 <0f> 0b 5b c3 66 0f 1f 44 00 00 0f 1f 44 00 00 48 85 ff 74 41 > 41 55 > [ 381.346019] RSP: 0018:ffffb3b34319f990 EFLAGS: 00010086 > [ 381.346022] RAX: fffffffffffffffc RBX: fffffffffffffffc RCX: 0000000000000004 > [ 381.346024] RDX: 0000000000000000 RSI: fffffffffffffffc RDI: ffff9c2cd7165270 > [ 381.346026] RBP: 0000000000000004 R08: 0000000000000000 R09: 0000000000000001 > [ 381.346028] R10: 00000000000000c8 R11: ffff9c2cd684e660 R12: 00000000fffffffc > [ 381.346030] R13: 0000000000000002 R14: 0000000000000006 R15: ffff9c2c8ce1f200 > [ 381.346033] FS: 0000000000000000(0000) GS:ffff9c2cd8200000(0000) > knlGS:0000000000000000 > [ 381.346039] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 381.346041] CR2: 00000000007be000 CR3: 00000001cdbfc005 CR4: 00000000001606f0 > [ 381.346043] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > [ 381.346045] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > [ 381.346047] Call Trace: > [ 381.346054] page_counter_uncharge+0x1d/0x30 > [ 381.346065] __memcg_kmem_uncharge_memcg+0x39/0x60 > [ 381.346071] __free_slab+0x34c/0x460 > [ 381.346079] deactivate_slab.isra.80+0x57d/0x6d0 > [ 381.346088] ? add_lock_to_list.isra.36+0x9c/0xf0 > [ 381.346095] ? __lock_acquire+0x252/0x1410 > [ 381.346106] ? cpumask_next_and+0x19/0x20 > [ 381.346110] ? slub_cpu_dead+0xd0/0xd0 > [ 381.346113] flush_cpu_slab+0x36/0x50 > [ 381.346117] ? slub_cpu_dead+0xd0/0xd0 > [ 381.346125] on_each_cpu_mask+0x51/0x70 > [ 381.346131] ? ksm_migrate_page+0x60/0x60 > [ 381.346134] on_each_cpu_cond_mask+0xab/0x100 > [ 381.346143] __kmem_cache_shrink+0x56/0x320 > [ 381.346150] ? ret_from_fork+0x3a/0x50 > [ 381.346157] ? unwind_next_frame+0x73/0x480 > [ 381.346176] ? __lock_acquire+0x252/0x1410 > [ 381.346188] ? kmemcg_workfn+0x21/0x50 > [ 381.346196] ? __mutex_lock+0x99/0x920 > [ 381.346199] ? kmemcg_workfn+0x21/0x50 > [ 381.346205] ? kmemcg_workfn+0x21/0x50 > [ 381.346216] __kmemcg_cache_deactivate_after_rcu+0xe/0x40 > [ 381.346220] kmemcg_cache_deactivate_after_rcu+0xe/0x20 > [ 381.346223] kmemcg_workfn+0x31/0x50 > [ 381.346230] process_one_work+0x23c/0x5e0 > [ 381.346241] worker_thread+0x3c/0x390 > [ 381.346248] ? process_one_work+0x5e0/0x5e0 > [ 381.346252] kthread+0x11d/0x140 > [ 381.346255] ? kthread_create_on_node+0x60/0x60 > [ 381.346261] ret_from_fork+0x3a/0x50 > [ 381.346275] irq event stamp: 10302 > [ 381.346278] hardirqs last enabled at (10301): [] > _raw_spin_unlock_irq+0x29/0x40 > [ 381.346282] hardirqs last disabled at (10302): [] > on_each_cpu_mask+0x49/0x70 > [ 381.346287] softirqs last enabled at (10262): [] > cgroup_idr_replace+0x3a/0x50 > [ 381.346290] softirqs last disabled at (10260): [] > cgroup_idr_replace+0x1d/0x50 > [ 381.346293] ---[ end trace b324ba73eb3659f0 ]--- > > v2: fixed return value from memcg_charge_slab(), spotted by Shakeel > > Reported-by: Andrei Vagin > Signed-off-by: Roman Gushchin > Cc: Christoph Lameter > Cc: Johannes Weiner > Cc: Michal Hocko > Cc: Shakeel Butt > Cc: Vladimir Davydov > Cc: Waiman Long > Cc: David Rientjes > Cc: Joonsoo Kim > Cc: Pekka Enberg Acked-by: David Rientjes