From patchwork Fri Sep 9 11:16:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 12971597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 880D2ECAAA1 for ; Fri, 9 Sep 2022 11:32:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27C6C8D0005; Fri, 9 Sep 2022 07:32:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 205758D0002; Fri, 9 Sep 2022 07:32:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A6228D0005; Fri, 9 Sep 2022 07:32:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EFA278D0002 for ; Fri, 9 Sep 2022 07:32:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CC93F412BC for ; Fri, 9 Sep 2022 11:32:07 +0000 (UTC) X-FDA: 79892333094.23.0301352 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [85.220.165.71]) by imf24.hostedemail.com (Postfix) with ESMTP id 48D1A1800AC for ; Fri, 9 Sep 2022 11:32:07 +0000 (UTC) Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1oWc04-0002dP-2x; Fri, 09 Sep 2022 13:16:44 +0200 From: Lucas Stach To: linux-mm@kvack.org, dri-devel@lists.freedesktop.org Cc: Daniel Vetter , David Airlie , Andrew Morton , Michal Hocko , =?utf-8?q?Christian_K=C3=B6nig?= , linux-fsdevel@vger.kernel.org, kernel@pengutronix.de Subject: [RFC PATCH 1/5] mm: add MM_DRIVERPAGES Date: Fri, 9 Sep 2022 13:16:36 +0200 Message-Id: <20220909111640.3789791-2-l.stach@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909111640.3789791-1-l.stach@pengutronix.de> References: <20220909111640.3789791-1-l.stach@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mm@kvack.org ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of l.stach@pengutronix.de designates 85.220.165.71 as permitted sender) smtp.mailfrom=l.stach@pengutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662723127; a=rsa-sha256; cv=none; b=iqYC0Y8f156ULUmKIYzdyHo9oWKIObEqaDJibloFxUFBI1dSGGSTkGXlB58cKvyCL3OGM3 2bE45yyD5MdBaYbhkyxPfO+RjSEbk6+i22ZJMpmftIlnnYX/o/ZM2RnSLWZ++SoQu30jaO 1yeBusMuzKL/8F+2cZCAmys4rMrqyX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662723127; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eaml+Iz7FW9vitLC5tsN/ex2hkOyNtHfirX90JZzfVM=; b=WmxgJonBwSsAZaDOQ7SfhGLAtRuFZmwOAKt+Ln0xQFx30h7M6M9ZxTJv4d3yrmF5EOrRBw roXWk7R+iFt+Ri4iXi9Q7lDKav0BIgrV+WLbRSTrWjUIGOw1Vm2H+eqiCuvsW+0Evkgo9o zhs0PkuoDOY3U1bo6PS+gmZr+iM3MFU= Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of l.stach@pengutronix.de designates 85.220.165.71 as permitted sender) smtp.mailfrom=l.stach@pengutronix.de X-Rspam-User: X-Rspamd-Server: rspam01 X-Stat-Signature: zpxp4w4ygoferhsaotrcgohomde3f47w X-Rspamd-Queue-Id: 48D1A1800AC X-HE-Tag: 1662723127-93749 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 adds a mm counter for pages allocated by a driver on behalf of a userspace task. Especially with DRM drivers there can be large amounts of pages that are never mapped into userspace and thus are not tracked by the usual ANONPAGES mmap accounting, as those pages are only ever touched by the device. They can make up a significant portion of the tasks resident memory size, but are currently not visible in any of the memory statistics visible to userspace and the OOM handling. Add the counter to allow tracking such memory, which allows to make more sensible decisions in the OOM handling as well as allowing userspace some better insight into the real system memory usage. Signed-off-by: Lucas Stach --- fs/proc/task_mmu.c | 6 ++++-- include/linux/mm.h | 3 ++- include/linux/mm_types_task.h | 1 + kernel/fork.c | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index a3398d0f1927..80b095a233bf 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -33,7 +33,8 @@ void task_mem(struct seq_file *m, struct mm_struct *mm) unsigned long text, lib, swap, anon, file, shmem; unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss; - anon = get_mm_counter(mm, MM_ANONPAGES); + anon = get_mm_counter(mm, MM_ANONPAGES) + + get_mm_counter(mm, MM_DRIVERPAGES); file = get_mm_counter(mm, MM_FILEPAGES); shmem = get_mm_counter(mm, MM_SHMEMPAGES); @@ -94,7 +95,8 @@ unsigned long task_statm(struct mm_struct *mm, *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> PAGE_SHIFT; *data = mm->data_vm + mm->stack_vm; - *resident = *shared + get_mm_counter(mm, MM_ANONPAGES); + *resident = *shared + get_mm_counter(mm, MM_ANONPAGES) + + get_mm_counter(mm, MM_DRIVERPAGES); return mm->total_vm; } diff --git a/include/linux/mm.h b/include/linux/mm.h index 3bedc449c14d..2cc014d1ea27 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2003,7 +2003,8 @@ static inline unsigned long get_mm_rss(struct mm_struct *mm) { return get_mm_counter(mm, MM_FILEPAGES) + get_mm_counter(mm, MM_ANONPAGES) + - get_mm_counter(mm, MM_SHMEMPAGES); + get_mm_counter(mm, MM_SHMEMPAGES) + + get_mm_counter(mm, MM_DRIVERPAGES); } static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm) diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h index c1bc6731125c..420d88e79906 100644 --- a/include/linux/mm_types_task.h +++ b/include/linux/mm_types_task.h @@ -45,6 +45,7 @@ enum { MM_ANONPAGES, /* Resident anonymous pages */ MM_SWAPENTS, /* Anonymous swap entries */ MM_SHMEMPAGES, /* Resident shared memory pages */ + MM_DRIVERPAGES, /* pages allocated by a driver on behalf of a task */ NR_MM_COUNTERS }; diff --git a/kernel/fork.c b/kernel/fork.c index 90c85b17bf69..74a07a2288ba 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -135,6 +135,7 @@ static const char * const resident_page_types[] = { NAMED_ARRAY_INDEX(MM_ANONPAGES), NAMED_ARRAY_INDEX(MM_SWAPENTS), NAMED_ARRAY_INDEX(MM_SHMEMPAGES), + NAMED_ARRAY_INDEX(MM_DRIVERPAGES), }; DEFINE_PER_CPU(unsigned long, process_counts) = 0;