Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp71050pxk; Wed, 30 Sep 2020 18:14:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHN2qThmZDYK5qDM76cUNQQ6x3A+EP1560kSsvwTE51olAOgteQlDsiesGAvo2zx6gZXaW X-Received: by 2002:a17:906:ae50:: with SMTP id lf16mr5456866ejb.343.1601514896661; Wed, 30 Sep 2020 18:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601514896; cv=none; d=google.com; s=arc-20160816; b=HxygeHE9Fy04LhJbCXK23yI/aF3nesHrQt3/dQBdYkfl4kSrD/Hsk2AnKYCGXQqGXE ODwhs5FdU+p4t00FTRo7GO+nvwG4EDzACW9fkJjDcRVokejrJRtPDkfTV54lriKjmqkI QHnt4vbVDvnqO8zW0ZeOzuOpw18aOyztycjvbd1BYxHLcz95BuLQZ4ZELRZpxsUrOerA RlhiCQVF6PKJflX1RbbLjls7622hRd3NHIWT17E/I3Gp7lycleQS5ZLqIySoretB/WsR EkMfJFatvfhUTrb0TXbphksKS+RqWwIIzZ28WSyVak0LhIHGOzJCa0MIn8aDuF+U1Kjs 3sYQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=nxkYWmR9uHeb56di1Os7YYMXD4UUaIBrdPMR7dN2WgA=; b=HiI1il3D4AINCdX6Zh0T1ty2WdyBKM8hkFOzBw9+mFJTi5WAt48/TScge/wSB7yWab yt0rPXVTaH5Tz7dA9R/Lb9fE2gDNczqNaB0qv5i9Z6iGytHjeM3ymLd2niukgsFwbmxG Rq3bZR3X3ShgvJvP0Wm+KweKmZBo6yHGofZW0qPGa+80RqGZIhoVAtkCtjKoYM9mtpPb XeY89S0HfGKXENOPn6aU/878IHu75Ak1Lr3HrfdCjGpAytL1dQjlAXO6qdQerlCo/aoL 67VO+dkmbln7J+vIK9jjKuEvpEndzQs+L75SrFlvr9LgctZUphRJnteL8gi45LIcV8EQ EQ0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=AmS+dOR1; 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 h12si2691237ejx.291.2020.09.30.18.14.33; Wed, 30 Sep 2020 18:14:56 -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=AmS+dOR1; 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 S1732025AbgJAA1n (ORCPT + 99 others); Wed, 30 Sep 2020 20:27:43 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:36634 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730703AbgJAA1n (ORCPT ); Wed, 30 Sep 2020 20:27:43 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 0910RdMO005973 for ; Wed, 30 Sep 2020 17:27:42 -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=nxkYWmR9uHeb56di1Os7YYMXD4UUaIBrdPMR7dN2WgA=; b=AmS+dOR1TpaKANUAoIm4Wc9MwmsJfF5gvMuKdWFB4vCb+85Xp4jkfvIHrPiwD0KdIQqx l40ODsxbzKut1oKdcsODB+Olbvg1fdL+Y0QHreifRfW3TqeNqDO4EnWYmNz8mVqo4sU4 VQCt77fLDqwgcan/YDkNb7NN9qJ3ES9LgBI= Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net with ESMTP id 33w05n1hhj-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 30 Sep 2020 17:27:42 -0700 Received: from intmgw004.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; Wed, 30 Sep 2020 17:27:19 -0700 Received: by devvm1755.vll0.facebook.com (Postfix, from userid 111017) id BFB48DE9665; Wed, 30 Sep 2020 17:27:17 -0700 (PDT) From: Roman Gushchin To: Andrew Morton CC: Shakeel Butt , Johannes Weiner , Michal Hocko , , , , Roman Gushchin Subject: [PATCH v4 0/4] mm: allow mapping accounted kernel pages to userspace Date: Wed, 30 Sep 2020 17:27:06 -0700 Message-ID: <20201001002710.748166-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-30_13:2020-09-30,2020-09-30 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 suspectscore=0 priorityscore=1501 mlxlogscore=543 impostorscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010010002 X-FB-Internal: deliver 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. v4: - more cosmetic changes, by Johannes v3: - READ_ONCE() in page_memcg_rcu() and page_objcgs*(), by Johannes - many cosmetic changes and renamings, by Johannes v2: - fixed a bug in page_obj_cgroups_check() - moved some definitions between patches, by Shakeel - dropped the memcg flags mutual exclusion requirement, by Shakeel v1: - added and fixed comments, by Shakeel - added some VM_BUG_ON() checks - fixed the debug output format of page->memcg_data Roman Gushchin (4): 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 fs/buffer.c | 2 +- fs/iomap/buffered-io.c | 2 +- include/linux/memcontrol.h | 242 +++++++++++++++++++++++++++++-- include/linux/mm.h | 22 --- include/linux/mm_types.h | 5 +- include/linux/page-flags.h | 11 +- include/trace/events/writeback.h | 2 +- kernel/fork.c | 7 +- mm/debug.c | 4 +- mm/huge_memory.c | 4 +- mm/memcontrol.c | 139 ++++++++---------- mm/page_alloc.c | 8 +- mm/page_io.c | 6 +- mm/slab.h | 38 ++--- mm/workingset.c | 2 +- 15 files changed, 327 insertions(+), 167 deletions(-) --=20 2.26.2