Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2330800ybg; Thu, 30 Jul 2020 17:24:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTZTM2LURHGnVUAZCW5XNOJNxvpGRkAHUhix1Tm1fldUGDuqQYFhkxnbVzW6NZ/BgqDp4T X-Received: by 2002:a05:6402:1545:: with SMTP id p5mr1470774edx.388.1596155096983; Thu, 30 Jul 2020 17:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596155096; cv=none; d=google.com; s=arc-20160816; b=dkPAc6Bkg6qWCwpuAOFlOHATuox+YVHzMy7ETXOzcuPgc4CmeR8jzmGRvsMeX2hmZF wzk3VrL/csMJ9MpJNQ/lJ2wnAsEgOASp2q+4hAtLbF2VuJkLae6HF/kjfrHz/zanDVT9 ykXMyRvb300CZw2gjl9FBIpbNPY6Uer7FtM5z/qcyoy+lzAs3RChsraMzdpBFGOGobkB Sji5PgBX/IBuZWt3c2lQYQnrH/Zm9GQaTFYnEtTDck22TXpOvxbr8K3sQ3dcMS4d/H2l SVZ/F0y5hh3hVQyZ+SOAALwq/DBUNMGKfsBoENOmBy3KJDwLTbb1R4JEEKNt667c3IiL ultA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KHN+uLmX/K+mPuq0yzanWuXPqaWti8JxXwhQ/gYkGRk=; b=gFxCPwsmeQTfmso7lpo+KqVXdH4A2t8jI2MlfZkeSq/GQwdUzLJrO8Z7JT4O4uu/9F mZpJxChKE7/PAdzhb9QCFRXydWN8poBMytX1CzjVHcLVQh15g9agjrbOBUtQgpMBvPuP g/xZdu7kFli8zWkWDG9PNEIJ8O/5Y5kVffu9Cm7tWVKhuTqLXf9ItPLuOXu6UVKykafx 1x92CdDa8TEYrLulSttV3s+/gB5EhvSsHMF5c7hifuLcexLhcpevAcaOrRXUFs7H1S6n 10ncvbzGptTCJ+5GTilQUad4vAU70yZuETO5qu2AQ2TKrtq4HxPjSCYWcnd1LhSeS9+H YFdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FUYO9lkP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do5si3210199ejc.612.2020.07.30.17.24.31; Thu, 30 Jul 2020 17:24:56 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=FUYO9lkP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730883AbgGaAYM (ORCPT + 99 others); Thu, 30 Jul 2020 20:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730800AbgGaAYM (ORCPT ); Thu, 30 Jul 2020 20:24:12 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3831BC061574 for ; Thu, 30 Jul 2020 17:24:12 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id t15so21182387iob.3 for ; Thu, 30 Jul 2020 17:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KHN+uLmX/K+mPuq0yzanWuXPqaWti8JxXwhQ/gYkGRk=; b=FUYO9lkPyHatjuEszFnSwiGD+PXO+vxOLyPE4yKhHZqNztOA82IJxgjjzOsRYaUQ8B lQM3KWBdDVwNcctLD3jqcQN2kMXkgZ8iF04zd75apQmHrUvkLdV7UavTfPV0HX/W2nPL +uf3qXlTFLJx29m9dtIyA0WvLgdUqoQT6iCvQp4P55G0uY1JpBzYn9X3/HMj4H7wDc6u FMTjW09sWrY2OQljOaS5+mFeIfputr77xApl47IrF0gZOY8o0GNB+lqhmofFQHq3snf4 l6i0I/nq8HyzY5VCrAZx52HurPnL/2xG01gMYU+EyXd8csYo4Ks1i1XTVzFI9JS3okVu lSaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KHN+uLmX/K+mPuq0yzanWuXPqaWti8JxXwhQ/gYkGRk=; b=osmBdIPbgHyReFAZ+8PM2aZBI7w7ikK32+YKw2Jk3XpiUfK+8l4XWnxByOEhEmFz2a dR7FbiwDp1Nmd5DBowLiIyc8hy1VPBDgQ24a0RDgh363l9lWZs6e9xoBKL7gDwe1PIWP qFQU5HRwtKXbWiQEX80ANWxGKxDRKdwAvLuqdF2PjDQ1YmEwKvJMO2lmUaDlC1LcihSY hGZwp9AoLRKdl0+gqi6AqENlhf5RsWBWCLj1oVGCaqtdCliYiV4Zf9NNX61BiM2G6oJa MPiKlTYKiui6lH35haId1lpBhAlF27Qcudlden8av81/n750r1biNx3ogPB06ZHvFbY7 ylTw== X-Gm-Message-State: AOAM530GOE0PWvyQ9sVv+ttounR5KanUm63Qg1hH9HavWEY7DjxsOG4B eoNI8pl3dRxQdSRuXZbFAUQ1WBmQBRtADb10j2I4+kE2jyw= X-Received: by 2002:a6b:8d03:: with SMTP id p3mr1153341iod.114.1596155051462; Thu, 30 Jul 2020 17:24:11 -0700 (PDT) MIME-Version: 1.0 References: <1596107052-25682-1-git-send-email-zhaoyang.huang@unisoc.com> <20200730095842.3e438960@oasis.local.home> In-Reply-To: <20200730095842.3e438960@oasis.local.home> From: Zhaoyang Huang Date: Fri, 31 Jul 2020 08:24:00 +0800 Message-ID: Subject: Re: [PATCH] trace : use kvmalloc instead of kmalloc To: Steven Rostedt Cc: Ingo Molnar , chunyan.zhang@unisoc.com, Zhaoyang Huang , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2020 at 9:58 PM Steven Rostedt wrote: > > On Thu, 30 Jul 2020 19:04:12 +0800 > Zhaoyang Huang wrote: > > > High order memory stuff within trace could introduce OOM, use kvmalloc instead. > > > > Please find the bellowing for the call stack we run across in an android system. The scenario happens when traced_probes is woken up to get a large quantity of trace even if free memory is even higher than watermark_low. > > Please limit your column width in the description of patches to 76 > characters. > > > > > traced_probes invoked oom-killer: gfp_mask=0x140c0c0(GFP_KERNEL|__GFP_COMP|__GFP_ZERO), nodemask=(null), order=2, oom_score_adj=-1 > > > > What does this traced_probes thing do? traced_probes is an android exe which reads ftrace and writes them to files. I think kzalloc works fine for most of context but will cause OOM in high ratio ftrace access in memory constraint system, like mobilephone etc. > > > traced_probes cpuset=system-background mems_allowed=0 > > CPU: 3 PID: 588 Comm: traced_probes Tainted: G W O 4.14.181 #1 > > Hardware name: Generic DT based system > > (unwind_backtrace) from [] (show_stack+0x20/0x24) > > (show_stack) from [] (dump_stack+0xa8/0xec) > > (dump_stack) from [] (dump_header+0x9c/0x220) > > (dump_header) from [] (oom_kill_process+0xc0/0x5c4) > > (oom_kill_process) from [] (out_of_memory+0x220/0x310) > > (out_of_memory) from [] (__alloc_pages_nodemask+0xff8/0x13a4) > > (__alloc_pages_nodemask) from [] (kmalloc_order+0x30/0x48) > > (kmalloc_order) from [] (kmalloc_order_trace+0x30/0x118) > > (kmalloc_order_trace) from [] (tracing_buffers_open+0x50/0xfc) > > (tracing_buffers_open) from [] (do_dentry_open+0x278/0x34c) > > (do_dentry_open) from [] (vfs_open+0x50/0x70) > > (vfs_open) from [] (path_openat+0x5fc/0x169c) > > (path_openat) from [] (do_filp_open+0x94/0xf8) > > (do_filp_open) from [] (do_sys_open+0x168/0x26c) > > (do_sys_open) from [] (SyS_openat+0x34/0x38) > > (SyS_openat) from [] (ret_fast_syscall+0x0/0x28) > > > > Signed-off-by: Zhaoyang Huang > > --- > > changes since v1: change kfree to kvfree > > --- > > kernel/trace/trace.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > > index ca1ee65..8d70c79 100644 > > --- a/kernel/trace/trace.c > > +++ b/kernel/trace/trace.c > > @@ -6891,7 +6891,7 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp) > > if (trace_array_get(tr) < 0) > > return -ENODEV; > > > > - info = kzalloc(sizeof(*info), GFP_KERNEL); > > + info = kvmalloc(sizeof(*info), GFP_KERNEL); > > The above is a bug. It converts kzalloc() to kvmalloc() instead of > kvzalloc(). fixed and resend with patch v2 > > -- Steve > > > > > if (!info) { > > trace_array_put(tr); > > return -ENOMEM; > > @@ -7017,7 +7017,7 @@ static int tracing_buffers_release(struct inode *inode, struct file *file) > > if (info->spare) > > ring_buffer_free_read_page(iter->trace_buffer->buffer, > > info->spare_cpu, info->spare); > > - kfree(info); > > + kvfree(info); > > > > mutex_unlock(&trace_types_lock); > > >