Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8768067ybl; Fri, 17 Jan 2020 00:27:02 -0800 (PST) X-Google-Smtp-Source: APXvYqy3Qipvcwcndu6Bn6R5D7Wyf6kKG7Whj6RH/i1cpCSFsMBszCeBh+nPxLghjw1sqseEpX2N X-Received: by 2002:aca:e106:: with SMTP id y6mr2569917oig.131.1579249621940; Fri, 17 Jan 2020 00:27:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579249621; cv=none; d=google.com; s=arc-20160816; b=TDirFicZrasHn+9/UNNyAZ5fl6yl+zweVdc7f2YaOBxzKfYUkd9Aqk1Y5UE/I4ujwn H4pIr1TqcHszCZga+mfY0A6B5ghLmuEAO/tKBRs0yQzvKvBU1JQ4srXmcBDUY8/YELqU pR4JMqz2K0swA9el1NQOr2HvcqCdLqpxC33DXekS1EBheLY1+MR/o+yoIA6v2ZVZsksr KxzPYS0BeAp1n7yxWPFfecu56VZ0MqNasygAKuYge0CKHax8aFLPhYvCjC+wtP4tVbe0 PVWJCi3tNwbHvq0Fa+Uvqrho/s1cAyE/xnFwrmsJ5LzDJ3xVaBfacULO2IX3SFT4CLE/ Mzzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=c3CLbGH3yNmegqMMrTOsWM1VXAtdVUHSPp5sdhxItpE=; b=gNn+PvQ1MeLnOlDt8JUuxmv9dAlHLgoRU2efCBHCc6iYcqZs7KAkWs0qOui34rD0d1 V+YyRZRue/UgjxbFJsllj5IzvrEB1U13Z2N8o0YAwKX3g67Wp78KrR/X/KjV9aClDAVm tYkT2FTykFMDXLuI1Vwdh/VjOiX6AZa0HeHlDTFWubqObVACMr+kbSJ1nPKqEyHKjKok PIS6kzy61tV+qIYJW9R2VBABWG+6F49yBmszq4wsTUcBoWGZJ3VwEBnsk0+s+abKWUyJ NnUP6eCmtko0PwJSl/7U1f+P8S0lT+FvxB7SDLv3BUhO7ALuzXzhC0lNsYZbiH+ds8QK aYRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YPB5am7u; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t16si15099767otp.257.2020.01.17.00.26.50; Fri, 17 Jan 2020 00:27:01 -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=@gmail.com header.s=20161025 header.b=YPB5am7u; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729624AbgAQIY1 (ORCPT + 99 others); Fri, 17 Jan 2020 03:24:27 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36728 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729317AbgAQIY1 (ORCPT ); Fri, 17 Jan 2020 03:24:27 -0500 Received: by mail-pg1-f193.google.com with SMTP id k3so11308540pgc.3 for ; Fri, 17 Jan 2020 00:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=c3CLbGH3yNmegqMMrTOsWM1VXAtdVUHSPp5sdhxItpE=; b=YPB5am7urRYdi3ZEg/wc/wYUlIoNarzwCR501g4ss4efAaGox/Tf/xNZL1/PFI9BLD tA/yPz7irn4d1SqeNQSJRfhDI7HNRpnralnmvN/mPSoFwj24VPVQ23oXgQ92iJlozJxm 998lr08BWiEO849l6fn03UuXyfCf0dkH+eNjlYh+zKJbx2kCk3GDcgjXgwlPLylFWl5Y B+a7zYi4ZouoNeo0nLtLTJ35dCfWMjaAI9myoD0YHmp1ZILfBz3hFeX+xIPdpaPcUNGC i2Gmpjy02T22QRYOWO4LduTo0HZDqAOx5lV1DWgdA2hY05Kh7I0SEjrz1zO/pJKtzD1J 2Rtg== 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; bh=c3CLbGH3yNmegqMMrTOsWM1VXAtdVUHSPp5sdhxItpE=; b=Dj7amEyLvpxZ3l47HA5LnFQSkqHGpfbaIXW1/3epe1XV/jshxC+H2MoOjHM1VyrMgm NQm8vlfZP4G84eYuQOq7aH+OF4V11FbaLbRkAFnYuJiY3qJmDedTWQmycKDa4TybgRLY PvNVEshF4vpBSWuBZ2lVkIQbOtxQPHHmVmm79xi2BCu80VeQUIPn8gp4hL4rpQLpK6s0 xOSyyDW1ZUedYccJzeodVF/E0XG+XBQipWT5K9Hn5Ex55wBVDUK1EFu+mVz851Gv3WLA OyI3xEyI0NRUO2xAJI/JRSMFESn+vjGjy52E4SDUfvMEOatlRz/8eMQ7dIPXq4hAVGcg nzGw== X-Gm-Message-State: APjAAAUmaWcQ8GYF5tWkYM+4iLuuOenmjMS8gVeMgDpwauiJXbRmwqVL LkxA6duYks8iHlDxl30fpws= X-Received: by 2002:aa7:9edd:: with SMTP id r29mr1807945pfq.14.1579249466692; Fri, 17 Jan 2020 00:24:26 -0800 (PST) Received: from bj08259pcu1.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id d1sm6158471pjx.6.2020.01.17.00.24.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Jan 2020 00:24:26 -0800 (PST) From: Jing Xia To: akpm@linux-foundation.org Cc: npiggin@gmail.com, rppt@linux.ibm.com, allison@lohutok.net, tglx@linutronix.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, yuming.han@unisoc.com, chunyang.zhang@unisoc.com, Jing Xia Subject: [RFC] lib/show_mem.c: extend show_mem() to support showing drivers' memory consumption Date: Fri, 17 Jan 2020 16:24:05 +0800 Message-Id: <1579249445-27429-1-git-send-email-jing.xia.mail@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jing Xia In low memory situations, sometimes we need to check how much memory a driver using.This patch add a notifer chain to show_mem.So a driver can show their memory usage when show_mem_extend() is called. Co-developed-by: Yuming Han Signed-off-by: Yuming Han Signed-off-by: Jing Xia --- include/linux/mm.h | 9 +++++++++ lib/show_mem.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index cfaa8fe..a37274a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2201,6 +2201,15 @@ extern void memmap_init_zone(unsigned long, int, unsigned long, unsigned long, #ifdef __HAVE_ARCH_RESERVED_KERNEL_PAGES extern unsigned long arch_reserved_kernel_pages(void); #endif +enum show_mem_extend_type { + SHOW_MEM_EXTEND_BASIC, + SHOW_MEM_EXTEND_CLASSIC, + SHOW_MEM_EXTEND_ALL +}; +extern int register_show_mem_notifier(struct notifier_block *nb); +extern int unregister_show_mem_notifier(struct notifier_block *nb); +extern void show_mem_extend(unsigned int flags, nodemask_t *nodemask, + enum show_mem_extend_type type); extern __printf(3, 4) void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...); diff --git a/lib/show_mem.c b/lib/show_mem.c index 1c26c14..6b013cb 100644 --- a/lib/show_mem.c +++ b/lib/show_mem.c @@ -7,6 +7,8 @@ #include #include +#include +#include void show_mem(unsigned int filter, nodemask_t *nodemask) { @@ -42,3 +44,37 @@ void show_mem(unsigned int filter, nodemask_t *nodemask) printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); #endif } + +static BLOCKING_NOTIFIER_HEAD(show_mem_notify_list); + +int register_show_mem_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&show_mem_notify_list, nb); +} +EXPORT_SYMBOL_GPL(register_show_mem_notifier); + +int unregister_show_mem_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&show_mem_notify_list, nb); +} +EXPORT_SYMBOL_GPL(unregister_show_mem_notifier); + +void show_mem_extend(unsigned int filter, nodemask_t *nodemask, + enum show_mem_extend_type type) +{ + unsigned long used = 0; + struct sysinfo si; + + pr_info("Mem-Info-Extend:\n"); + show_mem(filter, NULL); + si_meminfo(&si); + pr_info("MemTotal: %8lu KB\n" + "Buffers: %8lu KB\n" + "SwapCached: %8lu KB\n", + (si.totalram) << (PAGE_SHIFT - 10), + (si.bufferram) << (PAGE_SHIFT - 10), + total_swapcache_pages() << (PAGE_SHIFT - 10)); + + blocking_notifier_call_chain(&show_mem_notify_list, + (unsigned long)type, &used); +} -- 1.9.1