From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D85D1C286 for ; Thu, 25 Jul 2024 17:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721929197; cv=none; b=njpigpTTRlPktFvO7W1EHzkyR5VoPYepBQlOPh1rxyfUaytpOTMyoTGwwfr2o4jT+M9POakQuRMXJkfiXhuernqDPc7gFSYIoMwgZXHd3kxaEFH0MeKt+j7rNPtvQIuJ2gzzQO2RKQqxwJHxDvEr7o8oJJ0xgNuof3MlokJ3Ykg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721929197; c=relaxed/simple; bh=yoEv3GlbwT6UsQ5b5s5duS6tb26odOD0neXsqOSLGEE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xjp/wqjlJDRJaeYRRpWWLd8rgZ+UUCqL5uhtFqKH4O/jdsEpr85FDatXHE5JUhIPJwCsl3Y22zyuyWrZqhIYNpzEhJo+HoDd6sZVDNp3s5Hz9uyGLEApNDW+h/R3Tu2pqYVzSPGt5FZYLpllwc0RKedVzC11l1WVPg7rvbpSNfY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FgNdkf4J; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FgNdkf4J" Date: Thu, 25 Jul 2024 17:39:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721929193; 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=wodKrrDe2cqof0/g9wNaNIiFlKLU0ROQCInky1h/aQo=; b=FgNdkf4JTFnSgALEkNLIckMzWTpjyhh8UIdUCiMC8VSGcsi80CXKKYMsp53gE7tsNBO0Qq sJduM1mngr2yTe7RfxBKc0FoD6rRVSNzanp8hZEsuaC2c0UyI/d2YxNy6bPkkuZ/KXLomQ 6YGuQ9RGzooG1yYEvhTuVRpu4WnADZY= 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, shakeel.butt@linux.dev, muchun.song@linux.dev, akpm@linux-foundation.org, vbabka@kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] mm: kmem: add lockdep assertion to obj_cgroup_memcg Message-ID: References: <20240725094330.72537-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240725094330.72537-1-songmuchun@bytedance.com> X-Migadu-Flow: FLOW_OUT On Thu, Jul 25, 2024 at 05:43:30PM +0800, Muchun Song wrote: > The obj_cgroup_memcg() is supposed to safe to prevent the returned > memory cgroup from being freed only when the caller is holding the > rcu read lock or objcg_lock or cgroup_mutex. It is very easy to > ignore thoes conditions when users call some upper APIs which call > obj_cgroup_memcg() internally like mem_cgroup_from_slab_obj() (See > the link below). So it is better to add lockdep assertion to > obj_cgroup_memcg() to find those issues ASAP. > > Because there is no user of obj_cgroup_memcg() holding objcg_lock > to make the returned memory cgroup safe, do not add objcg_lock > assertion (We should export objcg_lock if we really want to do). > Additionally, this is some internal implementation detail of memcg > and should not be accessible outside memcg code. > > Some users like __mem_cgroup_uncharge() do not care the lifetime > of the returned memory cgroup, which just want to know if the > folio is charged to a memory cgroup, therefore, they do not need > to hold the needed locks. In which case, introduce a new helper > folio_memcg_charged() to do this. Compare it to folio_memcg(), it > could eliminate a memory access of objcg->memcg for kmem, actually, > a really small gain. > > Link: https://lore.kernel.org/all/20240718083607.42068-1-songmuchun@bytedance.com/ > Signed-off-by: Muchun Song Acked-by: Roman Gushchin Thanks!