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 EA21CC4363A for ; Tue, 27 Oct 2020 00:17:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7893920754 for ; Tue, 27 Oct 2020 00:17:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="hfO9HlAs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7893920754 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 59FC16B0072; Mon, 26 Oct 2020 20:17:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B3986B0073; Mon, 26 Oct 2020 20:17:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 308416B0074; Mon, 26 Oct 2020 20:17:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id E71896B0072 for ; Mon, 26 Oct 2020 20:17:18 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 904CD1EE6 for ; Tue, 27 Oct 2020 00:17:18 +0000 (UTC) X-FDA: 77415790956.23.thumb49_371094a27277 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 6EC3237606 for ; Tue, 27 Oct 2020 00:17:18 +0000 (UTC) X-HE-Tag: thumb49_371094a27277 X-Filterd-Recvd-Size: 5383 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 27 Oct 2020 00:17:17 +0000 (UTC) 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 09R0CrgK002883 for ; Mon, 26 Oct 2020 17:17:17 -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=41NXwfOK69YLdJBmqXAfvRcowfw7CrS/L8kIz565Jvg=; b=hfO9HlAsFioDdoA2P1f8QfIHhJJlVlAhYPIvjhmVw0qZusMykNZsgXM/cc7Tij5Gwi5h kQCslzPEF2KshEqYxKpLzNESdiNrzmA9KZixMq2dh3JTAO2uqtCWTlCHX1EHkjnRJ1TA wjREkZIby3p/Cve5JSSlOvYKZms9tA8FL3E= Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net with ESMTP id 34cfxn3tkw-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2020 17:17:17 -0700 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 26 Oct 2020 17:17:14 -0700 Received: by devvm1755.vll0.facebook.com (Postfix, from userid 111017) id 710721C56453; Mon, 26 Oct 2020 17:17:04 -0700 (PDT) From: Roman Gushchin To: Andrew Morton CC: Shakeel Butt , Johannes Weiner , Michal Hocko , , , , Roman Gushchin Subject: [PATCH v6 0/4] mm: allow mapping accounted kernel pages to userspace Date: Mon, 26 Oct 2020 17:16:53 -0700 Message-ID: <20201027001657.3398190-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.737 definitions=2020-10-26_17:2020-10-26,2020-10-26 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 impostorscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 spamscore=0 mlxscore=0 clxscore=1015 phishscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=734 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010270000 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: 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 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 bit tricks. v6: - removed a bogus change in the last commit - rebased to the current head with a minor fix v5: - added ~MEMCG_DATA_FLAGS_MASK to page_memcg_rcu(), by Michal - more cosmetic changes, by Johannes 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 read 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 | 215 +++++++++++++++++++++++++++++-- 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, 300 insertions(+), 167 deletions(-) --=20 2.26.2