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 A6AF9C43334 for ; Sun, 19 Jun 2022 19:37:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB4206B0071; Sun, 19 Jun 2022 15:37:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C64256B0072; Sun, 19 Jun 2022 15:37:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B53A96B0073; Sun, 19 Jun 2022 15:37:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A662E6B0071 for ; Sun, 19 Jun 2022 15:37:40 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6ED8233CA2 for ; Sun, 19 Jun 2022 19:37:40 +0000 (UTC) X-FDA: 79595995080.27.3B2DA9A Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf08.hostedemail.com (Postfix) with ESMTP id EAC5D16000B for ; Sun, 19 Jun 2022 19:37:39 +0000 (UTC) Date: Sun, 19 Jun 2022 12:37:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1655667458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YC8yB2PG4+G4xynDd4qhQyEPOAofxKVrbu3RRitWED4=; b=qD+Mvbj8IaI6qDNJWPeluOnJwp3jOJoDFAlyYvn3hpSvpPHCy2u9O7pXCmd/wKVQaa191Z BL+H+G8SckXSSX4/zrN40egc6e0GXplsUqbnw5+JYBugq02IQYc5TAljDysQhZNjUYe+lb /lPOYR+3IUzs8PTIkjMG8AUO96ECJrU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Muchun Song Cc: hannes@cmpxchg.org, mhocko@kernel.org, shakeelb@google.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, longman@redhat.com Subject: Re: [PATCH v5 07/11] mm: memcontrol: make all the callers of {folio,page}_memcg() safe Message-ID: References: <20220530074919.46352-1-songmuchun@bytedance.com> <20220530074919.46352-8-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220530074919.46352-8-songmuchun@bytedance.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655667460; a=rsa-sha256; cv=none; b=0muXlitkF2Tw8CYw81H937+JbFttQcuhn6cxGOptbGRAN55/tum4V+Es4I62Rv56L2537c OaoMTjiFTMr34A6jXSskA1Mw5OIMs4ktyHwDzPY7s0OnTtr0g5AsSEdP9Mzvq52qSnoJZJ CCYKQa4adVPEZvXhjMob072QF9WbAso= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qD+Mvbj8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of roman.gushchin@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655667460; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YC8yB2PG4+G4xynDd4qhQyEPOAofxKVrbu3RRitWED4=; b=5boFvvDcwE6lytkHVE77oKNiGvkWe3oBMu2YGbskDshB6BI+7X1+/3xie8FJtDswPYqohU 957RELAdiLH2Fzt2ucGVQGLPSY4LF8y+KRNC8EC8TEdyXiPux8n/2U+1mJZIagcj3K1cHr JW9yqEwqsszrFThm5ZR0aAHQ+bx3DJI= X-Rspamd-Server: rspam01 X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qD+Mvbj8; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of roman.gushchin@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev X-Stat-Signature: 4tb6hig76tnd1pm79mb14p5qquoxizik X-Rspamd-Queue-Id: EAC5D16000B X-HE-Tag: 1655667459-391553 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 Mon, May 30, 2022 at 03:49:15PM +0800, Muchun Song wrote: > When we use objcg APIs to charge the LRU pages, the page will not hold > a reference to the memcg associated with the page. So the caller of the > {folio,page}_memcg() should hold an rcu read lock or obtain a reference > to the memcg associated with the page to protect memcg from being > released. So introduce get_mem_cgroup_from_{page,folio}() to obtain a > reference to the memory cgroup associated with the page. > > In this patch, make all the callers hold an rcu read lock or obtain a > reference to the memcg to protect memcg from being released when the LRU > pages reparented. > > We do not need to adjust the callers of {folio,page}_memcg() during > the whole process of mem_cgroup_move_task(). Because the cgroup migration > and memory cgroup offlining are serialized by @cgroup_mutex. In this > routine, the LRU pages cannot be reparented to its parent memory cgroup. > So {folio,page}_memcg() is stable and cannot be released. > > This is a preparation for reparenting the LRU pages. > > Signed-off-by: Muchun Song Acked-by: Roman Gushchin The locking seems to be correct. I'm slightly worried about a potential perf degradation, especially on dying cgroups, where css_get() is relatively expensive. I hope getting it into mm-unstable will help to determine whether it's actually a problem. Thanks!