Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5306418ybi; Tue, 11 Jun 2019 23:54:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIrv4r0aGbS+we4KspMIZxBqLnsREMc4XpX8ABKdfy8bgwS2BZKY/vb7mskcAiJy08aldJ X-Received: by 2002:a17:902:b696:: with SMTP id c22mr76861980pls.119.1560322440715; Tue, 11 Jun 2019 23:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560322440; cv=none; d=google.com; s=arc-20160816; b=jtvx3ihbbHEg8O7HCtudHFWULPp5j6FsA3XxB6gnKvzW2UJEw7LeRoaiBqQsNs1+yt r1obqQvnTFvKk6ezB9g7pwa4WauT1EFLX1Rshb65BCrzGz0wght+FBq0LEw/jbVlXIx5 MlFuPg3+E0TtdrKZb+tvT38S67guFvifxzjLMDjTClF4bjR74nEx0YMhIHDa9/9JVEnC E3gzg44OiGAnAcENktBXYls53UQCWq04+nGbkbgX55VrN4Z5/T2lGksaDyTzVZivaZH5 TcAa3wHH0OoovgzPUGhUQ090cJNjeHIsXHZbJsfDG+LWgKo+1dvDD3dv8QkrU+7ESMrq ndLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature; bh=JhIs3/HCydWffB+uV1RGxA08DRLtLPsTTqEKxSMP1fY=; b=jgMIBhlDDzOokk32sgSNJ15CpqF8ixlmnF+BM2IdE1hN5hhoG3Ur7llDGCOYpKuznT WlaUjL5d3BXUaN0iGahJW6k1cD6nlZyGVgAkZgm6Rbg8Oun38Bmfzdk34zIFsIhXaTzZ JlJlalgy9VOZaF0cwOGWduasjdRMM/AMvrmrZQMpkaET+o9RwhkoDumvpZ7LKhiszAhG 8mZyw8MHfIP1KdesX5wbf3aytidRL25Zpj1ueRZlKDspWojQiNVqCH6FQ1c4qDp+ub2S W0E5w6K+Q3sELKXjGWK2dRvamyFUBTPZ9OvCdFPQrb70x63Gi0wBZX63bIR6G01rgOT4 tItw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Zk3BS+Qo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g13si11452371pgr.577.2019.06.11.23.53.41; Tue, 11 Jun 2019 23:54:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=Zk3BS+Qo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408078AbfFKXSt (ORCPT + 99 others); Tue, 11 Jun 2019 19:18:49 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:39260 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408031AbfFKXSd (ORCPT ); Tue, 11 Jun 2019 19:18:33 -0400 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5BNAEP9024730 for ; Tue, 11 Jun 2019 16:18:32 -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-type; s=facebook; bh=JhIs3/HCydWffB+uV1RGxA08DRLtLPsTTqEKxSMP1fY=; b=Zk3BS+QoAeRg4WWCaz05ocuVThlNe41m7dPL12u8XO0/tdXd0hGBEwMvHnFYHMreoq+Z vKyranxiKgeotgqqiTLUQHMhhBrp9CLOU5qIcgjkIWnDW1xx41kANpgts1x+5GG0cFQP FmeXRqW/Nx9lpVsVLV4vcMTRwEiWmZEI4qQ= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2t2n4j04ug-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 11 Jun 2019 16:18:32 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Tue, 11 Jun 2019 16:18:22 -0700 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 35E75130CBF6D; Tue, 11 Jun 2019 16:18:20 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: Andrew Morton , Vladimir Davydov CC: , , , Johannes Weiner , Shakeel Butt , Waiman Long , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH v7 04/10] mm: introduce __memcg_kmem_uncharge_memcg() Date: Tue, 11 Jun 2019 16:18:07 -0700 Message-ID: <20190611231813.3148843-5-guro@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190611231813.3148843-1-guro@fb.com> References: <20190611231813.3148843-1-guro@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-11_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=942 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906110151 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's separate the page counter modification code out of __memcg_kmem_uncharge() in a way similar to what __memcg_kmem_charge() and __memcg_kmem_charge_memcg() work. This will allow to reuse this code later using a new memcg_kmem_uncharge_memcg() wrapper, which calls __memcg_kmem_uncharge_memcg() if memcg_kmem_enabled() check is passed. Signed-off-by: Roman Gushchin Reviewed-by: Shakeel Butt Acked-by: Vladimir Davydov --- include/linux/memcontrol.h | 10 ++++++++++ mm/memcontrol.c | 25 +++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 3ca57bacfdd2..9abf31bbe53a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1304,6 +1304,8 @@ int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order); void __memcg_kmem_uncharge(struct page *page, int order); int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, struct mem_cgroup *memcg); +void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, + unsigned int nr_pages); extern struct static_key_false memcg_kmem_enabled_key; extern struct workqueue_struct *memcg_kmem_cache_wq; @@ -1345,6 +1347,14 @@ static inline int memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, return __memcg_kmem_charge_memcg(page, gfp, order, memcg); return 0; } + +static inline void memcg_kmem_uncharge_memcg(struct page *page, int order, + struct mem_cgroup *memcg) +{ + if (memcg_kmem_enabled()) + __memcg_kmem_uncharge_memcg(memcg, 1 << order); +} + /* * helper for accessing a memcg's index. It will be used as an index in the * child cache array in kmem_cache, and also to derive its name. This function diff --git a/mm/memcontrol.c b/mm/memcontrol.c index be9344777b29..8eaf553b67f1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2812,6 +2812,22 @@ int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order) css_put(&memcg->css); return ret; } + +/** + * __memcg_kmem_uncharge_memcg: uncharge a kmem page + * @memcg: memcg to uncharge + * @nr_pages: number of pages to uncharge + */ +void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, + unsigned int nr_pages) +{ + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + page_counter_uncharge(&memcg->kmem, nr_pages); + + page_counter_uncharge(&memcg->memory, nr_pages); + if (do_memsw_account()) + page_counter_uncharge(&memcg->memsw, nr_pages); +} /** * __memcg_kmem_uncharge: uncharge a kmem page * @page: page to uncharge @@ -2826,14 +2842,7 @@ void __memcg_kmem_uncharge(struct page *page, int order) return; VM_BUG_ON_PAGE(mem_cgroup_is_root(memcg), page); - - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) - page_counter_uncharge(&memcg->kmem, nr_pages); - - page_counter_uncharge(&memcg->memory, nr_pages); - if (do_memsw_account()) - page_counter_uncharge(&memcg->memsw, nr_pages); - + __memcg_kmem_uncharge_memcg(memcg, nr_pages); page->mem_cgroup = NULL; /* slab pages do not have PageKmemcg flag set */ -- 2.21.0