From patchwork Thu Sep 24 19:27:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 11798167 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B52BE59D for ; Thu, 24 Sep 2020 19:29:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 74FD42396E for ; Thu, 24 Sep 2020 19:29:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="VLfEUYhF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74FD42396E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=fb.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AA4C06B0062; Thu, 24 Sep 2020 15:29:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A7CA36B0068; Thu, 24 Sep 2020 15:29:35 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96AAD6B006C; Thu, 24 Sep 2020 15:29:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 82CF46B0062 for ; Thu, 24 Sep 2020 15:29:35 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3A0D3180AD804 for ; Thu, 24 Sep 2020 19:29:35 +0000 (UTC) X-FDA: 77298944310.13.range89_610925f27161 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 12813181415A0 for ; Thu, 24 Sep 2020 19:29:35 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=6536bdcc23=guro@fb.com,,RULES_HIT:30054:30064,0,RBL:67.231.153.30:@fb.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04ygzy3w8kk4adpxp7zq8scqnyyqeopyykjczognou8973d6gb38cifxjj9ggcu.bifc4gmaekia6djhq1gxigmz4z3gdrqix9mw16c4ekwckmgkpcntsme3jiapsj3.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: range89_610925f27161 X-Filterd-Recvd-Size: 5805 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 19:29:34 +0000 (UTC) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08OJO1u9021679 for ; Thu, 24 Sep 2020 12:29:33 -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=DMLQuQVs+jJkKU3j8qk3nRyLWAjn1h8Qya2UpIdDJzE=; b=VLfEUYhFW7hNnD1zOZGCcRPezKlwq66uwuAJfcR1B8Nwt962EnnMrRmRwuJAv0qlhJKI qKRiCg7r628OSUvinRqcHuQrWQ6iXNGXd1gE7h9Kl6j38Y9HRoxXjIUS7ngIagM3HCoO rcWABstCKBCcCBVjPv91VUpLCgucRKSz+ms= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 33qsp43nfm-19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 24 Sep 2020 12:29:33 -0700 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 24 Sep 2020 12:27:13 -0700 Received: by devvm1755.vll0.facebook.com (Postfix, from userid 111017) id 759E199237B; Thu, 24 Sep 2020 12:27:09 -0700 (PDT) From: Roman Gushchin To: Andrew Morton CC: Shakeel Butt , Johannes Weiner , Michal Hocko , , , , Roman Gushchin Subject: [PATCH v2 3/4] mm: introduce page memcg flags Date: Thu, 24 Sep 2020 12:27:05 -0700 Message-ID: <20200924192706.3075680-4-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200924192706.3075680-1-guro@fb.com> References: <20200924192706.3075680-1-guro@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-09-24_14:2020-09-24,2020-09-24 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=297 clxscore=1015 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009240140 X-FB-Internal: deliver 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: 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 page_memcg_flags enum, and replace all open-coded accesses with test_bit()/__set_bit(). Additional flags might be added later. Signed-off-by: Roman Gushchin Reviewed-by: Shakeel Butt --- include/linux/memcontrol.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 2ed36c8562ac..a498a7368cff 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -343,6 +343,15 @@ struct mem_cgroup { extern struct mem_cgroup *root_mem_cgroup; +enum page_memcg_flags { + /* page->memcg_data is a pointer to an objcgs vector */ + PG_MEMCG_OBJ_CGROUPS, + /* the next bit after the last actual flag */ + PG_MEMCG_LAST_FLAG, +}; + +#define MEMCG_FLAGS_MASK ((1UL << PG_MEMCG_LAST_FLAG) - 1) + /* * page_mem_cgroup - get the memory cgroup associated with a page * @page: a pointer to the page struct @@ -371,13 +380,7 @@ static inline struct mem_cgroup *page_mem_cgroup_check(struct page *page) { unsigned long memcg_data = page->memcg_data; - /* - * 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 (test_bit(PG_MEMCG_OBJ_CGROUPS, &memcg_data)) return NULL; return (struct mem_cgroup *)memcg_data; @@ -422,7 +425,12 @@ static inline void clear_page_mem_cgroup(struct page *page) */ static inline struct obj_cgroup **page_obj_cgroups(struct page *page) { - return (struct obj_cgroup **)(page->memcg_data & ~0x1UL); + unsigned long memcg_data = page->memcg_data; + + VM_BUG_ON_PAGE(memcg_data && !test_bit(PG_MEMCG_OBJ_CGROUPS, + &memcg_data), page); + + return (struct obj_cgroup **)(memcg_data & ~MEMCG_FLAGS_MASK); } /* @@ -437,8 +445,8 @@ static inline struct obj_cgroup **page_obj_cgroups_check(struct page *page) { unsigned long memcg_data = page->memcg_data; - if (memcg_data && (memcg_data & 0x1UL)) - return (struct obj_cgroup **)(memcg_data & ~0x1UL); + if (memcg_data && test_bit(PG_MEMCG_OBJ_CGROUPS, &memcg_data)) + return (struct obj_cgroup **)(memcg_data & ~MEMCG_FLAGS_MASK); return NULL; } @@ -453,7 +461,11 @@ static inline struct obj_cgroup **page_obj_cgroups_check(struct page *page) static inline bool set_page_obj_cgroups(struct page *page, struct obj_cgroup **objcgs) { - return !cmpxchg(&page->memcg_data, 0, (unsigned long)objcgs | 0x1UL); + unsigned long memcg_data = (unsigned long)objcgs; + + __set_bit(PG_MEMCG_OBJ_CGROUPS, &memcg_data); + + return !cmpxchg(&page->memcg_data, 0, memcg_data); } /*