From patchwork Thu Sep 10 20:26:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 11769137 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 795FB698 for ; Thu, 10 Sep 2020 20:27:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2496D20BED for ; Thu, 10 Sep 2020 20:27:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="fUzaoHtK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2496D20BED 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 3EC52900006; Thu, 10 Sep 2020 16:27:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 37519900002; Thu, 10 Sep 2020 16:27:13 -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 23CD4900006; Thu, 10 Sep 2020 16:27:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id 0157D900002 for ; Thu, 10 Sep 2020 16:27:12 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B7D381DED for ; Thu, 10 Sep 2020 20:27:12 +0000 (UTC) X-FDA: 77248286304.18.mind41_3611457270e8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 79D46100EC667 for ; Thu, 10 Sep 2020 20:27:12 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=6522785d41=guro@fb.com,,RULES_HIT:30012:30054:30064,0,RBL:67.231.145.42:@fb.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10;04yraogiub3zdkb7cak3x9dui7c1mycu1mm1mfgwtctqob3zeppgktgu9643b3p.eo6k5x3u3kwu7simwfpn17tb3wzeynbhybtjjebceygnmdjqee9ud6wb8jukoeo.1-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: mind41_3611457270e8 X-Filterd-Recvd-Size: 4938 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Sep 2020 20:27:11 +0000 (UTC) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08AKK5dS026405 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 33fqw11a7j-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 10 Sep 2020 13:27:10 -0700 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c085:108::8) 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; 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 X-FB-Internal: Safe 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 adultscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=578 spamscore=0 malwarescore=0 phishscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009100183 X-FB-Internal: deliver X-Rspamd-Queue-Id: 79D46100EC667 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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. The first patch in the series is a bugfix, which I already sent separately. 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(-)