From patchwork Fri Aug 30 20:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13785528 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 056C3CA1013 for ; Fri, 30 Aug 2024 20:29:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90D606B024E; Fri, 30 Aug 2024 16:29:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BB816B024F; Fri, 30 Aug 2024 16:29:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75C426B025C; Fri, 30 Aug 2024 16:29:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4E4D16B024E for ; Fri, 30 Aug 2024 16:29:23 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CCB4740576 for ; Fri, 30 Aug 2024 20:29:22 +0000 (UTC) X-FDA: 82510051764.18.F2129B1 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf07.hostedemail.com (Postfix) with ESMTP id F1EB040004 for ; Fri, 30 Aug 2024 20:29:20 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cu8C3XTt; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725049671; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GjM4TCQPcyD2c0/3KvrBI/E6RtEEAPLZc40kpXbn95A=; b=KRFrl1v7yjbd03+a0CuGhFjiwB8N+nWoR0DrQjyRuaLIxLxqKidmU/ouErXNB+hAIRMUOb rxWxsm7DqTWChz/euaQSR1RJU/7VB7eANI7jNhL3+nEvW0EjlCE5UIBf/gwNBUIEBcXGmR EGtISTydkHVgNbjSeZXHL1AAapW2WQo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725049671; a=rsa-sha256; cv=none; b=cwtMToIWXhGrub8vAQFDsT8ddDugYXEkKlpD8Vpji4a4B6EeTrzT7mcPLNz7aqGamverpu BNk/bltStNHAR6DwmYF+COEbmAJObt6QdhdH3sbaxLG5DqVUo/hs3Ra8+5+qzFmHM8flrY iZ/80gAMva8gBt8wsdpcoo0hDV+G5hQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cu8C3XTt; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7141b04e7a3so1900733b3a.3 for ; Fri, 30 Aug 2024 13:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725049759; x=1725654559; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GjM4TCQPcyD2c0/3KvrBI/E6RtEEAPLZc40kpXbn95A=; b=Cu8C3XTtYtxQF6avWkLW9of1O2wKBh1WtRZl75onBDp9nItjG9Ma4+zVTVQ+3JJdTh BXPsHFFRHCcExUSp17QWNYezAbDcrpXtqe1U+Aans8gljuaRo5+muf3djMkdUfR1bMDh XCA8Dq38lC42cEZ/brEcU/vtDHn5VTd8LdSiYBAXO3YyR2H6DjFdcrKqn9fJQR7T16QD zY7G+PfNndHBOuBycmrWRPmLMm0W89gkJ8hT3h5iAQK2+Xq45ZIFB4SGEXxmvqlnGNiC y9V3rLBUYJNAEvh9ve+fsQpo0aDNtq9otDk9hmicXtq/dp5glibqX9yfaX1pWsnnTn/W EGqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725049759; x=1725654559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GjM4TCQPcyD2c0/3KvrBI/E6RtEEAPLZc40kpXbn95A=; b=DclA0suXQZo0m2EdFP3UtDd73bK/fM/S7TgA6f+ek1IrL55wRsf6Z8gNGu8DVok4Su +1+rwCSfD/xt71QKRSHbGdCIkFLStg+wENWQgDFnLYHmosq/mgPmhcP1ArEG+4voDlEV jj4Kb7iq+NHP7T40mpJLd5MQc/a51bBj/rSbbCFzHQ0f1ML+W0T96M1/Gq3S6BjUI92c 8KCSPWXZ/ZDVhmkuS1gJosipMOZzLDzzY9bsDqO0yaQnF5t0ebEq5oaLvdnupYW53Zq+ 6FWF+zBAdf+HAfK/Rpw4kt6NsObXgoOhrJ308nH3xDMFY6AKOcBOGCg2Wx5x3zlGojTq k1jA== X-Forwarded-Encrypted: i=1; AJvYcCW+cxtfU/DDuvkheR2JJ+VbfF3XaHL+OcA/Ty6SvDmk8RGnMn3t56sq5T+0x2V/gM4SP/KcI234Lg==@kvack.org X-Gm-Message-State: AOJu0YxYoMt72YMMmRAC5e/2CzjwI3Hk4CyWfvzovYobszo+gvsjOfBe XPgXoBsWOXS1N6o7pwn+ElCNlqkwaBTTuZVMR5+tANHg+vl/3tHn X-Google-Smtp-Source: AGHT+IHPNF3P8o/k5P1eGJ2+IaqrDvOqEe4xWUj5fF+7bw0WYag1yVFsYkqRh8YXWo7n9ciahhhJHA== X-Received: by 2002:a05:6a00:a06:b0:70b:cf1:8dc9 with SMTP id d2e1a72fcca58-715dfced5efmr9881420b3a.25.1725049759477; Fri, 30 Aug 2024 13:29:19 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e56d74eesm3257035b3a.147.2024.08.30.13.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 13:29:19 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org, virtualization@lists.linux.dev Cc: david@redhat.com, 42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, mhocko@suse.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, laoar.shao@gmail.com, Jason Wang , Xie Yongji Subject: [PATCH v4 1/3] vduse: avoid using __GFP_NOFAIL Date: Sat, 31 Aug 2024 08:28:21 +1200 Message-Id: <20240830202823.21478-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830202823.21478-1-21cnbao@gmail.com> References: <20240830202823.21478-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F1EB040004 X-Stat-Signature: a8bo3fnjhhujsoh1ux9k6kkkge9szwts X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725049760-144650 X-HE-Meta: U2FsdGVkX1+OmXnM5/juO3P0Qa4SM2bPc+Z4YI90+5yLhZ9ig5uT7EHsRlm/THu6CSf0t8+0Wf3u6+AQHH2ecWhPOPFDmmx8TGG1qPbx3/VSZIPpqEPNoyBSU0CjgBFG7uHjXq+eEkSS23J1eLa4x7nboTPR3gAWZKB/e+OveT0BeHo/F5I1FLJlXLpNtAizC7J86t3ONBdaOVsqmLE/cmcQVM0E1fjV5Rbi89tnl0bo2Z88GL2K0uydayUCf3daiCGZIz4aIdS7+31vK7Ht268lZsN+O3vsbJIiKVc4jnIMXHVtWZq4tJ6vVcVWB6aNwgOJxcExOVr0ja/lMQyzJUB2TJz9oKlVvNU94kxcrv4MWUsJ81obR1RudNldbsdU4NErzYCUKRcUDRJq+RHzlfS5obODaQiiCxTyXulh1xvK1JHLXt+fS80i3d8qBII4GwXcRgJxoS4amz2zHn+esl5HYDjgSMBnVu2lALa87SrLDZZINrlJz3ldKdSPkfpkpl302GQibcUltUNJHVB1e4q56HQMSDGbPD2q3qZ5qRu2RXnfXLmtowcIRMHFNEJySGbDNb3K/QUKuM9XW9gPHGBa3gJMgNbthBAvh4gAkVC+7HyMfhWVViaFCoy4YcMlSk2GzVFSW0vKy0ovdTY1mM97ALvkCwiNAbvCUvDLyirbYEthwwsFyeQUtw+0z5cyprgWsMtlUIa8t1kijGJACUW8JOjOivcl4nWenn6J8P/bvF4dRDP2/Ma1e1vNb8v63l9Hnb6pnHGlSD2Y1jXsR8GEu1AADuzLFlCh2gRSrUDepdHJo4B6uM5FiWhy6iPwNSariDuPP3q0rK1l7Zmtl7K9i+Ojxm3DoD0fMUfNI57GGXYfEDP9Yr8PSL1yqKhmbNQH3zj9IKIEHUTrkN/XcQsndPHB6xh4PGLfmXb6lHTe+2rcPrv7GWLGDMqH1FacwGzBM6phGt5JXuArhHg N+24nEqK Uwr4Z1vcvd8JTTzkiii+Tdpoo9b1SZ51AicHa5tdWd9GTyVopXnk7z7WKmdRt02hvx8pEJpEfPnySr7hp0wKLZ+9E0mDYZHo8LIji7dw8xZbbK+cNtCSbgSCvhvPkeSnQQTS/njikutqNofX3lO3nCHPTrKYWXWX6jorDzQiFQJBvssXZ2jgEPwC52H8vBDFgWgWqtIAZFSJ7eYBbQjJCHaMy+sIXOq44UmUucD1R4MlpQortqCsOCJLycvawwtufZnqi+94E+BXXBVE32kidd8LGUZd/V5JlcZ3bFIxaKiraKBkZKoCnyyNNQoE6SkSU8ZJ5v7VYNEY6SY2gfdDczQaKwfY00j+5t6e9VQpa4eK4ktN4TSR5LMhVxmbJfGTko//3xeVqI7ucYJGexSPi3+itWpTSn5m68LwM5DcpBv1COo1iMrd1RIDg8mqe0MlulbhGN0xvomFENNv3eetvnJNifYUbEGA6NcJeFFhjBrbBf0XNOot2l3T9s4A33LXeGHEl3e4lUUG/UIubMdjyox5VrB+wAqoknUamXqEPE+0BoQbkBNrXV+c72+D9Uly4oKYktOkSIsbn0mQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Jason Wang mm doesn't support non-blockable __GFP_NOFAIL allocation. Because persisting in providing __GFP_NOFAIL services for non-block users who cannot perform direct memory reclaim may only result in an endless busy loop. Therefore, in such cases, the current mm-core may directly return a NULL pointer: static inline struct page * __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, struct alloc_context *ac) { ... if (gfp_mask & __GFP_NOFAIL) { /* * All existing users of the __GFP_NOFAIL are blockable, so warn * of any new users that actually require GFP_NOWAIT */ if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) goto fail; ... } ... fail: warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: return page; } Unfortuantely, vpda does that nofail allocation under non-sleepable lock. A possible way to fix that is to move the pages allocation out of the lock into the caller, but having to allocate a huge number of pages and auxiliary page array seems to be problematic as well per Tetsuon: " You should implement proper error handling instead of using __GFP_NOFAIL if count can become large." So I choose another way, which does not release kernel bounce pages when user tries to register userspace bounce pages. Then we can avoid allocating in paths where failure is not expected.(e.g in the release). We pay this for more memory usage as we don't release kernel bounce pages but further optimizations could be done on top. Fixes: 6c77ed22880d ("vduse: Support using userspace pages as bounce buffer") Reviewed-by: Xie Yongji Tested-by: Xie Yongji Signed-off-by: Jason Wang [v-songbaohua@oppo.com: Refine the changelog] Signed-off-by: Barry Song --- drivers/vdpa/vdpa_user/iova_domain.c | 19 +++++++++++-------- drivers/vdpa/vdpa_user/iova_domain.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c index 791d38d6284c..58116f89d8da 100644 --- a/drivers/vdpa/vdpa_user/iova_domain.c +++ b/drivers/vdpa/vdpa_user/iova_domain.c @@ -162,6 +162,7 @@ static void vduse_domain_bounce(struct vduse_iova_domain *domain, enum dma_data_direction dir) { struct vduse_bounce_map *map; + struct page *page; unsigned int offset; void *addr; size_t sz; @@ -178,7 +179,10 @@ static void vduse_domain_bounce(struct vduse_iova_domain *domain, map->orig_phys == INVALID_PHYS_ADDR)) return; - addr = kmap_local_page(map->bounce_page); + page = domain->user_bounce_pages ? + map->user_bounce_page : map->bounce_page; + + addr = kmap_local_page(page); do_bounce(map->orig_phys + offset, addr + offset, sz, dir); kunmap_local(addr); size -= sz; @@ -270,9 +274,8 @@ int vduse_domain_add_user_bounce_pages(struct vduse_iova_domain *domain, memcpy_to_page(pages[i], 0, page_address(map->bounce_page), PAGE_SIZE); - __free_page(map->bounce_page); } - map->bounce_page = pages[i]; + map->user_bounce_page = pages[i]; get_page(pages[i]); } domain->user_bounce_pages = true; @@ -297,17 +300,17 @@ void vduse_domain_remove_user_bounce_pages(struct vduse_iova_domain *domain) struct page *page = NULL; map = &domain->bounce_maps[i]; - if (WARN_ON(!map->bounce_page)) + if (WARN_ON(!map->user_bounce_page)) continue; /* Copy user page to kernel page if it's in use */ if (map->orig_phys != INVALID_PHYS_ADDR) { - page = alloc_page(GFP_ATOMIC | __GFP_NOFAIL); + page = map->bounce_page; memcpy_from_page(page_address(page), - map->bounce_page, 0, PAGE_SIZE); + map->user_bounce_page, 0, PAGE_SIZE); } - put_page(map->bounce_page); - map->bounce_page = page; + put_page(map->user_bounce_page); + map->user_bounce_page = NULL; } domain->user_bounce_pages = false; out: diff --git a/drivers/vdpa/vdpa_user/iova_domain.h b/drivers/vdpa/vdpa_user/iova_domain.h index f92f22a7267d..7f3f0928ec78 100644 --- a/drivers/vdpa/vdpa_user/iova_domain.h +++ b/drivers/vdpa/vdpa_user/iova_domain.h @@ -21,6 +21,7 @@ struct vduse_bounce_map { struct page *bounce_page; + struct page *user_bounce_page; u64 orig_phys; }; From patchwork Fri Aug 30 20:28:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13785529 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 89125CA1013 for ; Fri, 30 Aug 2024 20:29:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB1676B0266; Fri, 30 Aug 2024 16:29:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E614E6B0269; Fri, 30 Aug 2024 16:29:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDB428D0008; Fri, 30 Aug 2024 16:29:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A49916B0266 for ; Fri, 30 Aug 2024 16:29:33 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 13D8C1C2B10 for ; Fri, 30 Aug 2024 20:29:33 +0000 (UTC) X-FDA: 82510052226.03.A8F01D1 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf07.hostedemail.com (Postfix) with ESMTP id 191B740015 for ; Fri, 30 Aug 2024 20:29:29 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cRFb+XM1; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725049725; 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=4uA9yJDuldkXpjNOiGrNCM2z32l5zmJbbH03h4Qi+gc=; b=pE662BqfsQ1nmn55SrRiGB3kACwFt+AFhvXzHJMKwrrU13gFkPCVH6QeA9kNGXncUUHcRQ 7SxbdHathqmP4yqA2DGxqVyGlt0xLvQt70DQ9KnAI1/x0LyUoy6/P79yxV/fvWrjTdQxbA M0U59j5x0rGt0VlL7xobYNw7gWQHlbQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cRFb+XM1; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725049725; a=rsa-sha256; cv=none; b=jrZnCvW7/oKfN57BCcSbq+AaqOsGTiFmoHrkDES3eLEh5y8GxKm/skoyfIvhCx3my9SH4X fLYPiaLUP/i4+9ZPL/6Ft46oQ28++/zlODD+yLNo1jHtJ8rZYlyniF7XNnaY48V0sJkric SgAgw5sv7AJKtLJT71MFCWExo1XPSI4= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7141d7b270dso1887857b3a.2 for ; Fri, 30 Aug 2024 13:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725049769; x=1725654569; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4uA9yJDuldkXpjNOiGrNCM2z32l5zmJbbH03h4Qi+gc=; b=cRFb+XM1Kgdj9gXRnJk2atpaQW8FIDtwWSKbzIQywy3PxjAKXqnniIa1BG0LVwzYs1 vPifW4XLlJX66ZR+GgCy8K7EWC9CbWjqKOD8/adQGecHhO25sPYeqzMnyWg+SziXInp2 p2emDCu05cxAjYEgwEN33xFQQaTE7cNQVys6Sl2G+AoaX+aNHSPLkjTpn0uVX6MTnQlp CZtPYiOxBSNd/+TSrJdNqo1fJEljC1Fe59i04DZPB8NlIN00JNgtyFxflcTXK1RtpARP lOICz3c6Cgs/asQMboPpqaTPPY+LRBRQHWBR9DjG2ZBSEci5v7CCXmyQ6yEe0PS1qXrT iKbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725049769; x=1725654569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4uA9yJDuldkXpjNOiGrNCM2z32l5zmJbbH03h4Qi+gc=; b=PnPLT7GrwaPSqZWu40zWfId8R5MohczNOEMw0PCr7HxbwpfIKun6Ef3DR1nJ9ob0f9 6SfGobVFiuAG4VxWmuf1S/hwF5ITK4DAVqMzWll/B7oJGoktHtI/mtvtFoFZiwEfktxE fF1ATR43UovGgDbns7XfINHzFxFEvkQhA2FtUMDZnmYfdmKXRgMsuYfPn5ztRRjkg6+2 5oEnfbTrBZPEukJeTLedtkit+bVXTwY0VxQZfdJyGpqXVTJXnuD1vDo1mx35WHxsR7Lv QgzFQrFPoTjku5JwyQm0meVOiaSSmT7XECygDNIzGo0oElWO9GgbkxzT2EcHLzLuZit+ Vaxw== X-Forwarded-Encrypted: i=1; AJvYcCXGcWefRwFlZXetBwVjBB6s+gw1p9DGja2V6TER8ZtSixifLFpIVq3YmrOqwQgpjmVcR/fBUvGfXw==@kvack.org X-Gm-Message-State: AOJu0YwcdboU+Exnf0FLyDj2pnrLNhCnGPObKuCgluWhBngyfI9rysR2 Dilo9RQtm1lssYH4xux+FstM+Gx13WHesX4G6LcddO/L4ZB7DGQF X-Google-Smtp-Source: AGHT+IG17vPMYD1S7Pz+MktNA899UqxDhkOHrGHPipZtAaxRI2/2JbLZJqwpWlQmoqhwmciVH6EbqA== X-Received: by 2002:a05:6a20:d706:b0:1c2:8bcc:bb09 with SMTP id adf61e73a8af0-1cce0feda6amr7038084637.8.1725049768642; Fri, 30 Aug 2024 13:29:28 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e56d74eesm3257035b3a.147.2024.08.30.13.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 13:29:28 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org, virtualization@lists.linux.dev Cc: david@redhat.com, 42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, mhocko@suse.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, laoar.shao@gmail.com, Christoph Hellwig , Davidlohr Bueso , =?utf-8?q?Eugenio_P=C3=A9rez?= , Jason Wang , Kees Cook , Lorenzo Stoakes , Maxime Coquelin , "Michael S. Tsirkin" , Xuan Zhuo Subject: [PATCH v4 2/3] mm: document __GFP_NOFAIL must be blockable Date: Sat, 31 Aug 2024 08:28:22 +1200 Message-Id: <20240830202823.21478-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830202823.21478-1-21cnbao@gmail.com> References: <20240830202823.21478-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 191B740015 X-Stat-Signature: 7h7g4uzsc9uwfiactehxqharbc1fuqeb X-HE-Tag: 1725049769-497410 X-HE-Meta: U2FsdGVkX1+XnvcCWP+dXvYx1nBtgLTNj9nUMWkbratcAUzKkp8ZNNp1rliAj1vCFrNZtmhCFpkt8yepoxfrcSOqvmK/0IK9bb7A8oxuserfCRe/1zjG6N+E9IY3i/0+eFy2yrl46ChG6UlVmZP00JdBUchFVmQE2Ntt1IxOtqR2SABfFS4MHCRW/2ck6ZEud1fONEOy4Rj7+e14puoj+ANP4iOyRf+2W/O2rnhfU3ebt4yPTKZX3iBvXO/UlU0sNXcDetmUfse5arydikhLUm598LgWw5ukbY4YBKqnPlVdhjtEv4SrtFZLK/4hWDvCM+I8m4GRlTAxiUYwVthR2F8Gm93eDIU0wKOheDcT3LdAzznR79A4wXM9HWX5T/GVtArrlBF7gznFXWzKkjT0mzERSEhFUHqb6oFJdZ50cfQ+5WQSJMx1p3dZ4BhqV4uebRf92rpATKGo9yE3RObJZ+VHJH+hjMGga/0+7rWn/zRb+ebAndX1G+fcWL/hm8J8QGLUZtB0LpTvI7guQJzuV1+A/X1zyN/feJAq/BgCnyc2ov/a8VeiVRJ9YLA05cPF05N7ne/mUGmjwrCCEOff6XK0wsXtzJa9+1GTB2wk55FF852p0rL/S3MZ5JywQK/jE2sMmBqis++XAflWW7VsBZBGM/D6vZ9S7m1Beq38BU5OBbpu0QglPHt1aGRx3b3YtJQpiqxB+OV3zia27xaNJ1kzS7LZtj+U5ajeYu1kYHpB/UJazS212HnOweh1YPMzWLgaBGdXt6GbCWZUTi0M5ia3MroCzhwxVJNbk+CUjAWSEqWcNqvT5eJYSM0ogaZNACSHH5Z+872HGk/kM9R2LisXwflw8SOlfnV255BSEDK9OM6H/rouUsNEnm5Eh65R9fQuwmooiLZHRqGZvXgjit/lLYoehWb24etYIYfEOlaFMEDSH4QhqFxiOmAZu4XC7bzVXIxSFYWvFaVm1qq xyudLPKZ /yFTs4brWeZGtdk1Sd0b6RBMl4v+fxe/x/8izvBTJWcfpDrdeIntcFPneZmcou8roSxqLHRUheWHC59/jUjrBYTDdkPLrRdncekLDicDdPv/Ajf6YgXD2p5Ikkyey0zJUrp7ulllGsjqB6pmljfuIk2Vjk3TtJYdppwzWTqXJLMa5o4MIqHBQHALVxzZMGmFn6Z8YwJbbzkQ4JOdp5fqwVLqKyxKbdyR45q0EHLDTLFP/chxieHWwJt8tmBg9pCDJFgXZ1Jcavr4l8BEMGEliARo+qAG14eKMduATIbandjUd9UPyrnPhV05m0x21/kAvEguYJz3PXGxVd0vS2yjGREXTZyw5fh5g4PDzt+yt0rZq0sa+JPaVDMsF9u2Knd3S26BpEpjpebt2Sr2dZ6SDl4RkREHAq+sFuOmbUBVz4tAeJMjr/hR5KTXcHiXP2JSP9DOguUgGL7euI5ktJIqS9cnMvScm53bFqi7QhLocm9titWVPxQIpbO3J6RnPeYoixZLlNh5jG9gu/iO+l6Q2oVSwFgdX1KXEW395MORbPOmd7sw6asaT8wbFxBhV7Whl4zSmYoWHaRbBYudAG01X3nCqGQbKXd7ZGuxiqN9yNQwuoUr5y3eP4g07l4ARfUVMrvULtFakYqi1ZgMj+RyKAJALtEiIpfHsnR8h9rlgwIXXlsks2qbCZlyTeH5rzUFnW9f/WQ3VUj5DhS5RIgbpuPQcGrlTIAefMx0xCwfiaBZ/yNtxbDHOPPjaCIW8SziufTlgF5+jUUYZCntwlpI9ePnIaPfMUUVpz4toMFzip+DNwMa7Qwo3id4NnKfrffOK/lW/nAqkH7GhXzHdvw05JLnTH6pC3KtUnZE6UPEr9cqq2pXhyJx34oLz9hjhrZoLH34gCU5exKzedT3n5H3FVnDodgVw3rel7GZwNMgPqNXJIg0I93A1EyMYtHK0IQiyRIwhhYsWF+gKhXTIbHJitnSturpS pr/XROv6 oRmtUcHgEcWGWcdzrGoSe8qffvrVlBGzBM0YkMBK3GI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Barry Song Non-blocking allocation with __GFP_NOFAIL is not supported and may still result in NULL pointers (if we don't return NULL, we result in busy-loop within non-sleepable contexts): static inline struct page * __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, struct alloc_context *ac) { ... /* * Make sure that __GFP_NOFAIL request doesn't leak out and make sure * we always retry */ if (gfp_mask & __GFP_NOFAIL) { /* * All existing users of the __GFP_NOFAIL are blockable, so warn * of any new users that actually require GFP_NOWAIT */ if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) goto fail; ... } ... fail: warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: return page; } Highlight this in the documentation of __GFP_NOFAIL so that non-mm subsystems can reject any illegal usage of __GFP_NOFAIL with GFP_ATOMIC, GFP_NOWAIT, etc. Signed-off-by: Barry Song Acked-by: Michal Hocko Reviewed-by: Christoph Hellwig Acked-by: Vlastimil Babka Acked-by: Davidlohr Bueso Cc: Christoph Lameter Cc: David Rientjes Cc: "Eugenio Pérez" Cc: Hailong.Liu Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Jason Wang Cc: Joonsoo Kim Cc: Kees Cook Cc: Linus Torvalds Cc: Lorenzo Stoakes Cc: Maxime Coquelin Cc: "Michael S. Tsirkin" Cc: Pekka Enberg Cc: Roman Gushchin Cc: Uladzislau Rezki (Sony) Cc: Xuan Zhuo Acked-by: David Hildenbrand --- include/linux/gfp_types.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index 313be4ad79fd..4a1fa7706b0c 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -215,7 +215,8 @@ enum { * the caller still has to check for failures) while costly requests try to be * not disruptive and back off even without invoking the OOM killer. * The following three modifiers might be used to override some of these - * implicit rules. + * implicit rules. Please note that all of them must be used along with + * %__GFP_DIRECT_RECLAIM flag. * * %__GFP_NORETRY: The VM implementation will try only very lightweight * memory direct reclaim to get some memory under memory pressure (thus @@ -246,6 +247,8 @@ enum { * cannot handle allocation failures. The allocation could block * indefinitely but will never return with failure. Testing for * failure is pointless. + * It _must_ be blockable and used together with __GFP_DIRECT_RECLAIM. + * It should _never_ be used in non-sleepable contexts. * New users should be evaluated carefully (and the flag should be * used only when there is no reasonable failure policy) but it is * definitely preferable to use the flag rather than opencode endless From patchwork Fri Aug 30 20:28:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13785530 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 25EF6CA1013 for ; Fri, 30 Aug 2024 20:29:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B08046B026B; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB8388D0008; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90ACD6B026D; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6AA0F6B026B for ; Fri, 30 Aug 2024 16:29:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CB48CA05BC for ; Fri, 30 Aug 2024 20:29:38 +0000 (UTC) X-FDA: 82510052436.12.4AAED17 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf09.hostedemail.com (Postfix) with ESMTP id DC560140021 for ; Fri, 30 Aug 2024 20:29:36 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iaycYqF0; spf=pass (imf09.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725049731; a=rsa-sha256; cv=none; b=ukcTCMSOH8e/b2tc7MTU8RpWydgtBKIj3LaMtcEOn0N01Ni6DiSwlIYWMjyWkU66+xycSa sGwQ4zPXDOQ2SehcTQbM8ntgGP58aAkVqZlTxPdhh42eCMNjQbvqcn2PcIV7g0IcU+rCOc feTJrhc89IGKsnVdDOfwLGpCcpBc3D0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iaycYqF0; spf=pass (imf09.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725049731; 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=kCn45A0xkxYmnXC9jhkef4/QM2hxjGm0wlBoU+2BCnU=; b=fYaHoOD26aWlNbxY8bPSBVIONZirwGXg/oqs3SKxInFsM5Obpu2Zjghxj3mapZvANAYifU M3fEvfhtSFytrYSRi7FEG62LkdGHaLqaI8+9xziEzanEXZHqDmOHaC2QjAcclIUyXCKfmW 9eGYYIIx/o4w0TtYDYQT9Bd+Q06pLoI= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-7148912a1ebso1459282b3a.0 for ; Fri, 30 Aug 2024 13:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725049775; x=1725654575; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kCn45A0xkxYmnXC9jhkef4/QM2hxjGm0wlBoU+2BCnU=; b=iaycYqF0mcn0FVMLx2TDe2macsblRm38yqBop5eOT2N7P/lGr86LfClxqFLkU++Tqj amnd8M+55hxJxAHzyMHbKwxayLxVytu0TakS7ra0+15JTUX9u7zVl9A1Xc4MdAieJu7P N/SGcK0auCYXCgbvCQRrUvg1x/ZjZc+v/sUfFj9iKnZAIbljRVbH0RTT8W7rJhejEDoc qpnpWOF57zdAvjPWsDdIKmAAHlLfS7UmGP8QyCqWrfE/eTNjb2MORc6uQXfYhtOU3We8 LnKoaCxVbmQJaIaXPIdgMmgTPL4ADuV2fAHd5GoxgwbD/zA2npp4/Tvv3UEqh3KEV++c lyOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725049775; x=1725654575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kCn45A0xkxYmnXC9jhkef4/QM2hxjGm0wlBoU+2BCnU=; b=PpijBizlA+xswwYsAmpYKYFKpeBLiIrCbyuUOcW778GFRBINbvDGRfjxebnOf7qWh0 Wt4Ug5L57rqr+O3vxiQ5Dk6iDE5/WKU3xdrbyiY2UTeN6NZQ96pk4c2hh5s5TTFQIVSN f1hvNfpD5QLgCKz+vksQc8Jt9NUTS+zj+Q+mfE7U3Ri31IQMfFZ/XJ1fWSDJbxxfIcDZ g9kjzNYtK740SFPiZqRbEhb3lecH+ZZoqyEHwYQ8557q/5zGjLiEPjzMb2R23p+i5MXC FK6uhETRMKPywQn8msw2zjSU11HpVoNCooINEqVgFfmirsKhY9vPXLPj04MjADBfnDVk tuaw== X-Forwarded-Encrypted: i=1; AJvYcCVSa8hfHfEYQhuYNryt+S6QB02QvRPGoXnJuwUWLw9p+CXFqZ/tE0pf09NQm9XuFpFmZvjtBTibew==@kvack.org X-Gm-Message-State: AOJu0Yyvcgy6PE7wv4ba0gdSKH0OsUFH47knkkZeIhJWgRoPB75+ibZk Hkwls7ckeuOTLtLZzEAilvyj5J9Qz/y68K9PmVm8ze8N6wbqOhW6 X-Google-Smtp-Source: AGHT+IG8y6GX/E7RigCSHufkr+GwgOj7KdtzlyA39qYM7vxl8g1/NMkb5KBYNwmdjJECo9kKMTCYSA== X-Received: by 2002:a05:6a00:124a:b0:705:9992:e7f2 with SMTP id d2e1a72fcca58-7173c1f7300mr1000751b3a.12.1725049775341; Fri, 30 Aug 2024 13:29:35 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e56d74eesm3257035b3a.147.2024.08.30.13.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 13:29:34 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org, virtualization@lists.linux.dev Cc: david@redhat.com, 42.hyeyoo@gmail.com, cl@linux.com, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, mhocko@suse.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, laoar.shao@gmail.com Subject: [PATCH v4 3/3] mm: warn about illegal __GFP_NOFAIL usage in a more appropriate location and manner Date: Sat, 31 Aug 2024 08:28:23 +1200 Message-Id: <20240830202823.21478-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830202823.21478-1-21cnbao@gmail.com> References: <20240830202823.21478-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: zjmo8f3zyrshxy8ruw7jjmg4cew6ifxb X-Rspamd-Queue-Id: DC560140021 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1725049776-583992 X-HE-Meta: U2FsdGVkX1+SUMOI9Zy3R3fzi2J7zTW//7mD/QOFzFT57lM24xGt/Wpzv9uIfbBz+fywwdk338czLUI6DyIweu5topt/TFurIZ/wUXvsSQr9AHhxZegvWXuHt/6lZLcFG2kFS1CWEfEw0d/k+TjVFVhPvjsduIEMFT/CXSfPLgVarJS5A80c1RPJxEc1HLe34sWfR/MsppzMyl9noY75OBCSepgCQrdBPS9a/5vd4RTz9dzREt+0xZC+TUqXUaS2ogBha8YE1bzP0ljYVWGSyj3Bm/BzB4YeSCT8P1vOQ8DOol6R49D9+1BARgDpDQtgY0DTeLnPs3mDRh8Bpl5nFzp6cSHHqNCCH2RBU/ZBMsXd9VRF0mswu0FNzCE5aF0nqyuFwHnXvchVY3BifJGu47RnfRLwHegtUBt1JKdc88D4K3fk8ifmW1V0Uvkp/g/A/bjoZv1NzA0eX+E3IYnDk0FLBLohHhncllHtS27BwPKFHn1tqMEYSWCTPphbAahyjFsjhHZUqUormupzXJvygvKhUzZjso/QWm1tPle5Bv9CHGMCmRiTAtGVp0K1KmatVQFJqQ0D9mTxLFl94QNties3NQHv1l9uF/yuawFZq2JjBs7HsZLZ8zO4fAVEI6b07plZMrCVM1FTSMepfHbp5wec6eFTm/LWUZQzMJVFMrPpyBoLmHq136qHja6sY//wJ5m2rKyD7oeTp9EmVUGZDojhhtjdPPs5B1vAIVLzyjEhvFpBO8Ymq8ZfgyxMnnctRU5/xQ8N9Tm6F0GkV7DVs2Hb/H93ptn6z+qTseIa7Pb4QBkgcMs9do3Tl28IFkfE4VO3WIliXntj3y/GX92JjX8wPU20yA8+kDlkSjfYRVyKuyRmHjvM00EZom3Z2RWK9RpsFhyv9G7k0zVepx2uc1MARwbRmohVvXvqHpzWwkjqLr3TPn6AneoauOgQj1xBiWeSGXLoWv5XxwLOAOu qa1twgbc AlBWvI0BIgEfgAre6gmLnQXK+TbvqCKkfiu2bScIu6TrzGvuyEt1XYZU4qFfIe/jXFTV9soCJGud5IqYYuCytidYFrr+b7u0sH47DpKa1sCpzODy0ly3eg67QGkaklZBA0I54ueRy2kOn3X4QHvWUi6mcTumkBLE04k3s/QtCgUNYVWmzfQpYKMNi5HIox6gcNsn3Kc6bOftZzz9/9O/i/bbJ3SRrrUr354tmJmI/Ln39hu7iNnIKpIU7VRZXWzwwGEUPf3Qsq0t+YWEMuFaZP6ypG5d95Xq3mvwAaoFiPFi7P36CeT7ZmwK6vWtkmWzHIH9TafOqNziwXPhyyPPThQUH5E5RoQ6wkbcgJB7F4uJ/3KqyZb4zfvcSl41xa5o1rLhDIEVIQWRKThMW2dvZuApVw9UArFfwIbdh+DzqdoV9Jj+CBeKdYEgz1dW57a3q8yc9dxPkEcDl5z3xCXbMTq+T6n6Bespn1wO9qgFcOW2R8qDh45hEs6h9OmpZSixj6peUlR3Q4tnQJnGP08Qv2soBN2r1nBX1L3kXwQKWT1InzCA3Ppxdv4cHHdb+HFLnxRY/dAPqHIzUyEY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Barry Song Three points for this change: 1. We should consolidate all warnings in one place. Currently, the order > 1 warning is in the hotpath, while others are in less likely scenarios. Moving all warnings to the slowpath will reduce the overhead for order > 1 and increase the visibility of other warnings. 2. We currently have two warnings for order: one for order > 1 in the hotpath and another for order > costly_order in the laziest path. I suggest standardizing on order > 1 since it’s been in use for a long time. 3. We don't need to check for __GFP_NOWARN in this case. __GFP_NOWARN is meant to suppress allocation failure reports, but here we're dealing with bug detection, not allocation failures. So replace WARN_ON_ONCE_GFP by WARN_ON_ONCE. Suggested-by: Vlastimil Babka Signed-off-by: Barry Song Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand Acked-by: Michal Hocko Signed-off-by: Barry Song --- mm/page_alloc.c | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c81ee5662cc7..e790b4227322 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3033,12 +3033,6 @@ struct page *rmqueue(struct zone *preferred_zone, { struct page *page; - /* - * We most definitely don't want callers attempting to - * allocate greater than order-1 page units with __GFP_NOFAIL. - */ - WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1)); - if (likely(pcp_allowed_order(order))) { page = rmqueue_pcplist(preferred_zone, zone, order, migratetype, alloc_flags); @@ -4175,6 +4169,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, { bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM; bool can_compact = gfp_compaction_allowed(gfp_mask); + bool nofail = gfp_mask & __GFP_NOFAIL; const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER; struct page *page = NULL; unsigned int alloc_flags; @@ -4187,6 +4182,25 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, unsigned int zonelist_iter_cookie; int reserve_flags; + if (unlikely(nofail)) { + /* + * We most definitely don't want callers attempting to + * allocate greater than order-1 page units with __GFP_NOFAIL. + */ + WARN_ON_ONCE(order > 1); + /* + * Also we don't support __GFP_NOFAIL without __GFP_DIRECT_RECLAIM, + * otherwise, we may result in lockup. + */ + WARN_ON_ONCE(!can_direct_reclaim); + /* + * PF_MEMALLOC request from this context is rather bizarre + * because we cannot reclaim anything and only can loop waiting + * for somebody to do a work for us. + */ + WARN_ON_ONCE(current->flags & PF_MEMALLOC); + } + restart: compaction_retries = 0; no_progress_loops = 0; @@ -4404,29 +4418,15 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, * Make sure that __GFP_NOFAIL request doesn't leak out and make sure * we always retry */ - if (gfp_mask & __GFP_NOFAIL) { + if (unlikely(nofail)) { /* - * All existing users of the __GFP_NOFAIL are blockable, so warn - * of any new users that actually require GFP_NOWAIT + * Lacking direct_reclaim we can't do anything to reclaim memory, + * we disregard these unreasonable nofail requests and still + * return NULL */ - if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) + if (!can_direct_reclaim) goto fail; - /* - * PF_MEMALLOC request from this context is rather bizarre - * because we cannot reclaim anything and only can loop waiting - * for somebody to do a work for us - */ - WARN_ON_ONCE_GFP(current->flags & PF_MEMALLOC, gfp_mask); - - /* - * non failing costly orders are a hard requirement which we - * are not prepared for much so let's warn about these users - * so that we can identify them and convert them to something - * else. - */ - WARN_ON_ONCE_GFP(costly_order, gfp_mask); - /* * Help non-failing allocations by giving some access to memory * reserves normally used for high priority non-blocking