From patchwork Fri Oct 2 17:25:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 11814177 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 0887492C for ; Fri, 2 Oct 2020 17:26:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAA75208B6 for ; Fri, 2 Oct 2020 17:26:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="ltPwhT5g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAA75208B6 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 C2FAA6B0062; Fri, 2 Oct 2020 13:26:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BE0116B0068; Fri, 2 Oct 2020 13:26:06 -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 ACFA16B006C; Fri, 2 Oct 2020 13:26:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 812D46B0062 for ; Fri, 2 Oct 2020 13:26:06 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 05B05181AE863 for ; Fri, 2 Oct 2020 17:26:06 +0000 (UTC) X-FDA: 77327663532.28.wax21_2a14d67271a5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id C7F8A6C04 for ; Fri, 2 Oct 2020 17:26:05 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=75443b2d03=guro@fb.com,,RULES_HIT:30012:30054:30064,0,RBL:67.231.153.30:@fb.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04ygi5rjehi49twhsrsgp7zjmw45pypfnf6fc7ehpfa5fcq8mkeu1f3bsd7a6o3.uwtjdhnrcgzmpo7ubmxpup8e5kyane6zi59prqs4gtem19mi6rix94tudx9qnd6.n-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:24,LUA_SUMMARY:none X-HE-Tag: wax21_2a14d67271a5 X-Filterd-Recvd-Size: 5319 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Fri, 2 Oct 2020 17:26:05 +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 092HDuIn002385 for ; Fri, 2 Oct 2020 10:26:04 -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=N2oKeTPdqGNG/HeJnW3ZUvuaxAMKy3hOfq9GZwkiXIw=; b=ltPwhT5gklbuyglHE1UM2Rk/VfbadT6eCkYYL8UAFb2KSfkVEhQMxcZvSvsbK+wQFTpU zqbsvFDd4Q9r1j6gYgWHo+LfqAgESBj6Js3xMQNeNG71ZR25IxdioBzJqHhCTQbUtzMf 56wZca/Wwk067dgYrckPjIWsf2X1nljUYAs= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 33w05nbdgv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 02 Oct 2020 10:26:04 -0700 Received: from intmgw001.41.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 2 Oct 2020 10:26:03 -0700 Received: by devvm1755.vll0.facebook.com (Postfix, from userid 111017) id B4F58F1529B; Fri, 2 Oct 2020 10:26:00 -0700 (PDT) From: Roman Gushchin To: Andrew Morton CC: Shakeel Butt , Johannes Weiner , Michal Hocko , , , , Roman Gushchin Subject: [PATCH v5 0/4] mm: allow mapping accounted kernel pages to userspace Date: Fri, 2 Oct 2020 10:25:55 -0700 Message-ID: <20201002172559.4000748-1-guro@fb.com> X-Mailer: git-send-email 2.24.1 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-10-02_11:2020-10-02,2020-10-02 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 suspectscore=0 priorityscore=1501 mlxlogscore=582 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-2010020129 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. 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 cover.txt | 4 +- 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 +- 16 files changed, 302 insertions(+), 169 deletions(-)