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=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 A967EC35247 for ; Wed, 5 Feb 2020 22:45:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 486F8214AF for ; Wed, 5 Feb 2020 22:45:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="KBUp+xcU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 486F8214AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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 C1A0F6B0003; Wed, 5 Feb 2020 17:45:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCA356B0005; Wed, 5 Feb 2020 17:45:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B07D26B0006; Wed, 5 Feb 2020 17:45:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 9835F6B0003 for ; Wed, 5 Feb 2020 17:45:33 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4B505181AEF0B for ; Wed, 5 Feb 2020 22:45:33 +0000 (UTC) X-FDA: 76457556546.03.crib63_6a9fa0b8d371d X-HE-Tag: crib63_6a9fa0b8d371d X-Filterd-Recvd-Size: 4935 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Wed, 5 Feb 2020 22:45:32 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 015MdSQJ026504 for ; Wed, 5 Feb 2020 14:45:31 -0800 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-type; s=facebook; bh=F6dUXi+Yf0UlXl+ofbpSzuc0/nL9XeCvPBtkE6b86b4=; b=KBUp+xcUOGS8tIL9k8SX9QyBKX1UYLgCHMvIUVHIzSEgf1Dyt0/Vqrok/YV0iGciZmZw KXf12TkplQ8DCge9zvt6Uf0ZU0g6xqmrnkGOp4rb9jJ96gWv8j9cB5NR47E1HbjfIa03 F+M1u8GB/PdgLBOKAxaJ/bjtd4xRcFfeif8= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 2xyhm1nhsr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 05 Feb 2020 14:45:31 -0800 Received: from intmgw004.03.ash8.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 5 Feb 2020 14:45:30 -0800 Received: by devvm5228.lla1.facebook.com (Postfix, from userid 119756) id 9F428BE3DAEA; Wed, 5 Feb 2020 14:35:25 -0800 (PST) Smtp-Origin-Hostprefix: devvm From: Dan Schatzberg Smtp-Origin-Hostname: devvm5228.lla1.facebook.com To: CC: Dan Schatzberg , Jens Axboe , Tejun Heo , Li Zefan , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Hugh Dickins , "open list:BLOCK LAYER" , open list , "open list:CONTROL GROUP (CGROUP)" , "open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)" Smtp-Origin-Cluster: lla1c31 Subject: [PATCH 1/2] mm: Charge current memcg when no mm is set Date: Wed, 5 Feb 2020 14:33:47 -0800 Message-ID: <20200205223348.880610-2-dschatzberg@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200205223348.880610-1-dschatzberg@fb.com> References: <20200205223348.880610-1-dschatzberg@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-05_06:2020-02-04,2020-02-05 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 bulkscore=0 mlxscore=0 phishscore=0 impostorscore=0 suspectscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002050174 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: This modifies the shmem and mm charge logic so that now if there is no mm set (as in the case of tmpfs backed loop device), we charge the current memcg, if set. Signed-off-by: Dan Schatzberg --- mm/memcontrol.c | 11 ++++++++--- mm/shmem.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c5b5f74cfd4d..5a6ab3183525 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6354,7 +6354,8 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, * @compound: charge the page as compound or small page * * Try to charge @page to the memcg that @mm belongs to, reclaiming - * pages according to @gfp_mask if necessary. + * pages according to @gfp_mask if necessary. If @mm is NULL, try to + * charge to the active memcg. * * Returns 0 on success, with *@memcgp pointing to the charged memcg. * Otherwise, an error code is returned. @@ -6398,8 +6399,12 @@ int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, } } - if (!memcg) - memcg = get_mem_cgroup_from_mm(mm); + if (!memcg) { + if (!mm) + memcg = get_mem_cgroup_from_current(); + else + memcg = get_mem_cgroup_from_mm(mm); + } ret = try_charge(memcg, gfp_mask, nr_pages); diff --git a/mm/shmem.c b/mm/shmem.c index 165fa6332993..014e576a617b 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1766,7 +1766,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, } sbinfo = SHMEM_SB(inode->i_sb); - charge_mm = vma ? vma->vm_mm : current->mm; + charge_mm = vma ? vma->vm_mm : NULL; page = find_lock_entry(mapping, index); if (xa_is_value(page)) { -- 2.17.1