From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53BE8C43461 for ; Thu, 10 Sep 2020 20:29:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC780208A9 for ; Thu, 10 Sep 2020 20:29:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="fUzaoHtK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726226AbgIJU3p (ORCPT ); Thu, 10 Sep 2020 16:29:45 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:32508 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbgIJU1O (ORCPT ); Thu, 10 Sep 2020 16:27:14 -0400 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08AKJrOw023666 for ; Thu, 10 Sep 2020 13:27:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=XxNUBDmOoVw3gOdVvGhbAvoCC5sCTXFRDz+Ow4pwwjo=; b=fUzaoHtKqG2Pm5mnAB2cKq/M5eSkSnGkTh/S++X510JgDq9v3h4ZH19pxuT+hrEMgFFI lbtWy1Gln6h+IzmzvQz/RkQuxHUv+35uRyEihQJ+qVloSldB8ctx0rozhpftEVhqgOGs WJ+0+GrrNbipgUzhh3CB/oAlJO66I08Tzm0= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 33f8bfddw7-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 10 Sep 2020 13:27:11 -0700 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 10 Sep 2020 13:27:10 -0700 Received: by devvm1096.prn0.facebook.com (Postfix, from userid 111017) id A83D73D449B0; Thu, 10 Sep 2020 13:27:03 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm1096.prn0.facebook.com To: Andrew Morton , CC: =Shakeel Butt , Johannes Weiner , Michal Hocko , , , Roman Gushchin Smtp-Origin-Cluster: prn0c01 Subject: [PATCH rfc 0/5] mm: allow mapping accounted kernel pages to userspace Date: Thu, 10 Sep 2020 13:26:54 -0700 Message-ID: <20200910202659.1378404-1-guro@fb.com> X-Mailer: git-send-email 2.24.1 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-09-10_09:2020-09-10,2020-09-10 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 bulkscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 phishscore=0 adultscore=0 mlxscore=0 mlxlogscore=585 suspectscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009100183 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently a non-slab kernel page which has been charged to a memory cgroup can't be mapped to userspace. The underlying reason is simple: PageKmemcg flag is defined as a page type (like buddy, offline, etc), so it takes a bit from a page->mapped counter. Pages with a type set can't be mapped to userspace. But in general the kmemcg flag has nothing to do with mapping to userspace. It only means that the page has been accounted by the page allocator, so it has to be properly uncharged on release. Some bpf maps are mapping the vmalloc-based memory to userspace, and their memory can't be accounted because of this implementation detail. This patchset removes this limitation by moving the PageKmemcg flag into one of the free bits of the page->mem_cgroup pointer. Also it formalizes all accesses to the page->mem_cgroup and page->obj_cgroups using new helpers, adds several checks and removes a couple of obsolete functions. As the result the code became more robust with fewer open-coded bits tricks. The first patch in the series is a bugfix, which I already sent separatel= y. Including it in rfc to make the whole series compile. Roman Gushchin (5): mm: memcg/slab: fix racy access to page->mem_cgroup in mem_cgroup_from_obj() mm: memcontrol: use helpers to access page's memcg data mm: memcontrol/slab: use helpers to access slab page's memcg_data mm: introduce page memcg flags mm: convert page kmemcg type to a page memcg flag include/linux/memcontrol.h | 161 +++++++++++++++++++++++++++++-- include/linux/mm.h | 22 ----- include/linux/mm_types.h | 5 +- include/linux/page-flags.h | 11 +-- include/trace/events/writeback.h | 2 +- mm/debug.c | 4 +- mm/huge_memory.c | 4 +- mm/memcontrol.c | 116 ++++++++++------------ mm/migrate.c | 2 +- mm/page_alloc.c | 6 +- mm/page_io.c | 4 +- mm/slab.h | 28 +----- mm/workingset.c | 4 +- 13 files changed, 221 insertions(+), 148 deletions(-) --=20 2.26.2