Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6132328ybi; Tue, 4 Jun 2019 19:47:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHZiljqE0jX3sIDcIppah4sxL3LKmHJk7/s+AnlCGuNqij26CIZY8ExQPbc0o5c18lrBSS X-Received: by 2002:a63:330b:: with SMTP id z11mr1000453pgz.407.1559702858971; Tue, 04 Jun 2019 19:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559702858; cv=none; d=google.com; s=arc-20160816; b=nFWrJOO2pixkt4JZEuEWonmXFaylyWQga76IHIHnFFYIFu3ync8L8YjWAvPwSKY+ny Q9pjy9pozhShyP0owqxL5ZmmK2sn+XL3oQWCD3d948TM9kLQMuciAhE6n8g6/86/F76G L8nD2U/BJEW4qaosSz6rI3ywUrciBHPI9IBEtDRZ7f014Cy5K/SCF8WiMDVyu5sRRowB IMMX51KIceM4hyQwKhoV0WMW7A7f4TwDp6NG/UEbfwo3haKWrmbLv6kbxIFMLztUItkz aOrJCkk6Gb9m/6nX6wfxujwp+1VIBkiu0RvHjvCa5a2p6Zu+AN0KKBm7p66GJ76B9iBJ FmhA== 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=kSMcIoZOy8bv6oPhIhSwMshcDK0XomRQ4uXD2a50jbU=; b=BzToPW+e6Hk0KCZtqt2Q/AzLfr9QJYmkCFsr5h88jIc+RZVZGPKkBpvXfTpKm10NPA WMhj+tGwAltu150YMACYSlbIkQnC3CD+5BrosVF8QqPQ9D1MlivzApzhr0KT9HvtBraB r1ZhO/3jFEoCkyO82MDR/tAuGsH+BqZoTEGPK5ZWeIHB96V+1+xGHkTLhOlIlinYm4aG 3RyAgv9QZ4J+lxxt0rMRJ7souISiG6ROJiMvWHLgsAZ0+23B0G9ElEbrNTHSdzm0u66v N9IydjA3N8clbIX6hVepUkCFEskOsbqaufCLoC0UpuVJgJp0GQkEjplEfj5ScUzxfEBZ vfYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=oAw7uVY1; 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 v4si24110157pgr.475.2019.06.04.19.47.22; Tue, 04 Jun 2019 19:47:38 -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=oAw7uVY1; 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 S1726826AbfFECpa (ORCPT + 99 others); Tue, 4 Jun 2019 22:45:30 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:46410 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726645AbfFECpE (ORCPT ); Tue, 4 Jun 2019 22:45:04 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x552hZud009253 for ; Tue, 4 Jun 2019 19:45:03 -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=kSMcIoZOy8bv6oPhIhSwMshcDK0XomRQ4uXD2a50jbU=; b=oAw7uVY12LZ2xbms08qwfD8NE4cyI/1+y+8BI8DKv6UEG/gLTJUBKxEGxa2NWIu4HGq5 HRTcpwgTAToVDVUjrfe4gFCStwtKmP8QsTVU3TJ2F1LCaJ0JvFMjHb4OibE7hXY7EYfD ye9dcGmDdcu4Y7DbND0nfS9F49dQ+GIxU5Y= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2sx0j78sds-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 04 Jun 2019 19:45:02 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 4 Jun 2019 19:45:00 -0700 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 87DB812C7FDCA; Tue, 4 Jun 2019 19:44:58 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: Andrew Morton CC: , , , Johannes Weiner , Shakeel Butt , Vladimir Davydov , Waiman Long , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH v6 05/10] mm: introduce __memcg_kmem_uncharge_memcg() Date: Tue, 4 Jun 2019 19:44:49 -0700 Message-ID: <20190605024454.1393507-6-guro@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190605024454.1393507-1-guro@fb.com> References: <20190605024454.1393507-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-05_02:,, 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=903 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906050015 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 --- 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 bdb66871cdec..3427396da612 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2731,6 +2731,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 @@ -2745,14 +2761,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.20.1