From mboxrd@z Thu Jan 1 00:00:00 1970 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 236A7C3DA4A for ; Mon, 19 Aug 2024 07:57:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 937526B0088; Mon, 19 Aug 2024 03:57:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E82B6B0089; Mon, 19 Aug 2024 03:57:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 761B16B008A; Mon, 19 Aug 2024 03:57:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 559266B0088 for ; Mon, 19 Aug 2024 03:57:58 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0CC6740FFA for ; Mon, 19 Aug 2024 07:57:58 +0000 (UTC) X-FDA: 82468241436.28.C821F67 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by imf30.hostedemail.com (Postfix) with ESMTP id 1149A8000D for ; Mon, 19 Aug 2024 07:57:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b="JKnyko/l"; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf30.hostedemail.com: domain of mhocko@suse.com designates 209.85.208.53 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724054213; a=rsa-sha256; cv=none; b=px7wOy4EvQiSLRl7d4SrHxxSHzBhtuhmFy5zmyv0HFvld0qbO8Mce0cgaBOWyy5tDaRUYo M4UnimFAYnO32/+toFbTp8aOp9pSD0wYPnRAVlbB3Ck0x0Pp0L8gYFgoe9+BFgALLeeuND 9/J5OACUZ18jpfSgD4I8+aV7lfE2yeI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b="JKnyko/l"; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf30.hostedemail.com: domain of mhocko@suse.com designates 209.85.208.53 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724054213; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=arnGtTyoS5RDdw2W3dSzbJ5CUs+i0D7zxAci5MUC2T8=; b=Jgmn+Hy0xlGvpKQoKc/FlOGV0YWxKRWo/FvuowjXzYXbx//NuOrCxoG8sFEZt2s0vdws4f IC7+zkZ0INNkPl9aTTQ/9QoXS//DucQF7Z9cvpuwavu1nrjxRVCAmIvX2mmBG/P/FY1T16 mskXJgJqqI+pexXP7bnokIjziCbr/48= Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5bb85e90ad5so2837244a12.3 for ; Mon, 19 Aug 2024 00:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1724054274; x=1724659074; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=arnGtTyoS5RDdw2W3dSzbJ5CUs+i0D7zxAci5MUC2T8=; b=JKnyko/lNvHgt4Mwh9Gdx1P6Siege4QmH6xiENiiJOhcD1f2uk504C0RJ9oUu0lh1f rG8klji+1IXoglLrJ26s/X7asUlGPUCf7+Xgc+O6rV8ZVvJRhWKua8MWEYluJ1lzo0oI l0yUryAWO+IuXd/1PScaYg50B62vMioXySWsx283g5J8X+2D16Bmw7C+i6VmKJQlyC3M sXDLAwxnJiepVYTK1Gujz9Ft64zpRlWWK7Azk34R5RqD/INa1ciikhp+J5sKOEwycyVj Dw4xtCTflyKtAT6mxxXZp5pk44TURX1Y5zGnLEZkkUZfIFpqaATqcVRC8/B9DdiLzYRV c39Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724054274; x=1724659074; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=arnGtTyoS5RDdw2W3dSzbJ5CUs+i0D7zxAci5MUC2T8=; b=ov8OiNp3BCh9uZpMrcUGnINYvwYE3j3UQ3/KNTZjPvkHlT5UX4FvfD2s9ALdjWHtXu frDZAnbL7770YvX8gI+EBPVugBzTZlvUpOk6/vz8U4Cj5JUu2YjqtFQ65e+kfB+FPMR0 EsiOOyzSTM//Qm82tJbs7Pi1LLutTm7HL72RajJCOLvWSakCRII5K3Fos5s4ev0t2KJG tzcidmf+dapaufv+ZTVshDHe/wAA2A2PuDhX+tOVcfTORIN89A2AOyoeouNC10QKlRGY 363JU/mOjUGU85L7DmM/aD3hVDvnDLEerG2K2o3Wt2canWULWTt47JpAHiQmQCP0tWuV HUMA== X-Forwarded-Encrypted: i=1; AJvYcCWTrkIEe8Nsi9w4+6IcQ1HzFgxH5ivA2qZyk4J6XZh2b5N0TUrYxJQEFmX4t7AYvGUZ5QBFd1soYw==@kvack.org X-Gm-Message-State: AOJu0Yxatgn5qVjCqYXDDLOxDEXJtVbKgY47XOEQIqgSIH0oYUK3iR26 +8oHKNJPNUGllIOflebUuEapIFXX3YfcrYuZ1ysNn9+bpeNNZN5WPjZaKuw5ilg= X-Google-Smtp-Source: AGHT+IEQgoJGknYLZ16yIzD+XS2lqDcmI5iK2qcYT0XI1UhOu4JBsyHp+IcQGr4Y23idFaQQJh18vw== X-Received: by 2002:a05:6402:84b:b0:5be:bcdf:4110 with SMTP id 4fb4d7f45d1cf-5beca263a7cmr7293268a12.0.1724054274369; Mon, 19 Aug 2024 00:57:54 -0700 (PDT) Received: from localhost (109-81-83-72.rct.o2.cz. [109.81.83.72]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bedf8a0628sm2514761a12.34.2024.08.19.00.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 00:57:54 -0700 (PDT) Date: Mon, 19 Aug 2024 09:57:53 +0200 From: Michal Hocko To: Yafang Shao Cc: Andrew Morton , Christoph Hellwig , viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Kent Overstreet Subject: Re: [PATCH] mm: document risk of PF_MEMALLOC_NORECLAIM Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1149A8000D X-Stat-Signature: sbp9sf1f6ptz4776efop8euahitaeynj X-Rspam-User: X-HE-Tag: 1724054275-841924 X-HE-Meta: U2FsdGVkX19a5pvzSa4kfWFSPItrBUCvpQ6/kovKYm4tMCbDjoOVOnDEcchB0kxyrfs6qirKIXJ8XcSLL2XtR2gMJ83DFtfFhVcu1dOYrMNy82FwjBxOK1t7fB/yVAEbcPIiWA1CttfekTrRrZZ7tarZB6YKZv1Bau0It+D5pSGahv9nufg0o7/UXi6VCsvUNxO15AGON+JnmU/rtscY0/6OxiUkS09nesK2MYmF2DiyFfafVumwelq/GPyyB2mG/yUiC+g5bIfMonGGWm/kzA6MKhpTbqVOBGaHpp2axX//sNDyA/UwsNxIrFFcat9H3eKLJn+KImETiAxwA0esUpk322RtgcvwGRHrxKjV1ghTiB7ZG2IJprvSHh5ma17qIa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uJ8TNRJmNfITQOWdcNjFANClERsq1liiLlB/Rdv1Ryh187ExbR9xjzo/Tv9oJt/6d4FeUIugfEMlwg29lhaDhxRdWYY2D7EEJgDVbLNtkxW7ySURdCaYYNHuX/uCwMppxnDfjjUZFN+C5UzHGb6meGCmCyvsPfSI5XOaKrX+ZHiD X-Bogosity: Ham, tests=bogofilter, spamicity=0.007209, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sat 17-08-24 10:29:31, Yafang Shao wrote: > On Fri, Aug 16, 2024 at 4:17 PM Michal Hocko wrote: > > > > Andrew, could you merge the following before PF_MEMALLOC_NORECLAIM can > > be removed from the tree altogether please? For the full context the > > email thread starts here: https://lore.kernel.org/all/20240812090525.80299-1-laoar.shao@gmail.com/T/#u > > --- > > From f17d36975ec343d9388aa6dbf9ca8d1b58ed09ce Mon Sep 17 00:00:00 2001 > > From: Michal Hocko > > Date: Fri, 16 Aug 2024 10:10:00 +0200 > > Subject: [PATCH] mm: document risk of PF_MEMALLOC_NORECLAIM > > > > PF_MEMALLOC_NORECLAIM has been added even when it was pointed out [1] > > that such a allocation contex is inherently unsafe if the context > > doesn't fully control all allocations called from this context. Any > > potential __GFP_NOFAIL request from withing PF_MEMALLOC_NORECLAIM > > context would BUG_ON if the allocation would fail. > > > > [1] https://lore.kernel.org/all/ZcM0xtlKbAOFjv5n@tiehlicka/ > > > > Signed-off-by: Michal Hocko > > Documenting the risk is a good first step. For this change: > > Acked-by: Yafang Shao > > Even without the PF_MEMALLOC_NORECLAIM flag, the underlying risk > remains, as users can still potentially set both ~__GPF_DIRECT_RECLAIM > and __GFP_NOFAIL. Users can configure all sorts of nonsensical gfp flags combination. That is a sad reality of the interface. But we do assume that kernel code is somehow sane. Besides that Barry is working on making this less likely by droppong __GFP_NOFAIL and replace it by GFP_NOFAIL which always includes __GFP_DIRECT_RECLAIM. Sure nothing will prevent callers from clearing that flag explicitly but we have no real defense afains broken code. > PF_MEMALLOC_NORECLAIM does not create this risk; it > only exacerbates it. The core problem lies in the complexity of the > various GFP flags and the lack of robust management for them. While we > have extensive documentation on these flags, it can still be > confusing, particularly for new developers who haven't yet encountered > real-world issues. > > For instance: > > * %GFP_NOWAIT is for kernel allocations that should not stall for direct > * reclaim, > #define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM | __GFP_NOWARN) > > Initially, it wasn't clear to me why setting __GFP_KSWAPD_RECLAIM and > __GFP_NOWARN would prevent direct reclaim. It only became apparent > after I studied the entire code path of page allocation. I believe > other newcomers to kernel development may face similar confusion as I > did early in my experience. > > The real issue we need to address is improving the management of these > GFP flags, though I don't have a concrete solution at this time. Welcome to the club. Changing this interface is a _huge_ undertaking. Just have a look how many users of the gfp flags we have in the kernel. I can tell you from a first hand experience that even minor tweaks are really hard to make. -- Michal Hocko SUSE Labs