From patchwork Tue Sep 22 20:36:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 11793069 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 7689E618 for ; Tue, 22 Sep 2020 20:37:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D8B8235FD for ; Tue, 22 Sep 2020 20:37:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="WsGyqtPb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D8B8235FD 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 7F7316B005A; Tue, 22 Sep 2020 16:37:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7E07D6B005D; Tue, 22 Sep 2020 16:37:27 -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 489206B005C; Tue, 22 Sep 2020 16:37:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 254976B0055 for ; Tue, 22 Sep 2020 16:37:27 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E2464180AD806 for ; Tue, 22 Sep 2020 20:37:26 +0000 (UTC) X-FDA: 77291857692.22.cats09_610a1d527150 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id C289B18038E60 for ; Tue, 22 Sep 2020 20:37:26 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=65342fe525=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;04ygyrxirf58spna3bdkrm8qafeyiychurt9z6p11seb3wzs9yfr8a3gnu96p74.zq8wj9yi9x4yhyukeq8b7jkpwzysr4arsj4ew3fefkybh9k53ety5m4tncm1rf6.h-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: cats09_610a1d527150 X-Filterd-Recvd-Size: 4872 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 20:37:26 +0000 (UTC) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08MKZ0SG026677 for ; Tue, 22 Sep 2020 13:37:25 -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=QljWG4BanVKQ0V2dBu1N9GH2r7RFb4sjQmm/Vb841Uo=; b=WsGyqtPbJAIr7AJooDZ3CXBsgMdJ2Ph1m5snxMdPAygiYkieZRkNLl14KQqobBnPf3IY V6nB3F2BzBj12r+sQoGVCBP6Xc/uQ7Ablv9t54PmIrkjkiPgaJeyVpHTzr0/JNuPL02r ai/8dHhuW4Cr95zohiKpY5gdgIgqp1oluK8= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 33nfqu7th3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Sep 2020 13:37:25 -0700 Received: from intmgw004.06.prn3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) 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:24 -0700 Received: by devvm1755.vll0.facebook.com (Postfix, from userid 111017) id BB794864B57; 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 0/4] mm: allow mapping accounted kernel pages to userspace Date: Tue, 22 Sep 2020 13:36:56 -0700 Message-ID: <20200922203700.2879671-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-09-22_18:2020-09-21,2020-09-22 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 bulkscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 adultscore=0 mlxlogscore=457 mlxscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 spamscore=0 malwarescore=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: 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. 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 | 244 +++++++++++++++++++++++++++++-- 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 | 135 ++++++++--------- mm/migrate.c | 2 +- mm/page_alloc.c | 6 +- mm/page_io.c | 4 +- mm/slab.h | 28 +--- mm/workingset.c | 6 +- 16 files changed, 318 insertions(+), 166 deletions(-)