Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1130908pxb; Wed, 10 Feb 2021 00:21:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6sQck7t1fWgXFReDIRTlJw1T1n5D2cTvYZaP3d/CJsr6QEBlAToeRb3NtRCZLRU1ZHqy3 X-Received: by 2002:a17:906:2583:: with SMTP id m3mr1776301ejb.499.1612945287335; Wed, 10 Feb 2021 00:21:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612945287; cv=none; d=google.com; s=arc-20160816; b=yVzwAbHJIvO2n1+yxGgUiIeeSg0r6ULhd7X5HBpBPdEzxGHaoVV9shevAWujWavUmr Z815PAd9pLDIs9KsT3hMQDZDp7xcOzKeSCRWEJwxIW4Wd7YG+NgjbEHocMvazAum3eUh OoqAiZaDVz7zp91i4R1U1iFybnoygVnxF0OBD+ag5Iz9yWAhq7AZCDKUI8ASsbcKC0PG EI0PRZSwAxy91nkiR1cWXH2ZaDSs7iB4i67VsMuOCe4tA26MPkubDATcW9hp7D1TBlxu ST7LiqMHPBU5dRn2o8Cb2aUJsok+R0qUwxcEGfYj5Qq8CSLg/7/ZJe+eaGjzDx5TGhqh DQQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YMKTZdgN+ApLkWCndc7XhEgCcK+nIdQXAhjOxRLrovs=; b=N2vJ4x+2BWWsDFKT5/ZQ6THT0AesFTzNwoTpYR4vWuYXviPhgDa4dwo9A4aixghemN H+rfZEbaTlTkGDIU6P3KkR+jDVSNCx7HfZeOQi6TiMxPCgP+t2JTx7VWiDkQnNJQXSW0 QgY/SeqSrfAGi7D5npt1WFa6CeupLy7iPEHIbzJCVU+JdFPqtfzFqJVLdA/qW1VkFVxc efmWe3OGi3v2Wyuh3ejxaUyUQQ/eqJdNE7GnwYrA8s7iSn2S/bzUe3zYcDl7zzVKZ47U QkR+vsjc5K7H+GQnk9rZA6KBSgRbVQbqOahFvA+8J7bvmscK0fStyr8xjp9uSXbPeidF gFpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b="1ILh68/N"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f2si805194ejh.244.2021.02.10.00.21.03; Wed, 10 Feb 2021 00:21:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b="1ILh68/N"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234015AbhBJA35 (ORCPT + 99 others); Tue, 9 Feb 2021 19:29:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234203AbhBIU47 (ORCPT ); Tue, 9 Feb 2021 15:56:59 -0500 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02CCCC06174A for ; Tue, 9 Feb 2021 11:01:29 -0800 (PST) Received: by mail-qv1-xf31.google.com with SMTP id r13so9177429qvm.11 for ; Tue, 09 Feb 2021 11:01:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YMKTZdgN+ApLkWCndc7XhEgCcK+nIdQXAhjOxRLrovs=; b=1ILh68/NP5l/G7S16U0oxNfUCDuypDgiZHfAby/Q3FDossuYdKi04IofVJrtdlUv3h J0JpwX/TkNjlZGRKE+v4SQyd6HTyGJ+lQIjFzAR63oks20pvihdIuKhyJYeBRSQqiFxd Wacz1OSJzE1wMnzew7eaZevYCSl7JMJ3IYXqiv57tVrsDpyF6Usj44DuF1a9VpyHRkpn /zb/ySXsLtTjvZKa6CyMcXz73uizRxGZENJq8xXvS89p9JUYp4ALknig//YQ2rWUNaeK O3+Tx3bGp9of0fC3u3z7tw+/odYHMlkyR6e7Fy79ytBjXf1LVlo/3rmcJ1U17GfWrhjj jl3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YMKTZdgN+ApLkWCndc7XhEgCcK+nIdQXAhjOxRLrovs=; b=pLP609S0tJNLWZSwQl+yZcpVV6aVx2BhtmJgBEkSjuBVsKBisMwAiW/+Kmat2xKfj6 wpeDSuCYVy7zLONMJTk+MkwiA01bIIh0wSgUNA/UgO/jfthEdXz2vxVIqy1bn+T3KKz0 9cQf0AHGuMtXjeUjWb98UhAub3DfG3q8wsiuVQ6zfh8Q5oiBUjjXNqYmEBQUGofl3iV3 XCI4qPuVhs79yUMYUN0A47pUWQh7czyBxrb8fEttYUbN/XHj7QlPQ+Q9oNLEHl4lOcoc Pvdqa2ekmd8Dpkzj27trQGxOPXNWhxCS6AbTq7n8y9mEiOGu4OIV1ZwpKUJ+lRB1/KG6 7V3A== X-Gm-Message-State: AOAM532dgJ9I244/UP1dSlKwEbHrXSCJI8ivMlFisMOImBnoWS7zTw9g +tTguYRzYXvO9Q1BRjQFz4tifw== X-Received: by 2002:a0c:f986:: with SMTP id t6mr22149242qvn.15.1612897288164; Tue, 09 Feb 2021 11:01:28 -0800 (PST) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id 82sm2656726qkd.48.2021.02.09.11.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 11:01:27 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Muchun Song , Shakeel Butt , Michal Hocko , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH] fs: buffer: use raw page_memcg() on locked page Date: Tue, 9 Feb 2021 14:01:26 -0500 Message-Id: <20210209190126.97842-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org alloc_page_buffers() currently uses get_mem_cgroup_from_page() for charging the buffers to the page owner, which does an rcu-protected page->memcg lookup and acquires a reference. But buffer allocation has the page lock held throughout, which pins the page to the memcg and thereby the memcg - neither rcu nor holding an extra reference during the allocation are necessary. Use a raw page_memcg() instead. This was the last user of get_mem_cgroup_from_page(), delete it. Reported-by: Muchun Song Signed-off-by: Johannes Weiner --- fs/buffer.c | 4 ++-- include/linux/memcontrol.h | 7 ------- mm/memcontrol.c | 23 ----------------------- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 96c7604f69b3..dc5d3e22c493 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -847,7 +847,8 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, if (retry) gfp |= __GFP_NOFAIL; - memcg = get_mem_cgroup_from_page(page); + /* The page lock pins the memcg */ + memcg = page_memcg(page); old_memcg = set_active_memcg(memcg); head = NULL; @@ -868,7 +869,6 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, } out: set_active_memcg(old_memcg); - mem_cgroup_put(memcg); return head; /* * In case anything failed, we just free everything we got. diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index a8c7a0ccc759..a44b2d51aecc 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -687,8 +687,6 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm); -struct mem_cgroup *get_mem_cgroup_from_page(struct page *page); - struct lruvec *lock_page_lruvec(struct page *page); struct lruvec *lock_page_lruvec_irq(struct page *page); struct lruvec *lock_page_lruvec_irqsave(struct page *page, @@ -1169,11 +1167,6 @@ static inline struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) return NULL; } -static inline struct mem_cgroup *get_mem_cgroup_from_page(struct page *page) -{ - return NULL; -} - static inline void mem_cgroup_put(struct mem_cgroup *memcg) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 51778fa9b462..9e455815fb7a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1048,29 +1048,6 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) } EXPORT_SYMBOL(get_mem_cgroup_from_mm); -/** - * get_mem_cgroup_from_page: Obtain a reference on given page's memcg. - * @page: page from which memcg should be extracted. - * - * Obtain a reference on page->memcg and returns it if successful. Otherwise - * root_mem_cgroup is returned. - */ -struct mem_cgroup *get_mem_cgroup_from_page(struct page *page) -{ - struct mem_cgroup *memcg = page_memcg(page); - - if (mem_cgroup_disabled()) - return NULL; - - rcu_read_lock(); - /* Page should not get uncharged and freed memcg under us. */ - if (!memcg || WARN_ON_ONCE(!css_tryget(&memcg->css))) - memcg = root_mem_cgroup; - rcu_read_unlock(); - return memcg; -} -EXPORT_SYMBOL(get_mem_cgroup_from_page); - static __always_inline struct mem_cgroup *active_memcg(void) { if (in_interrupt()) -- 2.30.0