Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2446372ybl; Thu, 9 Jan 2020 12:56:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxueITme1B65NcTfKVorgW7dkvgBKoq45rhaBf8hX8h/dFe0csJF4PaSUrMckkuj3JvrSnT X-Received: by 2002:a05:6830:1d6a:: with SMTP id l10mr10493739oti.233.1578603415705; Thu, 09 Jan 2020 12:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578603415; cv=none; d=google.com; s=arc-20160816; b=sQy7zaUVJYZEPzB6yxHXVyR3Of8Z3zl+u+XZ+xVc9p3+zegHkB2BxpiAjCeNh0vbYm ohG4OQyQJst4yI0UNk+WLpa/paHrY2muKxkuPIUpHLczDJI+XZObLUCxEegzlOoNUZ6O wTXix29Oqz1H30SMPBlDXmCybs8+c958RRnpFP/nrYGII24bSqfiPWhAGy7tc0OB7WXF kysc7ZGbLWUQdW3fzG47b+X84gSkjU+iXr+FSqguAP0fgf53IwdDJXIPrsONnOb5EXpJ Ojjch7ub2QDltPcIvizgiAuOZ7X3gVTYlDYeNSbFs1Oy7lyNCODXRVVLHzpdldeCGpUK 4aNw== 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=rGgsGS/tWVyE9cLqfKHGOpozGq26BhblSUTNzP60qEo=; b=d4S9qLLd2Hlf6mGoCS0e/jy6g4ir/h1x7Zuhe5NZhDfsf7G4r0jSHtbl4d1rutu6Qr DPjpJMbXp/xAKQMV3v8aJbuc1SQMLdFoQOXla2RIwpnNJZP0FU27BTj7aXIzrLJ3CqQV PVTHOr4sLDkIgozDw9WjqP22KpKRKALJKhiugPJXMdH/L6PVamzVawdHNBgcx7W6q+CM SjMkE9uYXboY61DM9Feu24OshPzDYM5BXJCSeaa7S7df7Yc1mge76FJbSIoeVF9uJQvu XLgKazBIYbl4xDrxtyMj9QhRM/QbIjelYfh4SZz8cDhmKQlZprBLE4Y2jDxzpvXZI7F8 dtRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=qvy8RHJx; 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 k1si4182687oic.245.2020.01.09.12.56.44; Thu, 09 Jan 2020 12:56:55 -0800 (PST) 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=qvy8RHJx; 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 S1730212AbgAIU1P (ORCPT + 99 others); Thu, 9 Jan 2020 15:27:15 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:26986 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730126AbgAIU1P (ORCPT ); Thu, 9 Jan 2020 15:27:15 -0500 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 009KPj7t008585 for ; Thu, 9 Jan 2020 12:27:14 -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=rGgsGS/tWVyE9cLqfKHGOpozGq26BhblSUTNzP60qEo=; b=qvy8RHJxnWK0iFQeV6FyoWTS0n1jg9FUpzEANDuAdbu8T8n8CGHdPbhTICnsU7xF/KGu d9b6YS6KnEGnUC7anvzEb73BqWS2BM4dr132OB0gTy9J/4T8s8dj8qkHNALfpBNkm6t2 1l9Xr2Gm6Bvtjmvq7mPhC3UcXTCGdYE/sX4= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2xe2exu210-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 09 Jan 2020 12:27:14 -0800 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Thu, 9 Jan 2020 12:27:12 -0800 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 31F3B1D2F0DCA; Thu, 9 Jan 2020 12:27:07 -0800 (PST) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: , Andrew Morton CC: Michal Hocko , Johannes Weiner , Shakeel Butt , Vladimir Davydov , , , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH v2 4/6] mm: kmem: switch to nr_pages in (__)memcg_kmem_charge_memcg() Date: Thu, 9 Jan 2020 12:26:57 -0800 Message-ID: <20200109202659.752357-5-guro@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200109202659.752357-1-guro@fb.com> References: <20200109202659.752357-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:6.0.138,18.0.572 definitions=2020-01-09_04:2020-01-09,2020-01-09 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 phishscore=0 impostorscore=0 spamscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 clxscore=1015 adultscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-2001090168 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These functions are charging the given number of kernel pages to the given memory cgroup. The number doesn't have to be a power of two. Let's make them to take the unsigned int nr_pages as an argument instead of the page order. It makes them look consistent with the corresponding uncharge functions and functions like: mem_cgroup_charge_skmem(memcg, nr_pages). Signed-off-by: Roman Gushchin --- include/linux/memcontrol.h | 11 ++++++----- mm/memcontrol.c | 8 ++++---- mm/slab.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 4ee0c345e905..851c373edb74 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1364,7 +1364,8 @@ void memcg_kmem_put_cache(struct kmem_cache *cachep); #ifdef CONFIG_MEMCG_KMEM int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order); void __memcg_kmem_uncharge_page(struct page *page, int order); -int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order); +int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, + unsigned int nr_pages); void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, unsigned int nr_pages); @@ -1403,18 +1404,18 @@ static inline void memcg_kmem_uncharge_page(struct page *page, int order) } static inline int memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, - int order) + unsigned int nr_pages) { if (memcg_kmem_enabled()) - return __memcg_kmem_charge_memcg(memcg, gfp, order); + return __memcg_kmem_charge_memcg(memcg, gfp, nr_pages); return 0; } static inline void memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, - int order) + unsigned int nr_pages) { if (memcg_kmem_enabled()) - __memcg_kmem_uncharge_memcg(memcg, 1 << order); + __memcg_kmem_uncharge_memcg(memcg, nr_pages); } /* diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6bdf040e4615..8dbfb9fed9d8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2822,13 +2822,13 @@ void memcg_kmem_put_cache(struct kmem_cache *cachep) * __memcg_kmem_charge_memcg: charge a kmem page * @memcg: memory cgroup to charge * @gfp: reclaim mode - * @order: allocation order + * @nr_pages: number of pages to charge * * Returns 0 on success, an error code on failure. */ -int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, int order) +int __memcg_kmem_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp, + unsigned int nr_pages) { - unsigned int nr_pages = 1 << order; struct page_counter *counter; int ret; @@ -2872,7 +2872,7 @@ int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order) memcg = get_mem_cgroup_from_current(); if (!mem_cgroup_is_root(memcg)) { - ret = __memcg_kmem_charge_memcg(memcg, gfp, order); + ret = __memcg_kmem_charge_memcg(memcg, gfp, 1 << order); if (!ret) { page->mem_cgroup = memcg; __SetPageKmemcg(page); diff --git a/mm/slab.h b/mm/slab.h index e7da63fb8211..d96c87a30a9b 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -365,7 +365,7 @@ static __always_inline int memcg_charge_slab(struct page *page, return 0; } - ret = memcg_kmem_charge_memcg(memcg, gfp, order); + ret = memcg_kmem_charge_memcg(memcg, gfp, 1 << order); if (ret) goto out; -- 2.21.1