From patchwork Tue Sep 22 20:36:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 11793075 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 5DA00618 for ; Tue, 22 Sep 2020 20:38:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1367B235FD for ; Tue, 22 Sep 2020 20:38:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="SxjqcTLZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1367B235FD 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 34A6F6B005D; Tue, 22 Sep 2020 16:38:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2FAF46B0062; Tue, 22 Sep 2020 16:38:11 -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 1EA6D6B0068; Tue, 22 Sep 2020 16:38:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 08F3C6B005D for ; Tue, 22 Sep 2020 16:38:11 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C06193633 for ; Tue, 22 Sep 2020 20:38:10 +0000 (UTC) X-FDA: 77291859540.12.aunt22_62102c127150 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 9D84C18015313 for ; Tue, 22 Sep 2020 20:38:10 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=65342fe525=guro@fb.com,,RULES_HIT:30054:30064,0,RBL:67.231.145.42:@fb.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10;04yrq3ru3wuz3451wb7gthjiw5zf1opdcoywfcjhyce13s4par1bxdrpmpp6gcu.bifc4gc9uf7jqcc4q1gxigmz4z3gdrqix9mkoyhezjf4qmgkpcntsmcx9rirwai.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: aunt22_62102c127150 X-Filterd-Recvd-Size: 5660 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 20:38:09 +0000 (UTC) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08MKbeuF011486 for ; Tue, 22 Sep 2020 13:38:08 -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=OWbgJScCJjF4/NDWKw0S32FO6Lo1EgQ3Xsl+NSkPRIo=; b=SxjqcTLZqfEwQjEkJs1vmv07QIDmijGLUukfXm6S3ebLowY9/p8zh6P3u1jgjOcChTrQ j7Nx8Icpc8dXrqp84FnQtw/OUcBPDOD8UlcJS5xbExDlKw8Bb5QghKpcl8lEav3ZOgd5 o5VAziIpDIQHjpQjeR5Airn6nz7B2/QHglg= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 33p1ftd5ba-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Sep 2020 13:38:08 -0700 Received: from intmgw002.41.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 22 Sep 2020 13:37:25 -0700 Received: by devvm1755.vll0.facebook.com (Postfix, from userid 111017) id D5FB2864B5E; Tue, 22 Sep 2020 13:37:21 -0700 (PDT) From: Roman Gushchin To: Andrew Morton CC: Shakeel Butt , Johannes Weiner , Michal Hocko , , , , Roman Gushchin Subject: [PATCH v1 3/4] mm: introduce page memcg flags Date: Tue, 22 Sep 2020 13:36:59 -0700 Message-ID: <20200922203700.2879671-4-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200922203700.2879671-1-guro@fb.com> References: <20200922203700.2879671-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-22_18:2020-09-21,2020-09-22 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 mlxscore=0 malwarescore=0 phishscore=0 mlxlogscore=258 priorityscore=1501 clxscore=1015 spamscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009220161 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(). Few additional flags might be added later. Flags are intended to be mutually exclusive. Signed-off-by: Roman Gushchin --- include/linux/memcontrol.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index ab3ea3e90583..9a49f1e1c0c7 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -343,6 +343,11 @@ 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, +}; + /* * page_mem_cgroup - get the memory cgroup associated with a page * @page: a pointer to the page struct @@ -371,13 +376,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 +421,13 @@ 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); + __clear_bit(PG_MEMCG_OBJ_CGROUPS, &memcg_data); + + return (struct obj_cgroup **)memcg_data; } /* @@ -437,7 +442,7 @@ 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)) + if (memcg_data && test_bit(PG_MEMCG_OBJ_CGROUPS, &memcg_data)) return (struct obj_cgroup **)memcg_data; return NULL; @@ -453,7 +458,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); } /*