Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp69809pxu; Tue, 24 Nov 2020 19:06:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxW4BTQ4M0wantFteGahbfXC14bPpfb4XI/DOQ6dBDK/GSVj/U1A3vr5S13zei59nJAuL7u X-Received: by 2002:aa7:cb58:: with SMTP id w24mr1548991edt.35.1606273596164; Tue, 24 Nov 2020 19:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606273596; cv=none; d=google.com; s=arc-20160816; b=enolIaFl74fM+lhNCRRBSV5//FQW2+98RTbi/J/5clzOWPbFCr/K6Sgn30xmTHpzOC 6+Ply3XAzU1s9l4ItDqfyOp0+7WzCGsiKg8Vki1edA+jZ8f6TauiBmyUbU/WIHHAWPyz GtfjQ6XA6zCBp57KgsYqJTKjIKqS5MGspzMH2oPfpeSaq3mRIoPa+82dcYfEMAmoumJl DZ3Ip7Ujfxfyi63h0rCqS0gtcQZkhyMM0qSu8sq4MNi2wsx3JQcNoStLVzXIxgQypXZC fmk952213pdJOByq2uVpAcKd/CTEk690m44Jp7rpWIRCg9VxrRfJiJl/BtXtSJaVFWm9 5ATA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Hwzm6M4F6p3wIIDsFCV/NiMC7IzEqkcaYpjxL5TApLo=; b=Fj88w8WABJ1itqsHD8ivEk5PC3W4An60Zb/YdcSpu0wI47ShhGCYDK3/2RHSnDqmT5 KpZBRYEx2Fxomhe5xs7wAPUbx2pi4OnkqtmutqDenZrg+FHy3QWq87OIxOd6YMx/oEKB jLzDC1AK2pr2XLbw1hJICQXrWCWjwMVhE7eVRYmHUYrGwFil1AU08CF5QfsiD9R8VWbc OhEzdqIkeU+A6xG7xgRrdVTcklevrAU+oKy3708ZYV7sbPBLqRLcwYov7H5wWNKLLFnZ osg8gjp+bc2UY/nJZUFUVL48YbTKXL0gy+SdpKfwJUdE7789ysHFsEzx5Aa9zDKCf57C GGfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=KQKvlqMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si208488ejp.420.2020.11.24.19.06.13; Tue, 24 Nov 2020 19:06:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=KQKvlqMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728561AbgKYDDg (ORCPT + 99 others); Tue, 24 Nov 2020 22:03:36 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:10592 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727352AbgKYDBa (ORCPT ); Tue, 24 Nov 2020 22:01:30 -0500 Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AP2sxBw004061 for ; Tue, 24 Nov 2020 19:01:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=facebook; bh=Hwzm6M4F6p3wIIDsFCV/NiMC7IzEqkcaYpjxL5TApLo=; b=KQKvlqMWS+2GHCzGp+UPGFUtmAnBckj4VzM5fx9y6Ig6MaRI0mu9sqcqfV16+5elFGPV R9vx7xizwKRTbavmLRdgrtkYxi1X2VWsyndF5lUThuS7FCHBz5f05R/AYZIWLo2Nv8mr +hCD14+qPm3glUEvOgMh4pe385VbPalbiK8= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 3516xbsv6h-18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 24 Nov 2020 19:01:28 -0800 Received: from intmgw002.41.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 24 Nov 2020 19:01:25 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id E750316A1887; Tue, 24 Nov 2020 19:01:21 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v8 03/34] mm: introduce page memcg flags Date: Tue, 24 Nov 2020 19:00:48 -0800 Message-ID: <20201125030119.2864302-4-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201125030119.2864302-1-guro@fb.com> References: <20201125030119.2864302-1-guro@fb.com> X-FB-Internal: Safe Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-24_11:2020-11-24,2020-11-24 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxlogscore=513 clxscore=1015 bulkscore=0 spamscore=0 suspectscore=1 impostorscore=0 phishscore=0 malwarescore=0 adultscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011250018 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The lowest bit in page->memcg_data is used to distinguish between struct memory_cgroup pointer and a pointer to a objcgs array. All checks and modifications of this bit are open-coded. Let's formalize it using page memcg flags, defined in enum page_memcg_data_flags. Additional flags might be added later. Link: https://lkml.kernel.org/r/20201027001657.3398190-4-guro@fb.com Signed-off-by: Roman Gushchin Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner Acked-by: Michal Hocko Signed-off-by: Andrew Morton --- include/linux/memcontrol.h | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index c7ac0a5b8989..99a4841d658b 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -343,6 +343,15 @@ struct mem_cgroup { =20 extern struct mem_cgroup *root_mem_cgroup; =20 +enum page_memcg_data_flags { + /* page->memcg_data is a pointer to an objcgs vector */ + MEMCG_DATA_OBJCGS =3D (1UL << 0), + /* the next bit after the last actual flag */ + __NR_MEMCG_DATA_FLAGS =3D (1UL << 1), +}; + +#define MEMCG_DATA_FLAGS_MASK (__NR_MEMCG_DATA_FLAGS - 1) + /* * page_memcg - get the memory cgroup associated with a page * @page: a pointer to the page struct @@ -404,13 +413,7 @@ static inline struct mem_cgroup *page_memcg_check(stru= ct page *page) */ unsigned long memcg_data =3D READ_ONCE(page->memcg_data); =20 - /* - * The lowest bit set means that memcg isn't a valid - * memcg pointer, but a obj_cgroups pointer. - * In this case the page is shared and doesn't belong - * to any specific memory cgroup. - */ - if (memcg_data & 0x1UL) + if (memcg_data & MEMCG_DATA_OBJCGS) return NULL; =20 return (struct mem_cgroup *)memcg_data; @@ -429,7 +432,11 @@ static inline struct mem_cgroup *page_memcg_check(stru= ct page *page) */ static inline struct obj_cgroup **page_objcgs(struct page *page) { - return (struct obj_cgroup **)(READ_ONCE(page->memcg_data) & ~0x1UL); + unsigned long memcg_data =3D READ_ONCE(page->memcg_data); + + VM_BUG_ON_PAGE(memcg_data && !(memcg_data & MEMCG_DATA_OBJCGS), page); + + return (struct obj_cgroup **)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); } =20 /* @@ -444,10 +451,10 @@ static inline struct obj_cgroup **page_objcgs_check(s= truct page *page) { unsigned long memcg_data =3D READ_ONCE(page->memcg_data); =20 - if (memcg_data && (memcg_data & 0x1UL)) - return (struct obj_cgroup **)(memcg_data & ~0x1UL); + if (!memcg_data || !(memcg_data & MEMCG_DATA_OBJCGS)) + return NULL; =20 - return NULL; + return (struct obj_cgroup **)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); } =20 /* @@ -460,7 +467,8 @@ static inline struct obj_cgroup **page_objcgs_check(str= uct page *page) static inline bool set_page_objcgs(struct page *page, struct obj_cgroup **objcgs) { - return !cmpxchg(&page->memcg_data, 0, (unsigned long)objcgs | 0x1UL); + return !cmpxchg(&page->memcg_data, 0, (unsigned long)objcgs | + MEMCG_DATA_OBJCGS); } #else static inline struct obj_cgroup **page_objcgs(struct page *page) --=20 2.26.2