Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp320382ybb; Thu, 19 Mar 2020 23:00:52 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtZeZoVvK2UF5DI8KM6rxfbmp0kWTrxTaHoOkvmZUC6MQYzqrCN6SR962pdjs6yYwE22DYa X-Received: by 2002:a05:6808:3b3:: with SMTP id n19mr5302451oie.114.1584684052724; Thu, 19 Mar 2020 23:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584684052; cv=none; d=google.com; s=arc-20160816; b=MUfjqD6muuLw6ZxhyloYIc3w5zhR0e8wHYNW16tI3cQ4H6s+sP6q08kQB3bPI08KVD onI3yJHbSwEOOJm3ntahRBT05CO8LGDaYnM4b5sN8CrYFka05UIraJi0eQusPI77Aqm3 x+LgX8O6w/upNJKalaH9RhCNyy3IgELvmVqEeQSSFKXhbSC4FY5dbltKytBn6KZ4GDmO YlIMB4TwvzL8MMnrH394HycSG5ogRCwLUXGja8joDqvneszvq98m3l0vBiOsr5jsWobH j+rRIlDzdgx5dkccq/vV2wcn8dUYVM6q1wCBsomcrtbmIrE/rxD2EHHjFoeqDjPwXZSi AVNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=JLXzpDo2Uz5P4xcCLc3T6nk7O094GGMnndhBijC6c60=; b=v/dHeZ1ePSa0F99tTb3COaT42dnzJ+iTE49I8NMnqSNXr782hyIXUR4u4u4bos4LjC CLc62UuYcpQgEV0sSbyfDHqxtqGgdBokeG5Gq8dER9vcgYL6OEE/HyGzGI/NBGp+q/hB ce74uQlAqjk5uKbQESvTcHydXv2L6Ldl0Sf4PN13t3tJP69ENQ3CYq5KKTQVOZ4mfDV7 UTSKqGhlIFvbBrecO67CbKn7RFniInyHVR68xAKJRjm/jYYzFNJ00rYl4YuuoVVhTBWh LbJwga/TEvDF85TRBjilwmzsL3Jml4kajgjtgvIbvFim3Y5HaTjSgfVoRv0pVG+hn8Cm 3tNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=qjSniMvr; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si2413409otn.168.2020.03.19.23.00.40; Thu, 19 Mar 2020 23:00:52 -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=@samsung.com header.s=mail20170921 header.b=qjSniMvr; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbgCTF6v (ORCPT + 99 others); Fri, 20 Mar 2020 01:58:51 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:34452 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgCTF6n (ORCPT ); Fri, 20 Mar 2020 01:58:43 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20200320055841epoutp015267f48a08b2976019b75782c0ad5e09~97aF1zciV0507905079epoutp01Z for ; Fri, 20 Mar 2020 05:58:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20200320055841epoutp015267f48a08b2976019b75782c0ad5e09~97aF1zciV0507905079epoutp01Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1584683921; bh=JLXzpDo2Uz5P4xcCLc3T6nk7O094GGMnndhBijC6c60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjSniMvrQi9E6CrAZoY/KWmrEBPTDj078IDqBn/My8IG+488uyk2g1Ch1RLCUGPgv Lo8JPCEejcACRP/zAsoU1gI5kxd8HUyI+gvx8GKLNo1LvapLo7b4Z10tb/WB4icb52 Lt22LOx5U1dteU9+hRVYtbOEGQQvGCIJglsvTciw= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20200320055841epcas1p24fde7418e65b52d116358225715ecc75~97aFdKznn0986109861epcas1p2N; Fri, 20 Mar 2020 05:58:41 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.40.166]) by epsnrtp2.localdomain (Postfix) with ESMTP id 48kCkm1mJzzMqYkV; Fri, 20 Mar 2020 05:58:40 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 64.00.04071.09B547E5; Fri, 20 Mar 2020 14:58:40 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200320055839epcas1p189100549687530619d8a19919e8b5de0~97aDoCUx93235132351epcas1p1k; Fri, 20 Mar 2020 05:58:39 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200320055839epsmtrp23f33547d37fa3bf441efe7c22e14ea4b~97aDmu8c80413504135epsmtrp2y; Fri, 20 Mar 2020 05:58:39 +0000 (GMT) X-AuditID: b6c32a37-797ff70000000fe7-81-5e745b901180 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 84.06.04158.F8B547E5; Fri, 20 Mar 2020 14:58:39 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.104.82]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200320055839epsmtip136b85553e8d717235870d503d3b4d8bf~97aDc9S7t1022410224epsmtip1P; Fri, 20 Mar 2020 05:58:39 +0000 (GMT) From: Jaewon Kim To: willy@infradead.org, walken@google.com, bp@suse.de, akpm@linux-foundation.org, srostedt@vmware.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH v3 2/2] mm: mmap: add trace point of vm_unmapped_area Date: Fri, 20 Mar 2020 14:58:23 +0900 Message-Id: <20200320055823.27089-3-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20200320055823.27089-1-jaewon31.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRjm82zHs3JxWLeXkZcOJKmZO63pSaYU3Q7lD6P6U+Q6uMM2PLu0 s5l2oZsMWVnOWGV4zeiGYUyLlIoywsgoRcooKqOItOYqs5uZbZ5F/Xve53senof3ewlMdQBX Exabi3faOIHCp8iu3E7JSK/c7CrQdJ+PY2pamnHGdySFOdhajZiK0FAM09dRgzMvmifkzJ2f gzLmd9VuZux7Db5UwbaffB7LNgTcbOu5VDbwuSqWvXtiTMYebruA2NbunexIIIEdrg/i+YpN gt7Mc0bemcTbCu1Gi82UQ61db1hu0GVq6HR6CZNFJdk4K59DrcjLT19lEcL9qKRiTnCHqXxO FKmMXL3T7nbxSWa76MqheIdRcNAax0KRs4pum2lhod2aTWs0i3Rh5VbB/PpFl8zRE19y700I 34tC4EUKAsjFULP/CfKiKYSKvIqgr/aITBo+I/jUNS6LqFTkVwQX/Wl/HY/qH0b56wjqfImS 4RuCU1cq8cgDTqZBqKFKHsEzSDP4f76c5DHSDcEPd7EInk6uhHf9HZMaGTkP6kLvUQQryRwY uH80xouIcFgiNE5MyhVkLv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ITyxJzU5NLUgtgskycXBKNTCqWfVE 3ipUj1kTUPMzU9nKvTh1p7TY07eXA03/fRfXbL8ooZHT0fnRb0nVhWDNH7PSdzzauKD2SFz4 9wv/LNbVb6pp2Fh2eaG0uHveSuVPMuUvPyvt/XE5kKtCpHvGnrj2vScPCs7u/WOn/OloklyM T9Oavfp3c5261+VVuzxVVf/X3TfHO02JpTgj0VCLuag4EQAVXKm9TQIAAA== X-CMS-MailID: 20200320055839epcas1p189100549687530619d8a19919e8b5de0 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200320055839epcas1p189100549687530619d8a19919e8b5de0 References: <20200320055823.27089-1-jaewon31.kim@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Even on 64 bit kernel, the mmap failure can happen for a 32 bit task. Virtual memory space shortage of a task on mmap is reported to userspace as -ENOMEM. It can be confused as physical memory shortage of overall system. The vm_unmapped_area can be called to by some drivers or other kernel core system like filesystem. In my platform, GPU driver calls to vm_unmapped_area and the driver returns -ENOMEM even in GPU side shortage. It can be hard to distinguish which code layer returns the -ENOMEM. Create mmap trace file and add trace point of vm_unmapped_area. i.e.) 277.156599: vm_unmapped_area: addr=77e0d03000 err=0 total_vm=0x17014b flags=0x1 len=0x400000 lo=0x8000 hi=0x7878c27000 mask=0x0 ofs=0x1 342.838740: vm_unmapped_area: addr=0 err=-12 total_vm=0xffb08 flags=0x0 len=0x100000 lo=0x40000000 hi=0xfffff000 mask=0x0 ofs=0x22 Signed-off-by: Jaewon Kim --- v3: reduce fast_assign and print format v2: use trace point rather than printk with ratelimit v1: use printk with ratelimit --- include/trace/events/mmap.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ mm/mmap.c | 12 ++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 include/trace/events/mmap.h diff --git a/include/trace/events/mmap.h b/include/trace/events/mmap.h new file mode 100644 index 000000000000..986a41b6cfa9 --- /dev/null +++ b/include/trace/events/mmap.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM mmap + +#if !defined(_TRACE_MMAP_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_MMAP_H + +#include + +TRACE_EVENT(vm_unmapped_area, + + TP_PROTO(unsigned long addr, struct vm_unmapped_area_info *info), + + TP_ARGS(addr, info), + + TP_STRUCT__entry( + __field(unsigned long, addr) + __field(unsigned long, total_vm) + __field(unsigned long, flags) + __field(unsigned long, length) + __field(unsigned long, low_limit) + __field(unsigned long, high_limit) + __field(unsigned long, align_mask) + __field(unsigned long, align_offset) + ), + + TP_fast_assign( + __entry->addr = addr; + __entry->total_vm = current->mm->total_vm; + __entry->flags = info->flags; + __entry->length = info->length; + __entry->low_limit = info->low_limit; + __entry->high_limit = info->high_limit; + __entry->align_mask = info->align_mask; + __entry->align_offset = info->align_offset; + ), + + TP_printk("addr=%lx err=%ld total_vm=0x%lx flags=0x%lx len=0x%lx lo=0x%lx hi=0x%lx mask=0x%lx ofs=0x%lx\n", + IS_ERR_VALUE(__entry->addr) ? 0 : __entry->addr, + IS_ERR_VALUE(__entry->addr) ? __entry->addr : 0, + __entry->total_vm, __entry->flags, __entry->length, + __entry->low_limit, __entry->high_limit, __entry->align_mask, + __entry->align_offset) +); +#endif + +/* This part must be outside protection */ +#include diff --git a/mm/mmap.c b/mm/mmap.c index ba990c20ecc2..94ae18398c59 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -53,6 +53,9 @@ #include #include +#define CREATE_TRACE_POINTS +#include + #include "internal.h" #ifndef arch_mmap_check @@ -2061,10 +2064,15 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) */ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) { + unsigned long addr; + if (info->flags & VM_UNMAPPED_AREA_TOPDOWN) - return unmapped_area_topdown(info); + addr = unmapped_area_topdown(info); else - return unmapped_area(info); + addr = unmapped_area(info); + + trace_vm_unmapped_area(addr, info); + return addr; } #ifndef arch_get_mmap_end -- 2.13.7