From patchwork Thu Aug 27 17:52:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 11741227 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 0CE5F14F6 for ; Thu, 27 Aug 2020 17:52:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA319207CD for ; Thu, 27 Aug 2020 17:52:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="foGAK5Uq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA319207CD 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 17F838E0006; Thu, 27 Aug 2020 13:52:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 041548E0003; Thu, 27 Aug 2020 13:52:22 -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 DD6548E0006; Thu, 27 Aug 2020 13:52:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id C4DF88E0003 for ; Thu, 27 Aug 2020 13:52:22 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8525D4417 for ; Thu, 27 Aug 2020 17:52:22 +0000 (UTC) X-FDA: 77197092924.11.hair16_0406ce22706f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 46394180F8B82 for ; Thu, 27 Aug 2020 17:52:22 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=550855a34e=guro@fb.com,,RULES_HIT:30036:30054:30064,0,RBL:67.231.153.30:@fb.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04y8hhyqjj7ciur4nb5crqc9ft5fkypzjxxa9oj1fbbfwhet1p3qbakxw6ozq6q.zfax8fetn6fboyhi9xdb76azh459g5euqxme1hzyx81itwjzqpyykkt8ymtnxnk.c-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:25,LUA_SUMMARY:none X-HE-Tag: hair16_0406ce22706f X-Filterd-Recvd-Size: 4968 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Thu, 27 Aug 2020 17:52:21 +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 07RHpFFY009582 for ; Thu, 27 Aug 2020 10:52:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=GiSvtA9Y81I+jnIfUZtXBD50esug8S34EMBARaI7nmM=; b=foGAK5UqBbB+ZAGapE39yBPIE8Qge42QGP+OTLWgW6wstNydlIEUeOwHk3WUuLyx5qp6 Ircwsuy0TsTmB9v4GllxJEF+KpBYR2TGUBMEPLo3Rkgvp0nVtp4mkfcIId5xwK1jcsm2 2GU+ep1AEqxtK+aum6M0RjIdH6k/4x3agHA= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 335up66k17-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 27 Aug 2020 10:52:21 -0700 Received: from intmgw002.41.prn1.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 27 Aug 2020 10:52:19 -0700 Received: by devvm1096.prn0.facebook.com (Postfix, from userid 111017) id 3E5FD3922489; Thu, 27 Aug 2020 10:52:16 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm1096.prn0.facebook.com To: CC: Andrew Morton , =Shakeel Butt , Johannes Weiner , Michal Hocko , , , Roman Gushchin Smtp-Origin-Cluster: prn0c01 Subject: [PATCH RFC 4/4] mm: kmem: enable kernel memcg accounting from interrupt contexts Date: Thu, 27 Aug 2020 10:52:15 -0700 Message-ID: <20200827175215.319780-5-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200827175215.319780-1-guro@fb.com> References: <20200827175215.319780-1-guro@fb.com> 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-08-27_10:2020-08-27,2020-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 impostorscore=0 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 suspectscore=1 phishscore=0 mlxlogscore=798 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008270134 X-FB-Internal: deliver X-Rspamd-Queue-Id: 46394180F8B82 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: If a memcg to charge can be determined (using remote charging API), there are no reasons to exclude allocations made from an interrupt context from the accounting. Such allocations will pass even if the resulting memcg size will exceed the hard limit, but it will affect the application of the memory pressure and an inability to put the workload under the limit will eventually trigger the OOM. To use active_memcg() helper, memcg_kmem_bypass() is moved back to memcontrol.c. Signed-off-by: Roman Gushchin Reviewed-by: Shakeel Butt --- include/linux/memcontrol.h | 12 ------------ mm/memcontrol.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d0b036123c6a..924177502479 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1528,18 +1528,6 @@ static inline bool memcg_kmem_enabled(void) return static_branch_likely(&memcg_kmem_enabled_key); } -static inline bool memcg_kmem_bypass(void) -{ - if (in_interrupt()) - return true; - - /* Allow remote memcg charging in kthread contexts. */ - if ((!current->mm || (current->flags & PF_KTHREAD)) && - !current->active_memcg) - return true; - return false; -} - static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a51a6066079e..75cd1a1e66c8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1098,6 +1098,19 @@ static __always_inline struct mem_cgroup *get_active_memcg(void) return memcg; } +static __always_inline bool memcg_kmem_bypass(void) +{ + /* Allow remote memcg charging from any context. */ + if (unlikely(active_memcg())) + return false; + + /* Memcg to charge can't be determined. */ + if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD)) + return true; + + return false; +} + /** * If active memcg is set, do not fallback to current->mm->memcg. */