Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1006063rdb; Fri, 16 Feb 2024 02:19:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVZgFM5tJwt6YNcecueowZyFcu7ugtj7BI7Bq6G385gr2NMs2KpHG/AF1B5/llg+KaGAouUCKMGuth5RgyEOhqmnARch8hxZCwS/9u3fQ== X-Google-Smtp-Source: AGHT+IGVAJu5Jk78e+z2EnFDsdQ15E8GcaGB2xJlb3NXPMHNcSJ9w1HemlILrm4zLoByzJmuvfDk X-Received: by 2002:a17:906:2a97:b0:a38:916e:a4fe with SMTP id l23-20020a1709062a9700b00a38916ea4femr3329033eje.39.1708078749508; Fri, 16 Feb 2024 02:19:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708078749; cv=pass; d=google.com; s=arc-20160816; b=hc2uD/9E5jn06KxEonFjA+Z2B0JTTzoyDlcNJjvu3VWyu/zGdRtJ30g6tD+AyaTJ27 +85VH3dYG9Y+h8DOLCB0EpD1Ego4Lsqcb4hhiVrFTPy4sXKD9nVF3tI+WosEdFdmn5Bq RyAybj7XV6oUm4Hzmv39E5Aqn4lxeVV5lXA4m5741ou0Y/738b+DbBQhX95jjgTaiTB/ GsZWaeq2PbRuO9uQXmZho1C+0SpvOHJDy/Q+UPK01MHWfaI39kGXku/ZKLdNsc2tycgF kGWmu1KIKm91bk4f8OT07lRv0p4ZYt46vRu19zq0RfzBBeXU7QJeawcweADt7Qe5ewkk h8Lg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=6h/xSWPlRf7PDPu4yMf74pKtHxhg0XmMUweyxazKoaE=; fh=J63pf88FGyDDhGRdPKvH8dnS2rOkOm7Bcm2oaG+ReZ0=; b=nonid47ZEWpHQrwFAIAz11lOTFwddj349ONQ+GbBtiNBvGDnItmq5GvfuoXZzqXmIY k4+AyCcUqE1i0F4cr5x7k3EeGmrXKq34WeTo5fKgnwrz89lTFufjuXWodOfhMNVhIuzV P2l5d9JYMB6Z2s+Gqa54aniZHgnXRnIzkMwDb0baIRZBKRSBr+kOH8kdFWHcA14wqSns rO8SfaSNTfIHr6MlQJP4e9+c4c7QHpLjgV/gZkayJ7lRrb6sMUCICRYbb/yS5YXo0yaT MHN8YsY247aefbr+WaxxI8K54FsHZviN/cMkiWtaxfzKfDuqgY5VvR+WUNht1Rgkg6Iq ex4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=agRpDnIm; dkim=neutral (no key) header.i=@suse.de header.b=Q8L9QANS; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=miCOrLyg; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-68434-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68434-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r15-20020a1709067fcf00b00a3df762668asi66419ejs.922.2024.02.16.02.19.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 02:19:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68434-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=agRpDnIm; dkim=neutral (no key) header.i=@suse.de header.b=Q8L9QANS; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=miCOrLyg; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-68434-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68434-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1F0A31F24A3C for ; Fri, 16 Feb 2024 10:19:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB51F20B04; Fri, 16 Feb 2024 10:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="agRpDnIm"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Q8L9QANS"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="miCOrLyg"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="pM9icsqo" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2955E1B81C; Fri, 16 Feb 2024 10:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708078740; cv=none; b=uAqB4geXG91c5xSupXMCVugMD4OST8HKuHjjMS89KBx+2Lydv9Nw5+DKhnAwmbGdXvF0Y+AVObZgX9nn43VLZaGaFhYlFvFxgRUhEuWeCKxoed8oTSJKGdv7O3c7VasHQ3VG8qhgJecUKfCW3QHWMw1JzpxHt88lnV3jCRfq4hI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708078740; c=relaxed/simple; bh=2l/Luo4DE+UQCMB52S0bZ89e7WBP7HLxzEg0RHVs1EM=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=IxMxBT3PQ1ldS470je2nKsg7DbZecj2bwRHmbyPVKzS9Eo0/eewHixWaefVvtmKwBoNpyeuf0wtGoy3RAv6FFQuUHihNaf4IN71p0QpGhhbkQbExBvAXd5fVzTt1a8yY3U4j0xP09LTlYLhwspjhvpmiIZqzI+ST7KsT59mmx2A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=agRpDnIm; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=Q8L9QANS; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=miCOrLyg; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=pM9icsqo; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DC0151FB5B; Fri, 16 Feb 2024 10:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708078736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6h/xSWPlRf7PDPu4yMf74pKtHxhg0XmMUweyxazKoaE=; b=agRpDnImeZyWS78Js8bdcFUV2NVhV7IwcGA1IGE11p01MkbTPglbP3M+dRhVP9WpGpZENr Qyans5g34aYETR60cHOrUolFUicF3B9gdr2sFgmK0uh/HfV0W5Ug3BRLxhxv94YFeyLVUK 5jmzREIDTfr/WECikcnGIOJ+2VW8W4M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708078736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6h/xSWPlRf7PDPu4yMf74pKtHxhg0XmMUweyxazKoaE=; b=Q8L9QANS+g9P7FTChcAKpxBYo+tyKUXnlM/vE39cSrXUfqFmQEZXJfN+0nReqsMNzXZcxQ UVSmAonCbLL0YNCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708078735; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6h/xSWPlRf7PDPu4yMf74pKtHxhg0XmMUweyxazKoaE=; b=miCOrLygZO1ScyMykcr/WPln1exiufOHnRAQ+P+O7JUOavlFJVVOSm3K4voL2m/oNYNHQC ZZy36v58yOjUyEe0lNAOQgKbqoVMifbAQbYOAZDkr5PQ3jPVNL9npMAGC6lOuzvRoRc1Tj 271Uh/XjQ8rgqJ1zxqR3/IE+8+3M6X8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708078735; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6h/xSWPlRf7PDPu4yMf74pKtHxhg0XmMUweyxazKoaE=; b=pM9icsqomFguXaYdYV31rptOO8JdN00gPdel3E6ToBIlUWpNNvmPvbxF9WRFZb7CPAxPfS ZGnuj6UADbhYajDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9FA4C1398D; Fri, 16 Feb 2024 10:18:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id st+PJY82z2XPeAAAD6G6ig (envelope-from ); Fri, 16 Feb 2024 10:18:55 +0000 Date: Fri, 16 Feb 2024 11:18:55 +0100 Message-ID: <87frxsiueo.wl-tiwai@suse.de> From: Takashi Iwai To: Hillf Danton Cc: Sven van Ashbrook , Karthikeyan Ramasubramanian , LKML , Brian Geffon , linux-sound@vger.kernel.org, Kai Vehmanen Subject: Re: [PATCH v1] ALSA: memalloc: Fix indefinite hang in non-iommu case In-Reply-To: <87plwwiz6z.wl-tiwai@suse.de> References: <20240214170720.v1.1.Ic3de2566a7fd3de8501b2f18afa9f94eadb2df0a@changeid> <20240215034528.240-1-hdanton@sina.com> <87h6iaf7di.wl-tiwai@suse.de> <875xypk6d6.wl-tiwai@suse.de> <20240216043426.1218-1-hdanton@sina.com> <87plwwiz6z.wl-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[sina.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; FREEMAIL_TO(0.00)[sina.com]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO On Fri, 16 Feb 2024 09:35:32 +0100, Takashi Iwai wrote: > > On Fri, 16 Feb 2024 05:34:24 +0100, > Hillf Danton wrote: > > > > On Thu, 15 Feb 2024 18:03:01 +0100 Takashi Iwai wrote: > > > > > > So it sounds like that we should go back for __GFP_NORETRY in general > > > for non-zero order allocations, not only the call you changed, as > > > __GFP_RETRY_MAYFAIL doesn't guarantee the stuck. > > > > > > How about the changes like below? > > > > > > +/* default GFP bits for our allocations */ > > > +static gfp_t default_gfp(size_t size) > > > +{ > > > + /* don't allocate intensively for high-order pages */ > > > + if (size > PAGE_SIZE) > > > + return GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY; > > > + else > > > + return GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL; > > > +} > > > > Looks like an overdose because both __GFP_NORETRY and __GFP_RETRY_MAYFAIL > > are checked in __alloc_pages_slowpath(). > > If the check there worked as expected, this shouldn't have been a > problem, no? > > The fact that we have to drop __GFP_RETRY_MAYFAIL indicates that the > handling there doesn't suffice -- at least for the audio operation. Reconsidering on this again, I wonder keeping __GFP_RETRY_MAYFAIL makes sense. We did have __GFP_NORETRY for avoiding OOM-killer. But it's been over ages, and the memory allocation core became smart enough. The side-effect of __GFP_RETRY_MAYFAIL is that the page reclaim and compaction happens even for high-order allocations, and that must be the issue we see now. For dma_alloc_contiguous() with IOMMU, this wasn't visible because the loop there sets __GFP_NORETRY explicitly unless the minimal order. So, basically we could have achieved the more or less same effect just by dropping __GFP_NORETRY from DEFAULT_GFP definition. (Now it's a drop of __GFP_RETRY_MAYFAIL) OTOH, a slight concern with the drop of __GFP_RETRY_MAYFAIL is whether allowing OOM-killer for low order allocations is acceptable or not. There are two patterns of calling allocators: 1. SNDRV_DMA_TYPE_DEV for large pages: this is usually only once at driver probe, and the pages are preserved via PCM buffer preallocation mechanism 2. SNDRV_DMA_TYPE_DEV for lower orders: those are usually at probes for some communication buffers, and in most cases they are kept by drivers, too 3. SNDRV_DMA_TYPE_NONCONTIG for large size: this is called often, once per stream open, since the driver doesn't keep the buffer. 4. SNDRV_DMA_TYPE_NONCONTIG for lower orders: basically same as case 2. That is, triggering OOM-killer would be OK for 2 and 4, but we have to avoid for 3. So, __GFP_RETRY_MAYFAIL would be still useful for there. And for 3, there are two paths: - with IOMMU => we may pass __GFP_RETRY_MAYFAIL unconditionally to dma_alloc_noncontiguous() - without IOMMU => dma_alloc_noncontiguous() without MAYFAIL, but fallback allocation should become conditional: - higher order: default (or explicitly with NORETRY) - lower order: MAYFAIL OTOH, the avoidance of OOM-killer wouldn't be bad even for 2 and 4 (as its usefulness is dubious). Then the conditionally setting MAYFAIL wouldn't be bad for the calls of other dma_alloc_coherent() & co, too. Takashi