Received: by 10.192.165.148 with SMTP id m20csp2021454imm; Thu, 26 Apr 2018 05:24:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpFOhPfmUa4A4dwlcO7er9u9QmyEn06OtRNDzqiNgg0vnd3iijTBwDH0d1MqsM8p1ELg5em X-Received: by 2002:a17:902:5269:: with SMTP id z96-v6mr5399455plh.234.1524745494990; Thu, 26 Apr 2018 05:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524745494; cv=none; d=google.com; s=arc-20160816; b=AcBTO8pkexJecilXSUfcjmhBqH5B1k75ggknIKOx+4cR0aX2d9XKPTzSiyO//Qtf0v wn8o3LYvP/6XleleVYuInONOx63WCmioJrDhNLakuH2Kl0lNXFEw2nsS6B5uYVkGYmE7 +AAC1QOCcxoFbnpbMzO1bumu92X/njD8mDO6ph+4ZmsHC2mw4mJ5THHIBomP5S5HH8+8 fINpr+cQ9dXop8+REmsqN/nY8H3LZmTkZf7K7JkaGJSAeM7eKNoKpfVprSLl/AkIPN3g DUJXIlaEywPm03uY5Esh/tZWejOCuKX5TBDKuzLNqkZysQZIbfurCaJIhMAlLKEDqVpc zQvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:reply-to:from:date :arc-authentication-results; bh=MuDpY96s1XWjHLsHOVZbF3/IGni4mlwAjLok6iq1LM0=; b=oGNM0Hzf2ZYlReQzBAl9b2YiyOaqHpVh2wug7hzWKtUUBE44WzlI4y1nNqiRsQ0XsY 7Z/BgVXaNRS+tFKeaYJS82iqJvj2zc1T0rYJ4k/A+uhvy59cDFO966TT6Wb4myuhT99W 32ENWzOVR8tx6VNnixIZfmloZLo6fpqpBPRd4rlHgy1kfaKJ2qHNommbgLPHEOp2r5SM F0GCtRu7j9trWv5oLCyzEnl+OpftbDSm8y+5QVINF9ftHkFl8g4YxDl4uCSe+7fmRMa2 nOA/aW/U3I7tMjO13HSW4IPutXLBEEI/PSgjXQMkfQeOlTMZFE0FygvX10OBP7524NVA yhIw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o186si5886334pga.350.2018.04.26.05.24.40; Thu, 26 Apr 2018 05:24:54 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755542AbeDZMXW (ORCPT + 99 others); Thu, 26 Apr 2018 08:23:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34724 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754516AbeDZMXT (ORCPT ); Thu, 26 Apr 2018 08:23:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4FB885547; Thu, 26 Apr 2018 12:23:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9148E2C8CC; Thu, 26 Apr 2018 12:23:19 +0000 (UTC) Received: from zmail23.collab.prod.int.phx2.redhat.com (zmail23.collab.prod.int.phx2.redhat.com [10.5.83.28]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4C96B1808850; Thu, 26 Apr 2018 12:23:19 +0000 (UTC) Date: Thu, 26 Apr 2018 08:23:19 -0400 (EDT) From: Chunyu Hu Reply-To: Chunyu Hu To: Michal Hocko Cc: Chunyu Hu , Dmitry Vyukov , Catalin Marinas , LKML , Linux-MM Message-ID: <732114897.20075296.1524745398991.JavaMail.zimbra@redhat.com> In-Reply-To: <20180424170239.GP17484@dhcp22.suse.cz> References: <1524243513-29118-1-git-send-email-chuhu@redhat.com> <20180420175023.3c4okuayrcul2bom@armageddon.cambridge.arm.com> <20180422125141.GF17484@dhcp22.suse.cz> <20180424132057.GE17484@dhcp22.suse.cz> <850575801.19606468.1524588530119.JavaMail.zimbra@redhat.com> <20180424170239.GP17484@dhcp22.suse.cz> Subject: Re: [RFC] mm: kmemleak: replace __GFP_NOFAIL to GFP_NOWAIT in gfp_kmemleak_mask MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.68.5.41, 10.4.195.26] Thread-Topic: kmemleak: replace __GFP_NOFAIL to GFP_NOWAIT in gfp_kmemleak_mask Thread-Index: KrM68SfC8VSTg3XInQFcej5iJnwTHA== X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 26 Apr 2018 12:23:19 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Original Message ----- > From: "Michal Hocko" > To: "Chunyu Hu" > Cc: "Chunyu Hu" , "Dmitry Vyukov" , "Catalin Marinas" > , "LKML" , "Linux-MM" > Sent: Wednesday, April 25, 2018 1:02:39 AM > Subject: Re: [RFC] mm: kmemleak: replace __GFP_NOFAIL to GFP_NOWAIT in gfp_kmemleak_mask > > On Tue 24-04-18 12:48:50, Chunyu Hu wrote: > > > > > > ----- Original Message ----- > > > From: "Michal Hocko" > > > To: "Chunyu Hu" > > > Cc: "Dmitry Vyukov" , "Catalin Marinas" > > > , "Chunyu Hu" > > > , "LKML" , "Linux-MM" > > > > > > Sent: Tuesday, April 24, 2018 9:20:57 PM > > > Subject: Re: [RFC] mm: kmemleak: replace __GFP_NOFAIL to GFP_NOWAIT in > > > gfp_kmemleak_mask > > > > > > On Mon 23-04-18 12:17:32, Chunyu Hu wrote: > > > [...] > > > > So if there is a new flag, it would be the 25th bits. > > > > > > No new flags please. Can you simply store a simple bool into > > > fail_page_alloc > > > and have save/restore api for that? > > > > Hi Michal, > > > > I still don't get your point. The original NOFAIL added in kmemleak was > > for skipping fault injection in page/slab allocation for kmemleak object, > > since kmemleak will disable itself until next reboot, whenever it hit an > > allocation failure, in that case, it will lose effect to check kmemleak > > in errer path rose by fault injection. But NOFAULT's effect is more than > > skipping fault injection, it's also for hard allocation. So a dedicated > > flag > > for skipping fault injection in specified slab/page allocation was > > mentioned. > > I am not familiar with the kmemleak all that much, but fiddling with the kmemleak is using kmem_cache to record every pointers returned from kernel mem allocation activities such as kmem_cache_alloc(). every time an object from slab allocator is returned, a following new kmemleak object is allocated. And when a slab object is freed, then the kmemleak object which contains the ptr will also be freed. and kmemleak scan thread will run in period to scan the kernel data, stack, and per cpu areas to check that every pointers recorded by kmemleak has at least one reference in those areas beside the one recorded by kmemleak. If there is no place in the memory acreas recording the ptr, then it's possible a leak. so once a kmemleak object allocation failed, it has to disable itself, otherwise it would lose track of some object pointers, and become less meaningful to continue record and scan the kernel memory for the pointers. So disable it forever. so this is why kmemleak can't tolerate a slab alloc fail (from fault injection) @Catalin, Is this right? If something not so correct or precise, please correct me. I'm thinking about, is it possible that make kmemleak don't disable itself when fail_page_alloc is enabled? I can't think clearly what would happen if several memory allocation missed by kmelkeak trace, what's the bad result? > gfp_mask is a wrong way to achieve kmemleak specific action. I might be As Dmirty explained, this is in fact for fault injection providing a method to make some debug feature be able to not be injected fault by the 'fault injection'. Some other features beside kmemleak I can think out is ftrace will also hard disable itself when page allocation failed (not sure about slab) > easilly wrong but I do not see any code that would restore the original > gfp_mask down the kmem_cache_alloc path. looks like currently flag __GFP_NOFAIL can go very deep to where before new slab needed to be allocated. So what's a pity is when CONFIG_FAIL_PAGE_ALLOC is defined, when new slab is created, this flag will be filtered out. So GFP_NOFAIL currently is used by two meanings, first is allocation can't fail, second is meaning not fault injection, but page allocator don't accept the second meaning. So there is a real need for the 'avoid-fault' meaning, though I agree, current there is only limited user/market, kmemleak, it just don't have api to avoid being fault injected. But I think there will be other debug feature who can be used during fault injection works. > > > d9570ee3bd1d ("kmemleak: allow to coexist with fault injection") even use GFP_NOFAIL, when new slab needs to be allocated, and when CONFIG_FAIL_PAGE_ALLOC yes, it still can't avoid hurting by fault injection. as GFP_NOFAIL is filtered out in first fast path of allocate_slab. > > > > Do you mean something like below, with the save/store api? But looks like > > to make it possible to skip a specified allocation, not global disabling, > > a bool is not enough, and a gfp_flag is also needed. Maybe I missed > > something? > > Yes, this is essentially what I meant. It is still a global thing which > is not all that great and if it matters then you can make it per > task_struct. That really depends on the code flow here. Thank you Michal for this suggestion. What I can imagine this seems would be very complicated. You know memory allocation is very frequent, and some memory allocation can sleep, and some not. Also there are complicated kernel threads. If I got your point correctly, a member added in task_struct, then every mem allocation, needs to touch the member, and needs lock to protect the member. Also it needs to interact with kmemleak structure. I'm still not very clear and still thinking about it. @Dmitry know more about this? > > -- > Michal Hocko > SUSE Labs > -- Regards, Chunyu Hu