Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1478441pxk; Fri, 2 Oct 2020 10:27:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyR+7Mx2PLG1XlvbyU85AVwCAfCvILJKrwVvd7oBfF3K65hKCMwyASrdnpljIZEDW5WekmF X-Received: by 2002:a50:ee15:: with SMTP id g21mr3573639eds.47.1601659653015; Fri, 02 Oct 2020 10:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601659653; cv=none; d=google.com; s=arc-20160816; b=fqGdVmxD4HhaOrl3cb5Zw3QojVfz6okgfKGMAh9Mefq1jkwsdqGMT97NrefiDB0Axu KDD6mTg2EBJU0ggXK/aSaYLSByQN0Nu11+QLL03NRf3pXCrmNVD6wICSBU57yR8iwiva u+GNcMRgfIKaVDZ2jlXy8CbYyg3sKL1U+UWwEO8unHK5fbvpx7pBm434enNOhho+HZDV z9mGo1eC7Q9p6RcRTm9Ve+aSAyVYVLsncmU6GIErqgN/KDFfXdGohRvHajJ5lmw55gp7 cp0UKakfl/ITyNRaKuymotOlMvw3PQ87PjGwwnFm+H2VeBzgfJ64wAEPKdOLUeXC/eLd 7kdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5nmzS807sBiYvbQFNv9ABrpCezNK+SLtHjw1RYXnIGM=; b=vuz17Sb0SNdJm17LXFpv74z8g6cveQgVMBTknSk/aitW8bGyYpdhhdNm7IocbH4FVl Kqgs/UV+9jYAsCEy2vHLBTMhLIjBRFzuYBy6XupGxQFqH5M4MqzKQwLCK3wxofmCraDx mW8IxXTl4KbjILZNjlnqjFKkt0xCf0LqxUoINaivct0AaJbbBTKheqXAxw0HBmSA+N/t 9sSPziaLI4Z6DiW/Q0Y2TEHp89viDbjIgs1mASYpJdM4X1/OWlyKBmYLBS3K9AJxmwLu +H9kunDm87AxhZKDUQlr8tchlMlO9Ostgus65oxguxYdo4d0hgNJDh5exYRyzylw4DUg 5Oiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=A7BQ1SsK; 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 p11si1578824ejc.160.2020.10.02.10.27.10; Fri, 02 Oct 2020 10:27:33 -0700 (PDT) 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=A7BQ1SsK; 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 S2388247AbgJBR0H (ORCPT + 99 others); Fri, 2 Oct 2020 13:26:07 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:4634 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388132AbgJBR0G (ORCPT ); Fri, 2 Oct 2020 13:26:06 -0400 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 092HEW1x017232 for ; Fri, 2 Oct 2020 10:26:05 -0700 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 : mime-version : content-transfer-encoding : content-type; s=facebook; bh=5nmzS807sBiYvbQFNv9ABrpCezNK+SLtHjw1RYXnIGM=; b=A7BQ1SsK8Hfwya1az5xpI0NEk0BKhfauq3cZPB1uVTISvAB31sWjaiFhUdqEwaPXVzuA xD1Wq8uQegOAiRv/Rk36wkWT6ZAvGAtcdlJCQvVCX2bM/vfyPrW1SVP7gARmD/DOMacY MVT4383GCxig0314nsLLqK22BiShGj1FRek= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 33x6gu8tck-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 02 Oct 2020 10:26:04 -0700 Received: from intmgw001.41.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 2 Oct 2020 10:26:03 -0700 Received: by devvm1755.vll0.facebook.com (Postfix, from userid 111017) id C1AF8F152A1; Fri, 2 Oct 2020 10:26:00 -0700 (PDT) From: Roman Gushchin To: Andrew Morton CC: Shakeel Butt , Johannes Weiner , Michal Hocko , , , , Roman Gushchin Subject: [PATCH v5 3/4] mm: introduce page memcg flags Date: Fri, 2 Oct 2020 10:25:58 -0700 Message-ID: <20201002172559.4000748-4-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201002172559.4000748-1-guro@fb.com> References: <20201002172559.4000748-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-10-02_11:2020-10-02,2020-10-02 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 mlxlogscore=382 spamscore=0 mlxscore=0 clxscore=1015 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 impostorscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010020129 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. Signed-off-by: Roman Gushchin Reviewed-by: Shakeel Butt --- 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(st= ruct 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(st= ruct 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= (struct 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(s= truct 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